Skip to content

Commit

Permalink
fix(api): update config
Browse files Browse the repository at this point in the history
  • Loading branch information
runar-rkmedia committed Nov 16, 2021
1 parent 7bc1c06 commit 457a5d0
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions api/apiMain.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ func (ps *PubSub) Publish(kind, variant string, content interface{}) {
}
}

func getDefaultDBLocation() string {
if s, err := os.Stat("./gobyoall.bbolt"); err == nil && !s.IsDir() {
return "./storage/gobyoall.bbolt"
} else if s, err := os.Stat("./storage"); err == nil && s.IsDir() {
return "./storage/gobyoall.bbolt"
}
return "./gobyoall.bbolt"
}

//go:generate swagger generate spec -o generated-swagger.yml
//go:generate sh -c "cd ../frontend && yarn gen"
func main() {
Expand All @@ -100,16 +109,25 @@ func main() {
if config.LogLevel == "" {
config.LogLevel = "info"
}
if cfg.DBLocation == "" {
cfg.DBLocation = getDefaultDBLocation()
}
logger.InitLogger(logger.LogConfig{
Level: config.LogLevel,
Format: config.LogFormat,
// We add this option during local development, but also if loglevel is debug
WithCaller: config.LogLevel == "debug" || GitHash == "",
})
l := logger.GetLogger("main")
l.Info().Str("version", Version).Time("buildDate", BuildDate).Time("buildDateLocal", BuildDate.Local()).Str("gitHash", GitHash).Msg("Starting")
l.Info().
Str("version", Version).
Time("buildDate", BuildDate).
Time("buildDateLocal", BuildDate.Local()).
Str("gitHash", GitHash).
Str("db", config.Api.DBLocation).
Msg("Starting")
pubsub := PubSub{make(chan handlers.Msg)}
db, err := bboltStorage.NewBbolt(l, "db.bbolt", &pubsub)
db, err := bboltStorage.NewBbolt(l, cfg.DBLocation, &pubsub)
if err != nil {
l.Fatal().Err(err).Msg("Failed to initialize storage")
}
Expand Down

0 comments on commit 457a5d0

Please sign in to comment.