-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
32 lines (27 loc) · 919 Bytes
/
main.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
package main
import (
"net/http"
"github.com/tonny-zhang/cotton"
)
func main() {
r := cotton.Default()
r.Get("/user/:name", func(ctx *cotton.Context) {
ctx.String(http.StatusOK, "user name = "+ctx.Param("name"))
})
r.Get("/user/:name/:id", func(ctx *cotton.Context) {
ctx.String(http.StatusOK, "user id = "+ctx.Param("id")+" name = "+ctx.Param("name"))
})
r.Get("/user/:name/:id/one", func(ctx *cotton.Context) {
ctx.String(http.StatusOK, "one user id = "+ctx.Param("id")+" name = "+ctx.Param("name"))
})
r.Get("/user/:name/:id/two", func(ctx *cotton.Context) {
ctx.String(http.StatusOK, "two user id = "+ctx.Param("id")+" name = "+ctx.Param("name"))
})
r.Post("/user/:id", func(ctx *cotton.Context) {
ctx.String(http.StatusOK, "hello post "+ctx.Param("id"))
})
r.Get("/info/*file", func(ctx *cotton.Context) {
ctx.String(http.StatusOK, "info file = "+ctx.Param("file"))
})
r.Run("")
}