mirror of
https://github.com/thomiceli/opengist.git
synced 2025-01-03 16:22:40 +00:00
Change config behavior
This commit is contained in:
parent
db36ec6002
commit
31bec62834
3 changed files with 29 additions and 15 deletions
2
Makefile
2
Makefile
|
@ -31,7 +31,7 @@ watch_frontend:
|
||||||
|
|
||||||
watch_backend:
|
watch_backend:
|
||||||
@echo "Building Opengist binary..."
|
@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:
|
watch:
|
||||||
@bash ./watch.sh
|
@bash ./watch.sh
|
||||||
|
|
|
@ -70,16 +70,27 @@ func InitConfig(configPath string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
file, err := os.Open(configPath)
|
if configPath != "" {
|
||||||
if err == nil {
|
absolutePath, _ := filepath.Abs(configPath)
|
||||||
fmt.Println("Using config file: " + 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
|
// Override default values with values from config.yml
|
||||||
d := yaml.NewDecoder(file)
|
d := yaml.NewDecoder(file)
|
||||||
if err = d.Decode(&c); err != nil {
|
if err = d.Decode(&c); err != nil {
|
||||||
return err
|
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)
|
// Override default values with environment variables (as yaml)
|
||||||
|
@ -105,7 +116,6 @@ func InitLog() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
multi := zerolog.MultiLevelWriter(zerolog.NewConsoleWriter(), file)
|
|
||||||
|
|
||||||
var level zerolog.Level
|
var level zerolog.Level
|
||||||
level, err = zerolog.ParseLevel(C.LogLevel)
|
level, err = zerolog.ParseLevel(C.LogLevel)
|
||||||
|
@ -113,7 +123,12 @@ func InitLog() {
|
||||||
level = zerolog.InfoLevel
|
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) {
|
func CheckGitVersion(version string) (bool, error) {
|
||||||
|
|
|
@ -16,11 +16,10 @@ import (
|
||||||
func initialize() {
|
func initialize() {
|
||||||
fmt.Println("Opengist v" + config.OpengistVersion)
|
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()
|
flag.Parse()
|
||||||
absolutePath, _ := filepath.Abs(*configPath)
|
|
||||||
absolutePath = filepath.Clean(absolutePath)
|
if err := config.InitConfig(*configPath); err != nil {
|
||||||
if err := config.InitConfig(absolutePath); err != nil {
|
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
if err := os.MkdirAll(filepath.Join(config.GetHomeDir()), 0755); err != nil {
|
if err := os.MkdirAll(filepath.Join(config.GetHomeDir()), 0755); err != nil {
|
||||||
|
|
Loading…
Reference in a new issue