Skip to content

Commit

Permalink
mars: Add separate 'Setup' step to intialization to allow overriding …
Browse files Browse the repository at this point in the history
…configs.
  • Loading branch information
roblillack committed Aug 26, 2024
1 parent 0c5c20e commit 05d6467
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
3 changes: 1 addition & 2 deletions fakeapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,5 @@ func startFakeBookingApp() {
ERROR = TRACE

InitDefaults("prod", "testdata")

runStartupHooks()
Setup()
}
28 changes: 16 additions & 12 deletions mars.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,20 +112,13 @@ func init() {
log.SetFlags(defaultLoggerFlags)
}

// InitDefaults initializes Mars based on runtime-loading of config files.
//
// Params:
// mode - the run mode, which determines which app.conf settings are used.
// basePath - the path to the configuration, messages, and view directories
func InitDefaults(mode, basePath string) {
func Init(mode string) {
RunMode = mode

if runtime.GOOS == "windows" {
gocolorize.SetPlain(true)
}

BasePath = filepath.FromSlash(basePath)

var cfgPath string
if filepath.IsAbs(ConfigFile) {
cfgPath = ConfigFile
Expand Down Expand Up @@ -199,7 +192,22 @@ func InitDefaults(mode, basePath string) {
CookieDomain = Config.StringDefault("cookie.domain", CookieDomain)
CookieHttpOnly = Config.BoolDefault("cookie.httponly", CookieHttpOnly)
CookieSecure = Config.BoolDefault("cookie.secure", CookieSecure)
}

// InitDefaults initializes Mars based on runtime-loading of config files.
//
// Params:
//
// mode - the run mode, which determines which app.conf settings are used.
// basePath - the path to the configuration, messages, and view directories
func InitDefaults(mode, basePath string) {
BasePath = filepath.FromSlash(basePath)
Init(mode)
}

// Setup sets up the Mars framework and any custom components by running the
// startup hooks and setting up the views and router.
func Setup() {
if s := Config.StringDefault("app.secret", ""); s != "" {
SetAppSecret(s)
}
Expand All @@ -214,10 +222,6 @@ func InitDefaults(mode, basePath string) {
WARN = getLogger("warn", WARN)
ERROR = getLogger("error", ERROR)

setup()
}

func setup() {
// The "watch" config variable can turn on and off all watching.
// (As a convenient way to control it all together.)
if Config.BoolDefault("watch", DevMode) {
Expand Down
2 changes: 1 addition & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func initGracefulShutdown() {

func Run() {
if !setupDone {
setup()
Setup()
}

if DevMode {
Expand Down

0 comments on commit 05d6467

Please sign in to comment.