...
1 package main
2
3 import (
4 "net/http"
5
6 "github.com/go-chi/chi"
7 "github.com/go-chi/chi/middleware"
8 )
9
10 func init() {
11 chi.RegisterMethod("LINK")
12 chi.RegisterMethod("UNLINK")
13 chi.RegisterMethod("WOOHOO")
14 }
15
16 func main() {
17 r := chi.NewRouter()
18 r.Use(middleware.RequestID)
19 r.Use(middleware.Logger)
20 r.Get("/", func(w http.ResponseWriter, r *http.Request) {
21 w.Write([]byte("hello world"))
22 })
23 r.MethodFunc("LINK", "/link", func(w http.ResponseWriter, r *http.Request) {
24 w.Write([]byte("custom link method"))
25 })
26 r.MethodFunc("WOOHOO", "/woo", func(w http.ResponseWriter, r *http.Request) {
27 w.Write([]byte("custom woohoo method"))
28 })
29 r.HandleFunc("/everything", func(w http.ResponseWriter, r *http.Request) {
30 w.Write([]byte("capturing all standard http methods, as well as LINK, UNLINK and WOOHOO"))
31 })
32 http.ListenAndServe(":3333", r)
33 }
34
View as plain text