Skip to content

Commit

Permalink
docs(readme): expand on the basic example
Browse files Browse the repository at this point in the history
  • Loading branch information
utilyre committed Nov 11, 2024
1 parent f2dd476 commit f095fd8
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ import (
func main() {
mux := http.NewServeMux()

sh := statusHandler{}
sh := statusHandler{
Brief: "healthy",
Description: "service is ready to accept connections",
}

mux.HandleFunc("GET /{$}", xmate.HandleFunc(handleHelloWorld))
mux.Handle("GET /status", xmate.Handle(sh))
Expand All @@ -64,12 +67,15 @@ func handleHelloWorld(w http.ResponseWriter, r *http.Request) error {
return xmate.WriteText(w, http.StatusOK, "hello world")
}

type statusHandler struct{}
type statusHandler struct {
Brief string
Description string
}

func (sh statusHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) error {
return xmate.WriteJSON(w, http.StatusOK, map[string]any{
"status": "healthy",
"description": "service is ready to accept connections.",
"brief": sh.Brief,
"description": sh.Description,
})
}
```
Expand Down

0 comments on commit f095fd8

Please sign in to comment.