From 55efc5bec9703a299de5aac89006ed85600445fc Mon Sep 17 00:00:00 2001 From: Alan Pearce Date: Mon, 13 May 2024 19:34:12 +0200 Subject: refactor(config): simplify configuration commit 8225dbdb692c99b39dcafe2e5ec6ddc4daf08fb5 Author: Alan Pearce Date: Mon May 13 19:18:26 2024 +0200 refactor: consolidate configuration to reduce command-line options commit 5616d4c5a9bc6c0c14f744f812fa6609f859dc34 Author: Alan Pearce Date: Mon May 13 17:41:58 2024 +0200 refactor: move config file parsing to program entry points --- serve/main.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'serve') diff --git a/serve/main.go b/serve/main.go index 9ba2113..709d340 100644 --- a/serve/main.go +++ b/serve/main.go @@ -1,36 +1,36 @@ package main import ( - "fmt" + "flag" "log" "log/slog" "os" "os/signal" "sync" + "searchix/internal/config" "searchix/internal/server" +) - "github.com/ardanlabs/conf/v3" - "github.com/pkg/errors" +var ( + liveReload = flag.Bool("live", false, "whether to enable live reloading (development)") + configFile = flag.String("config", "config.toml", "config file to use") ) func main() { - runtimeConfig := server.Config{} - help, err := conf.Parse("", &runtimeConfig) + flag.Parse() + + conf, err := config.GetConfig(*configFile) if err != nil { - if errors.Is(err, conf.ErrHelpWanted) { - fmt.Println(help) - os.Exit(1) - } - log.Panicf("parsing runtime configuration: %v", err) + log.Panicf("error parsing configuration file: %v", err) } - slog.SetLogLoggerLevel(runtimeConfig.LogLevel) + slog.SetLogLoggerLevel(conf.LogLevel) log.SetFlags(log.LstdFlags | log.Lmsgprefix) log.SetPrefix("searchix: ") c := make(chan os.Signal, 2) signal.Notify(c, os.Interrupt) - sv, err := server.New(&runtimeConfig) + sv, err := server.New(conf, *liveReload) if err != nil { log.Fatalf("error setting up server: %v", err) } -- cgit 1.4.1