-
Notifications
You must be signed in to change notification settings - Fork 1
/
handlers.go
39 lines (30 loc) · 1.12 KB
/
handlers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package mux
import "net/http"
func (ro *Router) GET(path string, handlerFunc HandlerFunc) {
ro.Route("GET", path, handlerFunc)
}
func (ro *Router) POST(path string, handlerFunc HandlerFunc) {
ro.Route("POST", path, handlerFunc)
}
func (ro *Router) DELETE(path string, handlerFunc HandlerFunc) {
ro.Route("DELETE", path, handlerFunc)
}
func (ro *Router) PATCH(path string, handlerFunc HandlerFunc) {
ro.Route("PATCH", path, handlerFunc)
}
// Default error handlers (NotFound, MethodNotAllowed)
func defaultMethodNotAllowedHandler(c *Context) {
c.ResponseWriter.Header().Set("Content-Type", "application/json")
c.ResponseWriter.WriteHeader(http.StatusMethodNotAllowed)
c.ResponseWriter.Write(errMethodNotAllowed)
}
func defaultNotFoundHandler(c *Context) {
c.ResponseWriter.Header().Set("Content-Type", "application/json")
c.ResponseWriter.WriteHeader(http.StatusNotFound)
c.ResponseWriter.Write(errNotFound)
}
func defaultInternalErrorHandler(c *Context) {
c.ResponseWriter.Header().Set("Content-Type", "application/json")
c.ResponseWriter.WriteHeader(http.StatusInternalServerError)
c.ResponseWriter.Write(errInternalError)
}