ref: master
server/router.go
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
package server import ( "fmt" "log/slog" "net/http" "os" ) func Route(host string, port int) { listenAddress := fmt.Sprintf("%s:%d", host, port) srv := &http.Server{Addr: listenAddress} http.HandleFunc("GET /users/{userID}", func(w http.ResponseWriter, r *http.Request) { getUser(r.PathValue("userID"), w, r) }) http.HandleFunc("POST /users/{userID}/subscriptions/", func(w http.ResponseWriter, r *http.Request) { validateTicket(r.PathValue("userID"), w, r) }) if err := srv.ListenAndServe(); err != http.ErrServerClosed { slog.Error("ListenAndServe error", slog.Any("error", err)) os.Exit(1) } } |