mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-04 00:10:25 +08:00
fix: 主键字段获取调整&其他小优化
This commit is contained in:
@@ -15,7 +15,7 @@ require (
|
||||
github.com/sirupsen/logrus v1.9.0
|
||||
github.com/xwb1989/sqlparser v0.0.0-20180606152119-120387863bf2
|
||||
go.mongodb.org/mongo-driver v1.9.1 // mongo
|
||||
golang.org/x/crypto v0.1.0 // ssh
|
||||
golang.org/x/crypto v0.2.0 // ssh
|
||||
gopkg.in/yaml.v3 v3.0.1
|
||||
// gorm
|
||||
gorm.io/driver/mysql v1.4.1
|
||||
@@ -50,9 +50,9 @@ require (
|
||||
github.com/xdg-go/stringprep v1.0.2 // indirect
|
||||
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
|
||||
golang.org/x/image v0.0.0-20220302094943-723b81ca9867 // indirect
|
||||
golang.org/x/net v0.1.0 // indirect
|
||||
golang.org/x/net v0.2.0 // indirect
|
||||
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9 // indirect
|
||||
golang.org/x/sys v0.1.0 // indirect
|
||||
golang.org/x/sys v0.2.0 // indirect
|
||||
golang.org/x/text v0.4.0 // indirect
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
|
||||
google.golang.org/protobuf v1.28.0 // indirect
|
||||
|
||||
@@ -297,6 +297,7 @@ func (r *Redis) SetStringValue(rc *ctx.ReqCtx) {
|
||||
g := rc.GinCtx
|
||||
keyValue := new(form.StringValue)
|
||||
ginx.BindJsonAndValid(g, keyValue)
|
||||
rc.ReqParam = keyValue
|
||||
|
||||
ri := r.RedisApp.GetRedisInstance(uint64(ginx.PathParamInt(g, "id")), ginx.PathParamInt(g, "db"))
|
||||
biz.ErrIsNilAppendErr(r.TagApp.CanAccess(rc.LoginAccount.Id, ri.TagPath), "%s")
|
||||
|
||||
@@ -50,7 +50,7 @@ func InitRedisRouter(router *gin.RouterGroup) {
|
||||
})
|
||||
|
||||
// 删除key
|
||||
deleteKeyL := ctx.NewLogInfo("redis删除key").WithSave(true)
|
||||
deleteKeyL := ctx.NewLogInfo("redis-删除key").WithSave(true)
|
||||
redis.DELETE(":id/:db/key", func(c *gin.Context) {
|
||||
ctx.NewReqCtxWithGin(c).WithLog(deleteKeyL).Handle(rs.DeleteKey)
|
||||
})
|
||||
@@ -61,8 +61,9 @@ func InitRedisRouter(router *gin.RouterGroup) {
|
||||
})
|
||||
|
||||
// 设置string类型值
|
||||
setStringL := ctx.NewLogInfo("redis-setString").WithSave(true)
|
||||
redis.POST(":id/:db/string-value", func(c *gin.Context) {
|
||||
ctx.NewReqCtxWithGin(c).Handle(rs.SetStringValue)
|
||||
ctx.NewReqCtxWithGin(c).WithLog(setStringL).Handle(rs.SetStringValue)
|
||||
})
|
||||
|
||||
// hscan
|
||||
@@ -74,13 +75,15 @@ func InitRedisRouter(router *gin.RouterGroup) {
|
||||
ctx.NewReqCtxWithGin(c).Handle(rs.Hget)
|
||||
})
|
||||
|
||||
hdelL := ctx.NewLogInfo("redis-hdel").WithSave(true)
|
||||
redis.DELETE(":id/:db/hdel", func(c *gin.Context) {
|
||||
ctx.NewReqCtxWithGin(c).Handle(rs.Hdel)
|
||||
ctx.NewReqCtxWithGin(c).WithLog(hdelL).Handle(rs.Hdel)
|
||||
})
|
||||
|
||||
// 设置hash类型值
|
||||
setHashValueL := ctx.NewLogInfo("redis-setHashValue").WithSave(true)
|
||||
redis.POST(":id/:db/hash-value", func(c *gin.Context) {
|
||||
ctx.NewReqCtxWithGin(c).Handle(rs.SetHashValue)
|
||||
ctx.NewReqCtxWithGin(c).WithLog(setHashValueL).Handle(rs.SetHashValue)
|
||||
})
|
||||
|
||||
// 获取set类型值
|
||||
|
||||
@@ -74,14 +74,12 @@ func LogHandler(rc *ReqCtx) error {
|
||||
func getLogMsg(rc *ReqCtx) string {
|
||||
msg := rc.LogInfo.Description + fmt.Sprintf(" ->%dms", rc.timed)
|
||||
if !utils.IsBlank(reflect.ValueOf(rc.ReqParam)) {
|
||||
rb, _ := json.Marshal(rc.ReqParam)
|
||||
msg = msg + fmt.Sprintf("\n--> %s", string(rb))
|
||||
msg = msg + fmt.Sprintf("\n--> %s", getDesc(rc.ReqParam))
|
||||
}
|
||||
|
||||
// 返回结果不为空,则记录返回结果
|
||||
if rc.LogInfo.LogResp && !utils.IsBlank(reflect.ValueOf(rc.ResData)) {
|
||||
respB, _ := json.Marshal(rc.ResData)
|
||||
msg = msg + fmt.Sprintf("\n<-- %s", string(respB))
|
||||
msg = msg + fmt.Sprintf("\n<-- %s", getDesc(rc.ResData))
|
||||
}
|
||||
return msg
|
||||
}
|
||||
@@ -89,8 +87,7 @@ func getLogMsg(rc *ReqCtx) string {
|
||||
func getErrMsg(rc *ReqCtx, err interface{}) string {
|
||||
msg := rc.LogInfo.Description
|
||||
if !utils.IsBlank(reflect.ValueOf(rc.ReqParam)) {
|
||||
rb, _ := json.Marshal(rc.ReqParam)
|
||||
msg = msg + fmt.Sprintf("\n--> %s", string(rb))
|
||||
msg = msg + fmt.Sprintf("\n--> %s", getDesc(rc.ReqParam))
|
||||
}
|
||||
|
||||
var errMsg string
|
||||
@@ -104,3 +101,13 @@ func getErrMsg(rc *ReqCtx, err interface{}) string {
|
||||
}
|
||||
return (msg + errMsg)
|
||||
}
|
||||
|
||||
// 获取参数的日志描述
|
||||
func getDesc(param any) string {
|
||||
if paramStr, ok := param.(string); ok {
|
||||
return paramStr
|
||||
}
|
||||
|
||||
rb, _ := json.Marshal(param)
|
||||
return string(rb)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user