diff options
author | Alan Pearce | 2024-05-13 19:34:12 +0200 |
---|---|---|
committer | Alan Pearce | 2024-05-13 19:34:12 +0200 |
commit | 55efc5bec9703a299de5aac89006ed85600445fc (patch) | |
tree | 2e73e77ead7b6ad3820b3622be2b779b369e66ad /serve/main.go | |
parent | 37deedc9b1da92571548c920721984d545269eb4 (diff) | |
download | searchix-55efc5bec9703a299de5aac89006ed85600445fc.tar.lz searchix-55efc5bec9703a299de5aac89006ed85600445fc.tar.zst searchix-55efc5bec9703a299de5aac89006ed85600445fc.zip |
refactor(config): simplify configuration
commit 8225dbdb692c99b39dcafe2e5ec6ddc4daf08fb5 Author: Alan Pearce <alan@alanpearce.eu> Date: Mon May 13 19:18:26 2024 +0200 refactor: consolidate configuration to reduce command-line options commit 5616d4c5a9bc6c0c14f744f812fa6609f859dc34 Author: Alan Pearce <alan@alanpearce.eu> Date: Mon May 13 17:41:58 2024 +0200 refactor: move config file parsing to program entry points
Diffstat (limited to 'serve/main.go')
-rw-r--r-- | serve/main.go | 24 |
1 files changed, 12 insertions, 12 deletions
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) } |