-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
example_goblin_test.go
51 lines (39 loc) · 1.39 KB
/
example_goblin_test.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
package goblin_test
import (
"log"
"net/http"
"github.com/bmf-san/goblin"
)
func CORS(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})
}
func RootHandler() http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})
}
func FooHandler() http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})
}
func FooBarHandler() http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})
}
func FooBarNameHandler() http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})
}
func FooNameHandler() http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})
}
func BazHandler() http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})
}
func ExampleListenAndServe() {
r := goblin.NewRouter()
r.Methods(http.MethodGet).Handler(`/`, RootHandler())
r.Methods(http.MethodGet, http.MethodPost).Use(CORS).Handler(`/foo`, FooHandler())
r.Methods(http.MethodGet).Handler(`/foo/bar`, FooBarHandler())
r.Methods(http.MethodGet).Handler(`/foo/bar/:name`, FooBarNameHandler())
r.Methods(http.MethodPost).Use(CORS).Handler(`/foo/:name`, FooNameHandler())
r.Methods(http.MethodGet).Handler(`/baz`, BazHandler())
if err := http.ListenAndServe(":9999", r); err != nil {
log.Fatal(err)
}
}