summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorAlexander NeonXP Kiryukhin <i@neonxp.ru>2024-04-06 22:16:56 +0300
committerAlexander NeonXP Kiryukhin <i@neonxp.ru>2024-04-06 22:17:59 +0300
commitfcb71b492a5b69dabb0d6aef969ef0ea8e8ac7a3 (patch)
treea8e9459de601f7060befaf59f9aab8818d8244f4 /main.go
parent33f9af39187c56f696a9aa7a64a7432b402c4cb3 (diff)
поправил флаги
Diffstat (limited to 'main.go')
-rw-r--r--main.go13
1 files changed, 6 insertions, 7 deletions
diff --git a/main.go b/main.go
index 49abeb8..0878c9a 100644
--- a/main.go
+++ b/main.go
@@ -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)
}