Skip to content

Commit 1da7c9e

Browse files
committed
docs: readme
1 parent 25df732 commit 1da7c9e

1 file changed

Lines changed: 14 additions & 12 deletions

File tree

README.md

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,36 +33,38 @@ go get github.com/goforj/web
3333
package main
3434

3535
import (
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

4545
func 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

Comments
 (0)