36
All checks were successful
Deploy Production / Deploy to Staging (push) Has been skipped

This commit is contained in:
Alex Shevchuk
2025-08-19 03:05:51 +03:00
parent 265e8e5b60
commit df176f8aea
2 changed files with 18 additions and 4 deletions

View File

@@ -2,6 +2,7 @@ package config
import ( import (
"errors" "errors"
"flag"
"fmt" "fmt"
"os" "os"
@@ -27,13 +28,26 @@ func MustLoad(version, commit, date string) *Config {
} }
func loadConfig() (*Config, error) { func loadConfig() (*Config, error) {
if _, err := os.Stat(ConfigBasePath); os.IsNotExist(err) { var configPath string
flag.StringVar(&configPath, "config_path", configPath, "Path to config file")
flag.Parse()
if configPath == "" {
if path := os.Getenv("CONFIG_PATH"); path != "" {
configPath = path
} else {
configPath = ConfigBasePath
}
}
if _, err := os.Stat(configPath); os.IsNotExist(err) {
return nil, fmt.Errorf("no config file found") return nil, fmt.Errorf("no config file found")
} }
var localConfig LocalDeploy var localConfig LocalDeploy
if err := cleanenv.ReadConfig(ConfigBasePath, &localConfig); err != nil { if err := cleanenv.ReadConfig(configPath, &localConfig); err != nil {
return nil, fmt.Errorf("error reading local config: %w", err) return nil, fmt.Errorf("error reading local config: %w", err)
} }
@@ -45,7 +59,7 @@ func loadConfig() (*Config, error) {
var cfg Config var cfg Config
if err := cleanenv.ReadConfig(ConfigBasePath, &cfg); err != nil { if err := cleanenv.ReadConfig(configPath, &cfg); err != nil {
return nil, err return nil, err
} }

View File

@@ -1,5 +1,5 @@
package config package config
const ( const (
ConfigBasePath = "/home/alexorel/work/Molva/molva-backend/.build/config/local.example.yaml" ConfigBasePath = "/config.yaml"
) )