Compare commits
3 Commits
c10586ad10
...
v0.0.16
| Author | SHA1 | Date | |
|---|---|---|---|
| 09fe61defd | |||
| 7d2303e5e6 | |||
| 38f5d74f4a |
@@ -179,19 +179,23 @@ func insertHook(ctx context.Context, in *gdb.HookInsertInput) (result sql.Result
|
|||||||
in.Data[i]["id"] = node.Generate().Int64()
|
in.Data[i]["id"] = node.Generate().Int64()
|
||||||
}
|
}
|
||||||
if _, ok := in.Data[i]["tenant_id"]; ok {
|
if _, ok := in.Data[i]["tenant_id"]; ok {
|
||||||
|
if g.IsEmpty(in.Data[i]["tenant_id"]) {
|
||||||
if !g.IsEmpty(userInfo.TenantId) {
|
if !g.IsEmpty(userInfo.TenantId) {
|
||||||
in.Data[i]["tenant_id"] = userInfo.TenantId
|
in.Data[i]["tenant_id"] = userInfo.TenantId
|
||||||
} else {
|
} else {
|
||||||
return nil, fmt.Errorf("tenantId cannot be empty")
|
return nil, fmt.Errorf("tenantId cannot be empty")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if _, ok := in.Data[i]["creator"]; ok {
|
if _, ok := in.Data[i]["creator"]; ok {
|
||||||
|
if g.IsEmpty(in.Data[i]["tenant_id"]) {
|
||||||
if !g.IsEmpty(userInfo.UserName) {
|
if !g.IsEmpty(userInfo.UserName) {
|
||||||
in.Data[i]["creator"] = userInfo.UserName
|
in.Data[i]["creator"] = userInfo.UserName
|
||||||
} else {
|
} else {
|
||||||
return nil, fmt.Errorf("user info cannot be empty")
|
return nil, fmt.Errorf("user info cannot be empty")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if _, ok := in.Data[i]["updater"]; ok {
|
if _, ok := in.Data[i]["updater"]; ok {
|
||||||
if !g.IsEmpty(userInfo.UserName) {
|
if !g.IsEmpty(userInfo.UserName) {
|
||||||
in.Data[i]["updater"] = userInfo.UserName
|
in.Data[i]["updater"] = userInfo.UserName
|
||||||
|
|||||||
45
http/http.go
45
http/http.go
@@ -2,7 +2,6 @@ package http
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"reflect"
|
"reflect"
|
||||||
@@ -130,28 +129,28 @@ func doRequest(ctx context.Context, method string, url string, headers map[strin
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer response.Close()
|
defer response.Close()
|
||||||
result := response.ReadAll()
|
//result := response.ReadAll()
|
||||||
|
//
|
||||||
// 统一处理内部API响应格式:{code:200,message:"",data:{...}}
|
//// 统一处理内部API响应格式:{code:200,message:"",data:{...}}
|
||||||
resultStrut := &ghttp.DefaultHandlerResponse{}
|
//resultStrut := &ghttp.DefaultHandlerResponse{}
|
||||||
|
//
|
||||||
if err = gconv.Struct(result, &resultStrut); err != nil { // 修复:增加err检查
|
//if err = gconv.Struct(result, &resultStrut); err != nil { // 修复:增加err检查
|
||||||
return errors.New("响应解析失败: " + err.Error())
|
// return errors.New("响应解析失败: " + err.Error())
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
// 添加调试日志:打印解析后的结构
|
//// 添加调试日志:打印解析后的结构
|
||||||
g.Log().Debugf(ctx, "[HTTP] 解析后结构: Code=%d, Message=%s, Data类型=%T, Data值=%+v",
|
//g.Log().Debugf(ctx, "[HTTP] 解析后结构: Code=%d, Message=%s, Data类型=%T, Data值=%+v",
|
||||||
resultStrut.Code, resultStrut.Message, resultStrut.Data, resultStrut.Data)
|
// resultStrut.Code, resultStrut.Message, resultStrut.Data, resultStrut.Data)
|
||||||
|
//
|
||||||
if resultStrut.Code == 200 || resultStrut.Code == 0 {
|
//if resultStrut.Code == 200 || resultStrut.Code == 0 {
|
||||||
if err = gconv.Struct(resultStrut.Data, target); err != nil { // 修复:增加err检查
|
// if err = gconv.Struct(resultStrut.Data, target); err != nil { // 修复:增加err检查
|
||||||
return errors.New("数据解析失败: " + err.Error())
|
// return errors.New("数据解析失败: " + err.Error())
|
||||||
}
|
// }
|
||||||
// 添加调试日志:打印最终的target
|
// // 添加调试日志:打印最终的target
|
||||||
g.Log().Debugf(ctx, "[HTTP] 最终target: %+v", target)
|
// g.Log().Debugf(ctx, "[HTTP] 最终target: %+v", target)
|
||||||
} else {
|
//} else {
|
||||||
err = errors.New(resultStrut.Message)
|
// err = errors.New(resultStrut.Message)
|
||||||
}
|
//}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
func Get(ctx context.Context, url string, headers map[string]string, target any, data ...any) (err error) {
|
func Get(ctx context.Context, url string, headers map[string]string, target any, data ...any) (err error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user