package main import ( "encoding/json" "fmt" "os" "git.loyso.art/frx/kurious/internal/common/config" ) type dbEngine string const ( DBEngineUnknown dbEngine = "" DBEngineYDB dbEngine = "ydb" DBEngineSqlite dbEngine = "sqlite" ) type Config struct { Log config.Log `json:"log"` YDB config.YDB `json:"ydb"` Sqlite config.Sqlite `json:"sqlite"` DBEngine dbEngine `json:"db_engine"` SyncSravniCron string `json:"sync_sravni_cron"` DebugHTTP bool `json:"debug_http"` } func readFromFile(path string, defaultConfigF func() Config) (Config, error) { out := defaultConfigF() payload, err := os.ReadFile(path) if err != nil { return out, fmt.Errorf("opening file: %w", err) } err = json.Unmarshal(payload, &out) if err != nil { return out, fmt.Errorf("decoding as json: %w", err) } return out, nil } func defaultConfig() Config { return Config{ Log: config.Log{ Level: config.LogLevelInfo, Format: config.LogFormatText, }, // TODO: change to sqlite once it proven to be working DBEngine: DBEngineYDB, } }