make it more readable

This commit is contained in:
Ankit Patial 2024-10-12 19:40:54 +05:30
parent 67667dd2ce
commit 3ed309536a

View File

@ -25,7 +25,7 @@ func main() {
// let's add a route // 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("hello1")) w.Write([]byte("i am route /hello"))
}) })
// r.Post(pattern string, h http.HandlerFunc) // r.Post(pattern string, h http.HandlerFunc)
// r.Put(pattern string, h http.HandlerFunc) // r.Put(pattern string, h http.HandlerFunc)
@ -34,8 +34,8 @@ func main() {
// you can inline middleware(s) to a route // you can inline middleware(s) to a route
r. r.
With(mwInline). With(mwInline).
Get("/test", func(w http.ResponseWriter, r *http.Request) { Get("/hello-2", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("middle ware 3 test")) w.Write([]byte("i am route /hello-2 with my own middleware"))
}) })
// you define a resource // you define a resource
@ -50,18 +50,18 @@ func main() {
// PATCH /photos/:id // PATCH /photos/:id
// DELETE /photos/:id // DELETE /photos/:id
resource.Index(func(w http.ResponseWriter, r *http.Request) { resource.Index(func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("user index")) w.Write([]byte("all photos"))
}) })
resource.New(func(w http.ResponseWriter, r *http.Request) { resource.New(func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("create new user")) w.Write([]byte("upload a new pohoto"))
}) })
}) })
r.Group(func(grp *mux.Router) { r.Group(func(grp *mux.Router) {
grp.Use(mwGroup) 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 group 1")) w.Write([]byte("i am route /group"))
}) })
}) })