ghttp优化

This commit is contained in:
john
2018-07-31 14:28:41 +08:00
parent da6093a900
commit 6acd228fde
3 changed files with 17 additions and 2 deletions

View File

@ -20,8 +20,13 @@ func (r *Request) initPost() {
}
}
// 设置GET参数仅在ghttp.Server内有效**注意并发安全性**
func (r *Request) SetPost(k string, v string) {
r.PostForm[k] = []string{v}
}
// 获得post参数
func (r *Request) GetPost(k string) []string {
func (r *Request) GetPost(k string) string {
r.initPost()
if v, ok := r.PostForm[k]; ok {
return v

View File

@ -23,6 +23,16 @@ func (r *Request) initGet() {
}
}
// 设置GET参数仅在ghttp.Server内有效**注意并发安全性**
func (r *Request) SetQuery(k string, v string) {
r.queryVars[k] = []string{v}
}
// 添加GET参数构成[]string
func (r *Request) AddQuery(k string, v string) {
r.queryVars[k] = append(r.queryVars[k], v)
}
// 获得指定名称的get参数列表
func (r *Request) GetQuery(k string) []string {
r.initGet()

View File

@ -12,7 +12,7 @@ func main() {
// 多事件回调示例事件1
pattern1 := "/:name/info/{uid}"
s.BindHookHandlerByMap(pattern1, map[string]ghttp.HandlerFunc {
"BeforeServe" : func(r *ghttp.Request){
"BeforeServe" : func(r *ghttp.Request) {
fmt.Println("打印到Server端终端")
},
})