File tree Expand file tree Collapse file tree 1 file changed +12
-5
lines changed
Expand file tree Collapse file tree 1 file changed +12
-5
lines changed Original file line number Diff line number Diff line change 11package main
22
33import (
4- "github.com/thoas/stats "
4+ "encoding/json "
55 "net/http"
6+
7+ "github.com/thoas/stats"
68)
79
810func main () {
9- h := http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
11+ middleware := stats .New ()
12+ mux := http .NewServeMux ()
13+ mux .HandleFunc ("/hello" , func (w http.ResponseWriter , r * http.Request ) {
1014 w .Header ().Set ("Content-Type" , "application/json" )
1115 w .Write ([]byte ("{\" hello\" : \" world\" }" ))
1216 })
13-
14- handler := stats .New ().Handler (h )
15- http .ListenAndServe (":8080" , handler )
17+ mux .HandleFunc ("/stats" , func (w http.ResponseWriter , r * http.Request ) {
18+ w .Header ().Set ("Content-Type" , "application/json" )
19+ b , _ := json .Marshal (middleware .Data ())
20+ w .Write (b )
21+ })
22+ http .ListenAndServe (":8080" , middleware .Handler (mux ))
1623}
You can’t perform that action at this time.
0 commit comments