This repository has been archived by the owner on Oct 29, 2020. It is now read-only.
/
router.go
53 lines (41 loc) · 1.49 KB
/
router.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
51
52
53
// Copyright 2016 Fraunhofer Institute for Applied Information Technology FIT
package main
import (
"fmt"
"net/http"
"github.com/gorilla/mux"
)
type router struct {
*mux.Router
}
func newRouter() *router {
return &router{mux.NewRouter().StrictSlash(false).SkipClean(true)}
}
func (r *router) get(path string, handler http.Handler) {
r.Methods("GET").Path(path).Handler(handler)
r.Methods("GET").Path(fmt.Sprintf("%s/", path)).Handler(handler)
}
func (r *router) post(path string, handler http.Handler) {
r.Methods("POST").Path(path).Handler(handler)
r.Methods("POST").Path(fmt.Sprintf("%s/", path)).Handler(handler)
}
func (r *router) put(path string, handler http.Handler) {
r.Methods("PUT").Path(path).Handler(handler)
r.Methods("PUT").Path(fmt.Sprintf("%s/", path)).Handler(handler)
}
func (r *router) delete(path string, handler http.Handler) {
r.Methods("DELETE").Path(path).Handler(handler)
r.Methods("DELETE").Path(fmt.Sprintf("%s/", path)).Handler(handler)
}
func (r *router) patch(path string, handler http.Handler) {
r.Methods("PATCH").Path(path).Handler(handler)
r.Methods("PATCH").Path(fmt.Sprintf("%s/", path)).Handler(handler)
}
func (r *router) head(path string, handler http.Handler) {
r.Methods("HEAD").Path(path).Handler(handler)
r.Methods("HEAD").Path(fmt.Sprintf("%s/", path)).Handler(handler)
}
func (r *router) options(path string, handler http.Handler) {
r.Methods("OPTIONS").Path(path).Handler(handler)
r.Methods("OPTIONS").Path(fmt.Sprintf("%s/", path)).Handler(handler)
}