route := odserver.Default(
route.Get("/user",SayHello)
支持链式
route.Get("/user",SayHello).Get("/user1",SayHello)
route.Start("/new").Get("/1", SayHello).Get("/2", SayHello)
route.Target("/user").AddGet(SayHello).AddPost(SayHello2)
对路径/user
同时注册了Get和Post两种请求方式
route.Start("/cookie").
Target("/read").GoGet(ReadCookieServer).GoPost(ReadCookieServer).And().
Target("/write").GoGet(WriteCookieServer)
等价于
route.Target("/cookie/read").GoGet(ReadCookieServer)
route.Target("/cookie/read").GoGet(ReadCookieServer)
route.Target("/cookie/write").GoPost(WriteCookieServer)
/query?name=ljz&age=100
func GetQuery(c *odserver.Context) {
//c.GoReq().ParseForm()
getQuery := ""
for k, v := range c.GoReq().URL.Query() {
getQuery = getQuery + k + ":" + strings.Join(v, "") + " "
}
c.GoResW().Write([]byte(getQuery))
}
route.Target("/params/{id}/{name}").Get(GetParams)
当以/params/110/ljz访问时
func GetParams(c *odserver.Context) {
fmt.Println(c.Params) // ["110", "ljz"]
fmt.Println(c.GetParams) // map[id: "110", name: "ljz"]
}
// 可获取formData和application/json形式的数据提交
c.PostParams()