-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmethod.go
50 lines (40 loc) · 1.56 KB
/
method.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
40
41
42
43
44
45
46
47
48
49
50
package fux
import (
"github.com/gorilla/mux"
"net/http"
)
type (
Handler func(w http.ResponseWriter, request *http.Request)
)
// Get defines a route with GET method.
func (f *Fux) Get(pattern string, handler Handler) *mux.Route {
return f.Router.HandleFunc(pattern, handler).Methods(http.MethodGet)
}
// Post defines a route with POST method.
func (f *Fux) Post(pattern string, handler Handler) *mux.Route {
return f.Router.HandleFunc(pattern, handler).Methods(http.MethodPost)
}
// Put defines a route with PUT method.
func (f *Fux) Put(pattern string, handler Handler) *mux.Route {
return f.Router.HandleFunc(pattern, handler).Methods(http.MethodPut)
}
// Patch defines a route with PATCH method.
func (f *Fux) Patch(pattern string, handler Handler) *mux.Route {
return f.Router.HandleFunc(pattern, handler).Methods(http.MethodPatch)
}
// Delete defines a route with DELETE method.
func (f *Fux) Delete(pattern string, handler Handler) *mux.Route {
return f.Router.HandleFunc(pattern, handler).Methods(http.MethodDelete)
}
// HandleFunc defines a route without method.
// You can define methods like this HandleFunc(...).methods(http.MethodGet,...)
func (f *Fux) HandleFunc(pattern string, handler Handler) *mux.Route {
return f.Router.HandleFunc(pattern, handler)
}
// Handle registers a new route with a matcher for the URL path.
func (f *Fux) Handle(pattern string, handler http.Handler) *mux.Route {
return f.Router.Handle(pattern, handler)
}
func (f *Fux) FileServer(pattern string, root http.FileSystem) *mux.Route {
return f.Handle(pattern, http.FileServer(root))
}