diff --git a/Makefile b/Makefile index fa7f489..cd6df67 100644 --- a/Makefile +++ b/Makefile @@ -31,7 +31,7 @@ watch_frontend: watch_backend: @echo "Building Opengist binary..." - DEV=1 ./node_modules/.bin/nodemon --watch '**/*' -e html,yml,go,js --signal SIGTERM --exec 'go' run . + DEV=1 ./node_modules/.bin/nodemon --watch '**/*' -e html,yml,go,js --signal SIGTERM --exec 'go run . --config config.yml' watch: @bash ./watch.sh diff --git a/internal/config/config.go b/internal/config/config.go index 69bb9a5..8f82138 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -70,16 +70,27 @@ func InitConfig(configPath string) error { return err } - file, err := os.Open(configPath) - if err == nil { - fmt.Println("Using config file: " + configPath) + if configPath != "" { + absolutePath, _ := filepath.Abs(configPath) + absolutePath = filepath.Clean(absolutePath) + file, err := os.Open(absolutePath) + if err != nil { + if !os.IsNotExist(err) { + return err + } + fmt.Println("No YML config file found at " + absolutePath) + } else { + fmt.Println("Using config file: " + absolutePath) - // Override default values with values from config.yml - d := yaml.NewDecoder(file) - if err = d.Decode(&c); err != nil { - return err + // Override default values with values from config.yml + d := yaml.NewDecoder(file) + if err = d.Decode(&c); err != nil { + return err + } + defer file.Close() } - defer file.Close() + } else { + fmt.Println("No config file specified. Using default values.") } // Override default values with environment variables (as yaml) @@ -105,7 +116,6 @@ func InitLog() { if err != nil { panic(err) } - multi := zerolog.MultiLevelWriter(zerolog.NewConsoleWriter(), file) var level zerolog.Level level, err = zerolog.ParseLevel(C.LogLevel) @@ -113,7 +123,12 @@ func InitLog() { level = zerolog.InfoLevel } - log.Logger = zerolog.New(multi).Level(level).With().Timestamp().Logger() + if os.Getenv("DEV") == "1" { + multi := zerolog.MultiLevelWriter(zerolog.NewConsoleWriter(), file) + log.Logger = zerolog.New(multi).Level(level).With().Timestamp().Logger() + } else { + log.Logger = zerolog.New(file).Level(level).With().Timestamp().Logger() + } } func CheckGitVersion(version string) (bool, error) { diff --git a/opengist.go b/opengist.go index bd7b130..2e2d79b 100644 --- a/opengist.go +++ b/opengist.go @@ -16,11 +16,10 @@ import ( func initialize() { fmt.Println("Opengist v" + config.OpengistVersion) - configPath := flag.String("config", "config.yml", "Path to a config file in YML format") + configPath := flag.String("config", "", "Path to a config file in YML format") flag.Parse() - absolutePath, _ := filepath.Abs(*configPath) - absolutePath = filepath.Clean(absolutePath) - if err := config.InitConfig(absolutePath); err != nil { + + if err := config.InitConfig(*configPath); err != nil { panic(err) } if err := os.MkdirAll(filepath.Join(config.GetHomeDir()), 0755); err != nil {