refactor🎨 优化Context设置方法

This commit is contained in:
wenjianzhang
2021-05-12 18:47:29 +08:00
parent abcdf880fd
commit 70998c424d
6 changed files with 79 additions and 85 deletions
+3 -9
View File
@@ -18,7 +18,8 @@ type Api struct {
Logger *logger.Logger
}
func (e Api) SetContext(c *gin.Context) {
// MakeContext 设置http上下文
func (e *Api) MakeContext(c *gin.Context) {
fmt.Println(&c)
e.Context = c
fmt.Println(&e.Context)
@@ -30,13 +31,6 @@ func (e Api) GetLogger() *logger.Logger {
return api.GetRequestLogger(e.Context)
}
//func (e Api) GetLogger() (*logger.Logger, error) {
// if e.Context == nil {
// return nil, errors.New("API context cannot be nil")
// }
// return api.GetRequestLogger(e.Context), nil
//}
func (e Api) Bind(d interface{}, bindings ...binding.Binding) error {
var err error
for i := range bindings {
@@ -99,4 +93,4 @@ func (e Api) PageOK(result interface{}, count int, pageIndex int, pageSize int,
// Custom 兼容函数
func (e Api) Custom(data gin.H) {
response.Custum(e.Context, data)
}
}