Skip to content

Commit

Permalink
fail if the parent directory for database does not exist.
Browse files Browse the repository at this point in the history
  • Loading branch information
AnalogJ committed Oct 9, 2020
1 parent bd2f305 commit bf07077
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions webapp/backend/pkg/web/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ package web

import (
"fmt"
"github.com/analogj/go-util/utils"
"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/middleware"
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
"io"
"net/http"
"os"
"path/filepath"
)

type AppEngine struct {
Expand Down Expand Up @@ -77,6 +80,13 @@ func (ae *AppEngine) Start() error {
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)

return r.Run(fmt.Sprintf("%s:%s", ae.Config.GetString("web.listen.host"), ae.Config.GetString("web.listen.port")))
Expand Down

0 comments on commit bf07077

Please sign in to comment.