fail if the parent directory for database does not exist.

pull/77/head
Jason Kulatunga 4 years ago
parent bd2f305d80
commit bf07077154

@ -2,7 +2,9 @@ package web
import ( import (
"fmt" "fmt"
"github.com/analogj/go-util/utils"
"github.com/analogj/scrutiny/webapp/backend/pkg/config" "github.com/analogj/scrutiny/webapp/backend/pkg/config"
"github.com/analogj/scrutiny/webapp/backend/pkg/errors"
"github.com/analogj/scrutiny/webapp/backend/pkg/web/handler" "github.com/analogj/scrutiny/webapp/backend/pkg/web/handler"
"github.com/analogj/scrutiny/webapp/backend/pkg/web/middleware" "github.com/analogj/scrutiny/webapp/backend/pkg/web/middleware"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
@ -10,6 +12,7 @@ import (
"io" "io"
"net/http" "net/http"
"os" "os"
"path/filepath"
) )
type AppEngine struct { type AppEngine struct {
@ -77,6 +80,13 @@ func (ae *AppEngine) Start() error {
logger.SetOutput(io.MultiWriter(os.Stderr, logFile)) logger.SetOutput(io.MultiWriter(os.Stderr, logFile))
} }
//check if the database parent directory exists, fail here rather than in a handler.
if !utils.FileExists(filepath.Dir(ae.Config.GetString("web.database.location"))) {
return errors.ConfigValidationError(fmt.Sprintf(
"Database parent directory does not exist. Please check path (%s)",
filepath.Dir(ae.Config.GetString("web.database.location"))))
}
r := ae.Setup(logger) r := ae.Setup(logger)
return r.Run(fmt.Sprintf("%s:%s", ae.Config.GetString("web.listen.host"), ae.Config.GetString("web.listen.port"))) return r.Run(fmt.Sprintf("%s:%s", ae.Config.GetString("web.listen.host"), ae.Config.GetString("web.listen.port")))

Loading…
Cancel
Save