diff options
author | Alan Pearce | 2024-04-24 13:36:57 +0200 |
---|---|---|
committer | Alan Pearce | 2024-04-24 13:36:57 +0200 |
commit | 27f92894b50ffc2058c1b2f0db4d78d47a48c843 (patch) | |
tree | 6d832b323939c23a8c58a358507417cc2002a633 /cmd/server/main.go | |
parent | 40ab775c0a63b9fc4ff84c6ae59ab00650b07ee3 (diff) | |
download | website-27f92894b50ffc2058c1b2f0db4d78d47a48c843.tar.lz website-27f92894b50ffc2058c1b2f0db4d78d47a48c843.tar.zst website-27f92894b50ffc2058c1b2f0db4d78d47a48c843.zip |
split code into separate files
Diffstat (limited to 'cmd/server/main.go')
-rw-r--r-- | cmd/server/main.go | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/cmd/server/main.go b/cmd/server/main.go new file mode 100644 index 0000000..9fb9f14 --- /dev/null +++ b/cmd/server/main.go @@ -0,0 +1,38 @@ +package main + +import ( + "fmt" + "log" + "log/slog" + "os" + cfg "website/internal/config" + + "github.com/ardanlabs/conf/v3" + "github.com/pkg/errors" +) + +type Config struct { + Production bool `conf:"default:false"` + ListenAddress string `conf:"default:localhost"` + Port uint16 `conf:"default:3000,short:p"` + BaseURL cfg.URL `conf:"default:http://localhost:3000,short:b"` + RedirectOtherHostnames bool `conf:"default:false"` +} + +func main() { + if os.Getenv("DEBUG") != "" { + slog.SetLogLoggerLevel(slog.LevelDebug) + } + + runtimeConfig := Config{} + help, err := conf.Parse("", &runtimeConfig) + if err != nil { + if errors.Is(err, conf.ErrHelpWanted) { + fmt.Println(help) + os.Exit(1) + } + log.Panicf("parsing runtime configuration: %v", err) + } + + startServer(&runtimeConfig) +} |