implement webserver
This commit is contained in:
39
cmd/kuriweb/config.go
Normal file
39
cmd/kuriweb/config.go
Normal file
@ -0,0 +1,39 @@
|
||||
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,
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user