default options handler

This commit is contained in:
2024-11-04 11:00:02 +05:30
parent c34f5b7d0d
commit 894614cd54
5 changed files with 28 additions and 32 deletions

View File

@@ -25,7 +25,7 @@ func main() {
r.Use(middleware1, middleware2)
// let's add a route
r.Get("/hello", func(w http.ResponseWriter, r *http.Request) {
r.GET("/hello", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("i am route /hello"))
})
// r.Post(pattern string, h http.HandlerFunc)
@@ -35,7 +35,7 @@ func main() {
// you can inline middleware(s) to a route
r.
With(mwInline).
Get("/hello-2", func(w http.ResponseWriter, r *http.Request) {
GET("/hello-2", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("i am route /hello-2 with my own middleware"))
})
@@ -62,13 +62,13 @@ func main() {
// create a group of few routes with their own middlewares
r.Group(func(grp *mux.Router) {
grp.Use(mwGroup)
grp.Get("/group", func(w http.ResponseWriter, r *http.Request) {
grp.GET("/group", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("i am route /group"))
})
})
// catches all
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
r.GET("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("hello there"))
})