Change config behavior

This commit is contained in:
Thomas Miceli 2023-04-07 23:58:06 +02:00
parent db36ec6002
commit 31bec62834
No known key found for this signature in database
GPG key ID: D86C6F6390AF050F
3 changed files with 29 additions and 15 deletions

View file

@ -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

View file

@ -70,9 +70,17 @@ 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)
@ -81,6 +89,9 @@ func InitConfig(configPath string) error {
}
defer file.Close()
}
} else {
fmt.Println("No config file specified. Using default values.")
}
// Override default values with environment variables (as yaml)
configEnv := os.Getenv("CONFIG")
@ -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
}
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) {

View file

@ -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 {