@@ -33,36 +33,38 @@ go get github.com/goforj/web
3333package main
3434
3535import (
36+ " fmt"
3637 " log"
3738 " net/http"
3839
3940 " github.com/goforj/web"
4041 " github.com/goforj/web/adapter/echoweb"
4142 " github.com/goforj/web/webmiddleware"
42- " github.com/goforj/web/webprometheus"
4343)
4444
4545func main () {
4646 // Pick an adapter that satisfies the app-facing web.Router contract.
4747 adapter := echoweb.New ()
4848 router := adapter.Router ()
4949
50- // Attach reusable middleware for request IDs and Prometheus metrics.
51- metrics , _ := webprometheus.New (webprometheus.Config {Namespace: " app" })
52- prometheusMW := metrics.Middleware ()
53- requestID := webmiddleware.RequestID ()
50+ // Attach common app middleware once near the top of the stack.
51+ router.Use (
52+ webmiddleware.Recover (),
53+ webmiddleware.RequestID (),
54+ )
5455
55- router.Use (func (next web.Handler ) web.Handler {
56- return requestID (prometheusMW (next))
57- })
58-
59- // Register normal application routes.
56+ // Register a basic health route for uptime checks and local smoke tests.
6057 router.GET (" /healthz" , func (c web.Context ) error {
6158 return c.Text (http.StatusOK , " ok" )
6259 })
6360
64- // Expose operational diagnostics on a dedicated route.
65- router.GET (" /metrics" , metrics.Handler ())
61+ // Register an actual application route that returns JSON.
62+ router.GET (" /users/:id" , func (c web.Context ) error {
63+ return c.JSON (http.StatusOK , map [string ]any{
64+ " id" : c.Param (" id" ),
65+ " name" : fmt.Sprintf (" user-%s " , c.Param (" id" )),
66+ })
67+ })
6668
6769 // Boot the HTTP server with the adapter as the final handler.
6870 log.Fatal (http.ListenAndServe (" :8080" , adapter))
0 commit comments