Skip to content

Commit dea27f2

Browse files
committed
Add ping and stats route
1 parent 7ff62c5 commit dea27f2

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

route.go

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package mmbot
22

3-
import "net/http"
3+
import (
4+
"net/http"
5+
6+
"github.com/fukata/golang-stats-api-handler"
7+
)
48

59
// RouteHandlerFunc is route action function.
610
type RouteHandlerFunc func(*Robot, http.ResponseWriter, *http.Request)
@@ -19,3 +23,25 @@ type Route struct {
1923
// Route action.
2024
Action RouteHandlerFunc
2125
}
26+
27+
// NewPingRoute returns the route "ping".
28+
func NewPingRoute(pattern string) Route {
29+
return Route{
30+
Methods: []string{"GET"},
31+
Pattern: pattern,
32+
Action: func(bot *Robot, w http.ResponseWriter, r *http.Request) {
33+
w.Write([]byte("pong"))
34+
},
35+
}
36+
}
37+
38+
// NewStatsRoute returns the route for statistics of the process.
39+
func NewStatsRoute(pattern string) Route {
40+
return Route{
41+
Methods: []string{"GET"},
42+
Pattern: pattern,
43+
Action: func(bot *Robot, w http.ResponseWriter, r *http.Request) {
44+
stats_api.Handler(w, r)
45+
},
46+
}
47+
}

0 commit comments

Comments
 (0)