implement webserver

This commit is contained in:
Aleksandr Trushkin
2023-12-17 21:21:13 +03:00
parent f60ebcfb36
commit 1d4e8e10fb
12 changed files with 499 additions and 179 deletions

39
cmd/kuriweb/config.go Normal file
View 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,
},
}
}