refactor(utils): 替换日志库实现
- 导入自定义日志包 git.magicany.cc/black1552/gf-common/log - 将 g.Log().Infof 替换为 log.Info 方法调用 - 将 g.Log().Errorf 替换为 log.Error 方法调用 - 统一所有 HTTP 请求方法的日志记录方式 - 移除上下文参数 ctx 在日志记录中的传递main
parent
95623f3802
commit
8add85cea7
21
utils/sql.go
21
utils/sql.go
|
|
@ -3,6 +3,7 @@ package utils
|
|||
import (
|
||||
"context"
|
||||
|
||||
"git.magicany.cc/black1552/gf-common/log"
|
||||
_ "github.com/gogf/gf/contrib/drivers/mysql/v2"
|
||||
"github.com/gogf/gf/v2/crypto/gmd5"
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
|
|
@ -51,51 +52,51 @@ func NewClient[R any](request any, url string, header map[string]string) *SClien
|
|||
return s
|
||||
}
|
||||
func (w *SClient[R]) Post(ctx context.Context) (res *R, err error) {
|
||||
g.Log().Infof(ctx, "请求Url:%s,请求头:%v,请求方法:%s,请求内容:%s", w.url, w.header, "post", w.request)
|
||||
log.Info("请求Url:%s,请求头:%v,请求方法:%s,请求内容:%s", w.url, w.header, "post", w.request)
|
||||
resp := w.client.PostVar(ctx, w.url, w.request)
|
||||
err = gconv.Struct(resp, &res)
|
||||
if err != nil {
|
||||
g.Log().Errorf(ctx, "解析响应体异常:%s", err)
|
||||
log.Error("请求异常:", err)
|
||||
return nil, err
|
||||
}
|
||||
return
|
||||
}
|
||||
func (w *SClient[R]) Get(ctx context.Context) (res *R, err error) {
|
||||
g.Log().Infof(ctx, "请求Url:%s,请求头:%v,请求方法:%s,请求内容:%s", w.url, w.header, "get", w.request)
|
||||
log.Info("请求Url:%s,请求头:%v,请求方法:%s,请求内容:%s", w.url, w.header, "get", w.request)
|
||||
resp := w.client.GetVar(ctx, w.url, w.request)
|
||||
err = gconv.Struct(resp, &res)
|
||||
if err != nil {
|
||||
g.Log().Errorf(ctx, "解析响应体异常:%s", err)
|
||||
log.Error("解析响应体异常:", err)
|
||||
return nil, err
|
||||
}
|
||||
return
|
||||
}
|
||||
func (w *SClient[R]) Put(ctx context.Context) (res *R, err error) {
|
||||
g.Log().Infof(ctx, "请求Url:%s,请求头:%v,请求方法:%s,请求内容:%s", w.url, w.header, "put", w.request)
|
||||
log.Info("请求Url:%s,请求头:%v,请求方法:%s,请求内容:%s", w.url, w.header, "put", w.request)
|
||||
resp := w.client.PutVar(ctx, w.url, w.request)
|
||||
err = gconv.Struct(resp, &res)
|
||||
if err != nil {
|
||||
g.Log().Errorf(ctx, "解析响应体异常:%s", err)
|
||||
log.Error("解析响应体异常:", err)
|
||||
return nil, err
|
||||
}
|
||||
return
|
||||
}
|
||||
func (w *SClient[R]) Delete(ctx context.Context) (res *R, err error) {
|
||||
g.Log().Infof(ctx, "请求Url:%s,请求头:%v,请求方法:%s,请求内容:%s", w.url, w.header, "delete", w.request)
|
||||
log.Info("请求Url:%s,请求头:%v,请求方法:%s,请求内容:%s", w.url, w.header, "delete", w.request)
|
||||
resp := w.client.DeleteVar(ctx, w.url, w.request)
|
||||
err = gconv.Struct(resp, &res)
|
||||
if err != nil {
|
||||
g.Log().Errorf(ctx, "解析响应体异常:%s", err)
|
||||
log.Error("解析响应体异常:", err)
|
||||
return nil, err
|
||||
}
|
||||
return
|
||||
}
|
||||
func (w *SClient[R]) Patch(ctx context.Context) (res *R, err error) {
|
||||
g.Log().Infof(ctx, "请求Url:%s,请求头:%v,请求方法:%s,请求内容:%s", w.url, w.header, "patch", w.request)
|
||||
log.Info("请求Url:%s,请求头:%v,请求方法:%s,请求内容:%s", w.url, w.header, "patch", w.request)
|
||||
resp := w.client.PatchVar(ctx, w.url, w.request)
|
||||
err = gconv.Struct(resp, &res)
|
||||
if err != nil {
|
||||
g.Log().Errorf(ctx, "解析响应体异常:%s", err)
|
||||
log.Error("解析响应体异常:", err)
|
||||
return nil, err
|
||||
}
|
||||
return
|
||||
|
|
|
|||
Loading…
Reference in New Issue