diff options
author | Alexander NeonXP Kiryukhin <i@neonxp.ru> | 2024-04-06 22:16:56 +0300 |
---|---|---|
committer | Alexander NeonXP Kiryukhin <i@neonxp.ru> | 2024-04-06 22:17:59 +0300 |
commit | fcb71b492a5b69dabb0d6aef969ef0ea8e8ac7a3 (patch) | |
tree | a8e9459de601f7060befaf59f9aab8818d8244f4 | |
parent | 33f9af39187c56f696a9aa7a64a7432b402c4cb3 (diff) |
поправил флаги
-rw-r--r-- | main.go | 13 |
1 files changed, 6 insertions, 7 deletions
@@ -3,6 +3,7 @@ package main import ( "context" "encoding/json" + "flag" "html/template" "log/slog" "net/http" @@ -15,19 +16,17 @@ import ( var ( templates = template.Must(template.ParseFS(tplFS, "tpl/*.gohtml")) packages = Packages{} + bindAddr = flag.String("bind", ":8080", "Address to bind") + config = flag.String("config", "/etc/pkg/config.json", "Config file path") ) func main() { - addr := os.Getenv("ADDR") - if addr == "" { - addr = ":8080" - } ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, os.Kill) defer cancel() cfg := &Config{} - fp, err := os.Open("./config.json") + fp, err := os.Open(*config) if err != nil { panic(err) } @@ -73,14 +72,14 @@ func main() { srv := &http.Server{ Handler: h, - Addr: addr, + Addr: *bindAddr, } go func() { <-ctx.Done() srv.Shutdown(context.Background()) }() - logger.Info("server started", slog.String("bind", addr)) + logger.Info("server started", slog.String("bind", *bindAddr)) if err := srv.ListenAndServe(); err != http.ErrServerClosed { panic(err) } |