40 lines
709 B
Go
40 lines
709 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"`
|
|
HTTP config.HTTP `json:"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,
|
|
},
|
|
}
|
|
}
|