1
0
Fork 0
mirror of https://github.com/imjasonh/gohtmx synced 2026-07-07 00:23:12 +00:00

use flags

Signed-off-by: Jason Hall <jason@chainguard.dev>
This commit is contained in:
Jason Hall 2025-09-01 09:30:20 -04:00
parent 3800004072
commit 188f20f48d

16
main.go
View file

@ -1,23 +1,31 @@
package main
import (
"flag"
"gohtmx/internal/app"
"log/slog"
"net/http"
)
var (
file = flag.String("file", "todos.jsonl", "Path to the JSONL file to store todos")
port = flag.String("port", "8080", "Port to run the server on")
)
func main() {
flag.Parse()
// Create the application
application := app.New("todos.jsonl")
application := app.New(*file)
// Set up routes
mux := http.NewServeMux()
application.SetupRoutes(mux)
// Start server
port := ":8080"
slog.Info("Starting server", "port", port)
if err := http.ListenAndServe(port, mux); err != nil {
slog.Info("Starting server", "port", *port)
if err := http.ListenAndServe(":"+*port, mux); err != nil {
slog.Error("Server failed to start", "error", err)
}
}