调整request的方法,增加类型转换的方法
This commit is contained in:
@@ -77,20 +77,26 @@ now := tools.Now()
|
||||
str := tools.FormatDateTime(now)
|
||||
```
|
||||
|
||||
#### HTTP响应(Handler黑盒模式)
|
||||
#### HTTP响应(Factory黑盒模式,推荐)
|
||||
|
||||
```go
|
||||
import (
|
||||
"net/http"
|
||||
commonhttp "git.toowon.com/jimmy/go-common/http"
|
||||
"git.toowon.com/jimmy/go-common/factory"
|
||||
"git.toowon.com/jimmy/go-common/tools"
|
||||
)
|
||||
|
||||
func GetUser(h *commonhttp.Handler) {
|
||||
id := h.GetQueryInt64("id", 0)
|
||||
h.Success(data)
|
||||
func GetUser(w http.ResponseWriter, r *http.Request) {
|
||||
fac, _ := factory.NewFactoryFromFile("config.json")
|
||||
|
||||
// 获取查询参数(使用类型转换方法)
|
||||
id := tools.ConvertInt64(r.URL.Query().Get("id"), 0)
|
||||
|
||||
// 返回成功响应
|
||||
fac.Success(w, data)
|
||||
}
|
||||
|
||||
http.HandleFunc("/user", commonhttp.HandleFunc(GetUser))
|
||||
http.HandleFunc("/user", GetUser)
|
||||
```
|
||||
|
||||
#### 中间件(生产级配置)
|
||||
|
||||
Reference in New Issue
Block a user