From ed2cb5414da47a225fe2080a7cf4e3c685a129ec Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Fri, 9 Feb 2024 16:07:06 +0000 Subject: 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. --- cmd/web/main.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'cmd/web/main.go') 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) } -- cgit v1.2.3