package main import ( "fmt" "strings" "github.com/gin-gonic/gin" "github.com/knadh/koanf" "github.com/knadh/koanf/parsers/toml" "github.com/knadh/koanf/providers/env" "github.com/knadh/koanf/providers/file" "github.com/rs/zerolog" "github.com/rs/zerolog/log" "git.grassecon.net/grassrootseconomics/openethereum-node-status/internal/server" "git.grassecon.net/grassrootseconomics/openethereum-node-status/pkg/rpc" ) const ( confEnvOverridePrefix = "" ) var ( conf = koanf.New(".") ) func main() { zerolog.TimeFieldFormat = zerolog.TimeFormatUnix zerolog.SetGlobalLevel(zerolog.InfoLevel) ginMode := gin.ReleaseMode // confini style config loading/overriding confFile := file.Provider("config/config.toml") if err := conf.Load(confFile, toml.Parser()); err != nil { log.Fatal(). Err(err). Str("service", "koanf"). Msg("cannot load config file") } if err := conf.Load(env.Provider(confEnvOverridePrefix, ".", func(s string) string { return strings.ReplaceAll(strings.ToLower( strings.TrimPrefix(s, confEnvOverridePrefix)), "_", ".") }), nil); err != nil { log.Fatal(). Err(err). Str("module", "main"). Msg("cannot load env variables") } if conf.Bool("debug.enabled") { zerolog.SetGlobalLevel(zerolog.DebugLevel) ginMode = gin.DebugMode log.Debug().Str("module", "main").Msg("debug mode enabled") } server.RpcClient = rpc.NewRpcClient(conf.String("rpc.endpoint")) if err := server.Start(fmt.Sprintf(":%s", conf.String("server.port")), ginMode); err != nil { log.Fatal(). Err(err). Str("module", "main"). Msg("could not start server") } }