diff options
author | Matthew Lemon <y@yulqen.org> | 2024-02-09 16:07:06 +0000 |
---|---|---|
committer | Matthew Lemon <y@yulqen.org> | 2024-02-09 16:07:06 +0000 |
commit | ed2cb5414da47a225fe2080a7cf4e3c685a129ec (patch) | |
tree | 09aed47d49cb3dca6c6bf633f89254f409381b5f | |
parent | 70a695c6cdf5adfe89aeec721369f0edab30dcee (diff) |
Adds flags
Accepts -addr for the port.
Commented out flag for dsn (database string) - not yet implemented.
See https://github.com/go-sql-driver/mysql#dsn-data-source-name for the
correct format to be used for MySQL/MariaDB.
-rw-r--r-- | Makefile | 5 | ||||
-rw-r--r-- | cmd/web/main.go | 9 |
2 files changed, 11 insertions, 3 deletions
@@ -1,6 +1,9 @@ -run: +docker-run: @docker run -d --name ded-core -p 4000:4000 --rm ded-core:latest +run: + @go run ./cmd/web -addr ":4000" + build: @docker build -t ded-core . diff --git a/cmd/web/main.go b/cmd/web/main.go index d388364..a4082fd 100644 --- a/cmd/web/main.go +++ b/cmd/web/main.go @@ -1,6 +1,7 @@ package main import ( + "flag" "log" "log/slog" "net/http" @@ -12,6 +13,10 @@ type application struct { } func main() { + addr := flag.String("addr", ":4000", "HTTP network port") + // dsn := flag.String("dsn", "web:dedpassword:/ded?parseTime=true", "MySQL data source name") + flag.Parse() + logger := slog.New(slog.NewTextHandler(os.Stdout, nil)) app := &application{ logger: logger, @@ -19,7 +24,7 @@ func main() { // mux := http.NewServeMux() // mux.HandleFunc("/", home) // log.Print("starting server on :4000") - logger.Info("starting server on :4000") - err := http.ListenAndServe(":4000", app.routes()) + logger.Info("starting server", "addr", *addr) + err := http.ListenAndServe(*addr, app.routes()) log.Fatal(err) } |