Files
kurious/cmd/kuriweb/config.go
2024-04-02 15:23:22 +03:00

43 lines
851 B
Go

package main
import (
"encoding/json"
"fmt"
"os"
"git.loyso.art/frx/kurious/internal/common/config"
)
type Config struct {
Log config.Log `json:"log"`
YDB config.YDB `json:"ydb"`
Sqlite config.Sqlite `json:"sqlite"`
HTTP config.HTTP `json:"http"`
Tracing config.Trace `json:"tracing"`
DBEngine string `json:"db_engine"`
}
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,
},
}
}