Skip to content
This repository was archived by the owner on May 24, 2020. It is now read-only.

Commit 7cee177

Browse files
committed
Move the /.status route definition in status.go
1 parent 6210890 commit 7cee177

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

handler.go

+4-12
Original file line numberDiff line numberDiff line change
@@ -141,21 +141,10 @@ func (self *ResourceHandler) SetRoutes(routes ...Route) error {
141141
routes: routes,
142142
}
143143

144-
self.env = &env{}
145-
146144
// add the status route as the last route.
147145
if self.EnableStatusService == true {
148146
self.statusService = newStatusService()
149-
self.internalRouter.routes = append(
150-
self.internalRouter.routes,
151-
Route{
152-
HttpMethod: "GET",
153-
PathExp: "/.status",
154-
Func: func(writer *ResponseWriter, request *Request) {
155-
self.statusService.getStatus(writer, request)
156-
},
157-
},
158-
)
147+
self.internalRouter.routes = append(self.internalRouter.routes, self.statusService.getRoute())
159148
}
160149

161150
// start the router
@@ -164,6 +153,9 @@ func (self *ResourceHandler) SetRoutes(routes ...Route) error {
164153
return err
165154
}
166155

156+
// extra init actions
157+
self.env = &env{}
158+
167159
return nil
168160
}
169161

status.go

+10
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ func newStatusService() *statusService {
4040
}
4141
}
4242

43+
func (self *statusService) getRoute() Route {
44+
return Route{
45+
HttpMethod: "GET",
46+
PathExp: "/.status",
47+
Func: func(writer *ResponseWriter, request *Request) {
48+
self.getStatus(writer, request)
49+
},
50+
}
51+
}
52+
4353
func (self *statusService) update(statusCode int, responseTime *time.Duration) {
4454
self.lock.Lock()
4555
self.responseCounts[fmt.Sprintf("%d", statusCode)]++

0 commit comments

Comments
 (0)