Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e47dd99816 | ||
|
|
272943d238 | ||
|
|
172c1cc506 | ||
|
|
915e1f65ec | ||
|
|
c512327358 | ||
|
|
c091ed4984 | ||
|
|
dc4dd5dc62 | ||
|
|
7e51069595 | ||
|
|
791c9905df | ||
|
|
6097209c48 | ||
|
|
1835faddc0 | ||
|
|
0ddc2f17b9 |
@@ -0,0 +1 @@
|
|||||||
|
.git
|
||||||
+26
-13
@@ -7,10 +7,11 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"gitea.com/red-future/common/beans"
|
"gitea.redpowerfuture.com/red-future/common/beans"
|
||||||
"gitea.com/red-future/common/utils"
|
"gitea.redpowerfuture.com/red-future/common/utils"
|
||||||
"github.com/bwmarrin/snowflake"
|
"github.com/bwmarrin/snowflake"
|
||||||
"github.com/gogf/gf/v2/crypto/gmd5"
|
"github.com/gogf/gf/v2/crypto/gmd5"
|
||||||
"github.com/gogf/gf/v2/database/gdb"
|
"github.com/gogf/gf/v2/database/gdb"
|
||||||
@@ -29,8 +30,28 @@ import (
|
|||||||
var (
|
var (
|
||||||
localCache *gcache.Cache
|
localCache *gcache.Cache
|
||||||
snowflakeNode *snowflake.Node
|
snowflakeNode *snowflake.Node
|
||||||
|
snowflakeOnce sync.Once
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
ctx := context.Background()
|
||||||
|
snowflakeOnce.Do(func() {
|
||||||
|
nodeId := genv.Get("APP_NODE", 1).Int64()
|
||||||
|
// 安全范围 0~1023
|
||||||
|
if nodeId < 0 || nodeId > 1023 {
|
||||||
|
nodeId = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
node, err := snowflake.NewNode(nodeId)
|
||||||
|
if err != nil {
|
||||||
|
g.Log().Errorf(ctx, "snowflake init failed: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
snowflakeNode = node
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// getLocalCache 获取本地缓存实例
|
// getLocalCache 获取本地缓存实例
|
||||||
func getLocalCache() *gcache.Cache {
|
func getLocalCache() *gcache.Cache {
|
||||||
if localCache == nil {
|
if localCache == nil {
|
||||||
@@ -166,17 +187,8 @@ func insertHook(ctx context.Context, in *gdb.HookInsertInput) (result sql.Result
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 懒加载初始化全局snowflake节点,只创建一次
|
if g.IsEmpty(snowflakeNode) {
|
||||||
if snowflakeNode == nil {
|
return nil, fmt.Errorf("snowflakeNode is nil")
|
||||||
nodeId := genv.Get("APP_NODE", "").Int64()
|
|
||||||
if g.IsEmpty(nodeId) {
|
|
||||||
nodeId = 1
|
|
||||||
}
|
|
||||||
node, err := snowflake.NewNode(nodeId)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
snowflakeNode = node
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := range in.Data {
|
for i := range in.Data {
|
||||||
@@ -427,6 +439,7 @@ var (
|
|||||||
|
|
||||||
type Gfdb interface {
|
type Gfdb interface {
|
||||||
GetAll(ctx context.Context, sql string, args ...any) (gdb.Result, error)
|
GetAll(ctx context.Context, sql string, args ...any) (gdb.Result, error)
|
||||||
|
GetOne(ctx context.Context, sql string, args ...any) (gdb.Record, error)
|
||||||
Exec(ctx context.Context, sql string, args ...any) (sql.Result, error)
|
Exec(ctx context.Context, sql string, args ...any) (sql.Result, error)
|
||||||
Model(ctx context.Context, tableNameOrStruct ...any) *model
|
Model(ctx context.Context, tableNameOrStruct ...any) *model
|
||||||
Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) error
|
Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) error
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"gitea.com/red-future/common/log/consts"
|
"gitea.redpowerfuture.com/red-future/common/log/consts"
|
||||||
|
|
||||||
"github.com/gogf/gf/v2/frame/g"
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
"github.com/gogf/gf/v2/os/glog"
|
"github.com/gogf/gf/v2/os/glog"
|
||||||
|
|||||||
+4
-4
@@ -11,12 +11,12 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"gitea.com/red-future/common/log/consts"
|
"gitea.redpowerfuture.com/red-future/common/log/consts"
|
||||||
"go.mongodb.org/mongo-driver/v2/event"
|
"go.mongodb.org/mongo-driver/v2/event"
|
||||||
|
|
||||||
"gitea.com/red-future/common/beans"
|
"gitea.redpowerfuture.com/red-future/common/beans"
|
||||||
"gitea.com/red-future/common/log/model/entity"
|
"gitea.redpowerfuture.com/red-future/common/log/model/entity"
|
||||||
"gitea.com/red-future/common/utils"
|
"gitea.redpowerfuture.com/red-future/common/utils"
|
||||||
"github.com/gogf/gf/v2/container/gvar"
|
"github.com/gogf/gf/v2/container/gvar"
|
||||||
"github.com/gogf/gf/v2/errors/gerror"
|
"github.com/gogf/gf/v2/errors/gerror"
|
||||||
"github.com/gogf/gf/v2/frame/g"
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"gitea.com/red-future/common/beans"
|
"gitea.redpowerfuture.com/red-future/common/beans"
|
||||||
"gitea.com/red-future/common/utils"
|
"gitea.redpowerfuture.com/red-future/common/utils"
|
||||||
"github.com/gogf/gf/v2/container/gvar"
|
"github.com/gogf/gf/v2/container/gvar"
|
||||||
"github.com/gogf/gf/v2/errors/gerror"
|
"github.com/gogf/gf/v2/errors/gerror"
|
||||||
"github.com/gogf/gf/v2/frame/g"
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
module gitea.com/red-future/common
|
module gitea.redpowerfuture.com/red-future/common
|
||||||
|
|
||||||
go 1.26.0
|
go 1.26.0
|
||||||
|
|
||||||
|
|||||||
+67
-21
@@ -4,14 +4,15 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"reflect"
|
"reflect"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
_ "gitea.com/red-future/common/consul"
|
_ "gitea.redpowerfuture.com/red-future/common/consul"
|
||||||
"gitea.com/red-future/common/jaeger"
|
"gitea.redpowerfuture.com/red-future/common/jaeger"
|
||||||
"gitea.com/red-future/common/utils"
|
"gitea.redpowerfuture.com/red-future/common/utils"
|
||||||
"github.com/gogf/gf/v2/frame/g"
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
"github.com/gogf/gf/v2/net/gclient"
|
"github.com/gogf/gf/v2/net/gclient"
|
||||||
"github.com/gogf/gf/v2/net/ghttp"
|
"github.com/gogf/gf/v2/net/ghttp"
|
||||||
@@ -69,10 +70,10 @@ func SkipMiddleware(h func(r *ghttp.Request), path string) (handler ghttp.Handle
|
|||||||
}
|
}
|
||||||
|
|
||||||
func RouteRegister(controllers []interface{}) {
|
func RouteRegister(controllers []interface{}) {
|
||||||
//Httpserver.Group("/log", func(group *ghttp.RouterGroup) {
|
Httpserver.Group("/log", func(group *ghttp.RouterGroup) {
|
||||||
// group.Middleware(jaeger.NewTracer)
|
group.Middleware(jaeger.NewTracer)
|
||||||
// group.Bind(controller.OperationLog)
|
//group.Bind(controller.OperationLog)
|
||||||
//})
|
})
|
||||||
re := regexp.MustCompile("[A-Z]")
|
re := regexp.MustCompile("[A-Z]")
|
||||||
for _, t := range controllers {
|
for _, t := range controllers {
|
||||||
sName := reflect.ValueOf(t).Elem().Type().Name()
|
sName := reflect.ValueOf(t).Elem().Type().Name()
|
||||||
@@ -80,19 +81,15 @@ func RouteRegister(controllers []interface{}) {
|
|||||||
return fmt.Sprintf("/%s", strings.ToLower(s))
|
return fmt.Sprintf("/%s", strings.ToLower(s))
|
||||||
})
|
})
|
||||||
Httpserver.Group(convertedStr, func(group *ghttp.RouterGroup) {
|
Httpserver.Group(convertedStr, func(group *ghttp.RouterGroup) {
|
||||||
group.Middleware(jaeger.NewTracer)
|
|
||||||
group.Bind(t)
|
group.Bind(t)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
go Httpserver.Run()
|
go Httpserver.Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
// doRequest 统一HTTP请求处理(DELETE用ContentJson发送body,gconv.Struct增加err检查)
|
// doRequestRaw 执行HTTP请求,返回gclient.Response,调用方需自行Close
|
||||||
func doRequest(ctx context.Context, method string, url string, headers map[string]string, target any, data ...any) (err error) {
|
// 统一处理:client克隆、ContentJson设置、请求头注入、GET查询参数转换
|
||||||
err = utils.ValidStructPtr(target)
|
func doRequestRaw(ctx context.Context, method string, url string, headers map[string]string, data ...any) (*gclient.Response, error) {
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
client := Httpclient.Clone()
|
client := Httpclient.Clone()
|
||||||
|
|
||||||
// POST/PUT/DELETE请求都需要显式用ContentJson序列化body
|
// POST/PUT/DELETE请求都需要显式用ContentJson序列化body
|
||||||
@@ -110,9 +107,9 @@ func doRequest(ctx context.Context, method string, url string, headers map[strin
|
|||||||
// 修复:避免data...展开导致的双重包装问题
|
// 修复:避免data...展开导致的双重包装问题
|
||||||
// 当只有一个元素时,直接传递该元素,避免被包装成数组
|
// 当只有一个元素时,直接传递该元素,避免被包装成数组
|
||||||
var response *gclient.Response
|
var response *gclient.Response
|
||||||
|
var err error
|
||||||
// 对于GET请求,将参数转换为map
|
// 对于GET请求,将参数转换为map
|
||||||
if method == http.MethodGet && len(data) > 0 && len(data)%2 == 0 {
|
if method == http.MethodGet && len(data) > 0 && len(data)%2 == 0 {
|
||||||
// 构建query参数map
|
|
||||||
queryParams := make(map[string]string)
|
queryParams := make(map[string]string)
|
||||||
for i := 0; i < len(data); i += 2 {
|
for i := 0; i < len(data); i += 2 {
|
||||||
if key, ok := data[i].(string); ok && i+1 < len(data) {
|
if key, ok := data[i].(string); ok && i+1 < len(data) {
|
||||||
@@ -126,17 +123,33 @@ func doRequest(ctx context.Context, method string, url string, headers map[strin
|
|||||||
} else {
|
} else {
|
||||||
response, err = client.DoRequest(ctx, method, url, data...)
|
response, err = client.DoRequest(ctx, method, url, data...)
|
||||||
}
|
}
|
||||||
|
return response, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// doRequest 统一HTTP请求处理(同步/异步,解析内部API响应格式并填充target)
|
||||||
|
func doRequest(ctx context.Context, method string, url string, headers map[string]string, target any, respParse bool, data ...any) (res []byte, err error) {
|
||||||
|
if target != nil || respParse {
|
||||||
|
err = utils.ValidStructPtr(target)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
response, err := doRequestRaw(ctx, method, url, headers, data...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer response.Close()
|
defer response.Close()
|
||||||
result := response.ReadAll()
|
result := response.ReadAll()
|
||||||
|
|
||||||
|
if !respParse {
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
// 统一处理内部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 nil, errors.New("响应解析失败: " + err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
// 添加调试日志:打印解析后的结构
|
// 添加调试日志:打印解析后的结构
|
||||||
@@ -145,7 +158,7 @@ func doRequest(ctx context.Context, method string, url string, headers map[strin
|
|||||||
|
|
||||||
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 nil, errors.New("数据解析失败: " + err.Error())
|
||||||
}
|
}
|
||||||
// 添加调试日志:打印最终的target
|
// 添加调试日志:打印最终的target
|
||||||
g.Log().Debugf(ctx, "[HTTP] 最终target: %+v", target)
|
g.Log().Debugf(ctx, "[HTTP] 最终target: %+v", target)
|
||||||
@@ -154,19 +167,52 @@ func doRequest(ctx context.Context, method string, url string, headers map[strin
|
|||||||
}
|
}
|
||||||
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) {
|
||||||
err = doRequest(ctx, http.MethodGet, url, headers, target, data...)
|
_, err = doRequest(ctx, http.MethodGet, url, headers, target, true, data...)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
func Post(ctx context.Context, url string, headers map[string]string, target any, data ...any) (err error) {
|
func Post(ctx context.Context, url string, headers map[string]string, target any, data ...any) (err error) {
|
||||||
err = doRequest(ctx, http.MethodPost, url, headers, target, data...)
|
_, err = doRequest(ctx, http.MethodPost, url, headers, target, true, data...)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
func Put(ctx context.Context, url string, headers map[string]string, target any, data ...any) (err error) {
|
func Put(ctx context.Context, url string, headers map[string]string, target any, data ...any) (err error) {
|
||||||
err = doRequest(ctx, http.MethodPut, url, headers, target, data...)
|
_, err = doRequest(ctx, http.MethodPut, url, headers, target, true, data...)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
func Delete(ctx context.Context, url string, headers map[string]string, target any, data ...any) (err error) {
|
func Delete(ctx context.Context, url string, headers map[string]string, target any, data ...any) (err error) {
|
||||||
err = doRequest(ctx, http.MethodDelete, url, headers, target, data...)
|
_, err = doRequest(ctx, http.MethodDelete, url, headers, target, true, data...)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetNotParse(ctx context.Context, url string, headers map[string]string, data ...any) (res []byte, err error) {
|
||||||
|
res, err = doRequest(ctx, http.MethodGet, url, headers, nil, false, data...)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
func PostNotParse(ctx context.Context, url string, headers map[string]string, data ...any) (res []byte, err error) {
|
||||||
|
res, err = doRequest(ctx, http.MethodPost, url, headers, nil, false, data...)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// DoStream 流式HTTP请求,返回响应体io.ReadCloser,由调用方自行控制读取和关闭
|
||||||
|
// 注意:返回的是原始响应流,不会解析内部API响应格式,调用方必须在使用后Close
|
||||||
|
func doStream(ctx context.Context, method string, url string, headers map[string]string, data ...any) (io.ReadCloser, error) {
|
||||||
|
response, err := doRequestRaw(ctx, method, url, headers, data...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查HTTP状态码,提前返回错误
|
||||||
|
if response.StatusCode < 200 || response.StatusCode >= 300 {
|
||||||
|
bodyBytes, _ := io.ReadAll(response.Body)
|
||||||
|
response.Close()
|
||||||
|
return nil, fmt.Errorf("[HTTP][Stream] 状态码异常: %d, body=%s", response.StatusCode, string(bodyBytes))
|
||||||
|
}
|
||||||
|
|
||||||
|
return response.Body, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// PostStream POST流式请求,返回响应体io.ReadCloser
|
||||||
|
func PostStream(ctx context.Context, url string, headers map[string]string, data ...any) (io.ReadCloser, error) {
|
||||||
|
return doStream(ctx, http.MethodPost, url, headers, data...)
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ package controller
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"gitea.com/red-future/common/log/model/dto"
|
"gitea.redpowerfuture.com/red-future/common/log/model/dto"
|
||||||
"gitea.com/red-future/common/log/service"
|
"gitea.redpowerfuture.com/red-future/common/log/service"
|
||||||
)
|
)
|
||||||
|
|
||||||
type operationLog struct{}
|
type operationLog struct{}
|
||||||
|
|||||||
+5
-5
@@ -3,15 +3,15 @@ package dao
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"gitea.com/red-future/common/beans"
|
"gitea.redpowerfuture.com/red-future/common/beans"
|
||||||
"gitea.com/red-future/common/db/mongo"
|
"gitea.redpowerfuture.com/red-future/common/db/mongo"
|
||||||
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"gitea.com/red-future/common/log/consts"
|
"gitea.redpowerfuture.com/red-future/common/log/consts"
|
||||||
"gitea.com/red-future/common/log/model/dto"
|
"gitea.redpowerfuture.com/red-future/common/log/model/dto"
|
||||||
"gitea.com/red-future/common/log/model/entity"
|
"gitea.redpowerfuture.com/red-future/common/log/model/entity"
|
||||||
"go.mongodb.org/mongo-driver/v2/bson"
|
"go.mongodb.org/mongo-driver/v2/bson"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package dto
|
package dto
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"gitea.com/red-future/common/beans"
|
"gitea.redpowerfuture.com/red-future/common/beans"
|
||||||
"github.com/gogf/gf/v2/frame/g"
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
"github.com/gogf/gf/v2/os/gtime"
|
"github.com/gogf/gf/v2/os/gtime"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package entity
|
package entity
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"gitea.com/red-future/common/beans"
|
"gitea.redpowerfuture.com/red-future/common/beans"
|
||||||
)
|
)
|
||||||
|
|
||||||
// OperationLog 操作日志实体 - 用于记录数据增删改操作行为
|
// OperationLog 操作日志实体 - 用于记录数据增删改操作行为
|
||||||
|
|||||||
@@ -2,11 +2,11 @@ package service
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"gitea.com/red-future/common/beans"
|
"gitea.redpowerfuture.com/red-future/common/beans"
|
||||||
"gitea.com/red-future/common/log/dao"
|
"gitea.redpowerfuture.com/red-future/common/log/dao"
|
||||||
"gitea.com/red-future/common/log/model/dto"
|
"gitea.redpowerfuture.com/red-future/common/log/model/dto"
|
||||||
logEntity "gitea.com/red-future/common/log/model/entity"
|
logEntity "gitea.redpowerfuture.com/red-future/common/log/model/entity"
|
||||||
"gitea.com/red-future/common/utils"
|
"gitea.redpowerfuture.com/red-future/common/utils"
|
||||||
"github.com/gogf/gf/v2/util/gconv"
|
"github.com/gogf/gf/v2/util/gconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import (
|
|||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"gitea.com/red-future/common/utils"
|
"gitea.redpowerfuture.com/red-future/common/utils"
|
||||||
"github.com/alibaba/sentinel-golang/api"
|
"github.com/alibaba/sentinel-golang/api"
|
||||||
"github.com/alibaba/sentinel-golang/core/circuitbreaker"
|
"github.com/alibaba/sentinel-golang/core/circuitbreaker"
|
||||||
"github.com/gogf/gf/v2/frame/g"
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"gitea.com/red-future/common/beans"
|
"gitea.redpowerfuture.com/red-future/common/beans"
|
||||||
commonHttp "gitea.com/red-future/common/http"
|
commonHttp "gitea.redpowerfuture.com/red-future/common/http"
|
||||||
"gitea.com/red-future/common/utils"
|
"gitea.redpowerfuture.com/red-future/common/utils"
|
||||||
"github.com/gogf/gf/v2/database/gredis"
|
"github.com/gogf/gf/v2/database/gredis"
|
||||||
"github.com/gogf/gf/v2/frame/g"
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
"github.com/gogf/gf/v2/net/ghttp"
|
"github.com/gogf/gf/v2/net/ghttp"
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"gitea.com/red-future/common/utils"
|
"gitea.redpowerfuture.com/red-future/common/utils"
|
||||||
"github.com/gogf/gf/v2/frame/g"
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
"github.com/gogf/gf/v2/net/ghttp"
|
"github.com/gogf/gf/v2/net/ghttp"
|
||||||
"github.com/gogf/gf/v2/util/gconv"
|
"github.com/gogf/gf/v2/util/gconv"
|
||||||
|
|||||||
+2
-2
@@ -2,8 +2,8 @@ package swagger
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"gitea.com/red-future/common/consul"
|
"gitea.redpowerfuture.com/red-future/common/consul"
|
||||||
"gitea.com/red-future/common/http"
|
"gitea.redpowerfuture.com/red-future/common/http"
|
||||||
"github.com/gogf/gf/v2/frame/g"
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
"github.com/gogf/gf/v2/net/ghttp"
|
"github.com/gogf/gf/v2/net/ghttp"
|
||||||
"github.com/gogf/gf/v2/util/gconv"
|
"github.com/gogf/gf/v2/util/gconv"
|
||||||
|
|||||||
+3
-2
@@ -13,7 +13,7 @@ import (
|
|||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"gitea.com/red-future/common/beans"
|
"gitea.redpowerfuture.com/red-future/common/beans"
|
||||||
"github.com/gogf/gf/v2/container/gvar"
|
"github.com/gogf/gf/v2/container/gvar"
|
||||||
"github.com/gogf/gf/v2/database/gredis"
|
"github.com/gogf/gf/v2/database/gredis"
|
||||||
"github.com/gogf/gf/v2/errors/gcode"
|
"github.com/gogf/gf/v2/errors/gcode"
|
||||||
@@ -583,7 +583,8 @@ func GetLocalBaseURL(ctx context.Context) string {
|
|||||||
|
|
||||||
// GetCallbackURL 获取回调地址(完整 URL)
|
// GetCallbackURL 获取回调地址(完整 URL)
|
||||||
func GetCallbackURL(ctx context.Context, path string) string {
|
func GetCallbackURL(ctx context.Context, path string) string {
|
||||||
baseURL := GetLocalBaseURL(ctx)
|
//baseURL := GetLocalBaseURL(ctx)
|
||||||
|
baseURL := "http://" + GetLocalAddress(ctx)
|
||||||
// 确保 path 以 / 开头
|
// 确保 path 以 / 开头
|
||||||
if !strings.HasPrefix(path, "/") {
|
if !strings.HasPrefix(path, "/") {
|
||||||
path = "/" + path
|
path = "/" + path
|
||||||
|
|||||||
Reference in New Issue
Block a user