to:sync
This commit is contained in:
parent
b251398c14
commit
427b924909
@ -25,7 +25,7 @@ func InitAiGroup(g *echo.Group) {
|
|||||||
ctx := repository.GetFbc(&c)
|
ctx := repository.GetFbc(&c)
|
||||||
|
|
||||||
//groupId
|
//groupId
|
||||||
key := fbl.ToString(corpId) + "_" + fbl.ToString(bizId) + "_" + fbl.ToString(uid)
|
key := utils.ToString(corpId) + "_" + utils.ToString(bizId) + "_" + utils.ToString(uid)
|
||||||
groupId := utils.GetCache(key)
|
groupId := utils.GetCache(key)
|
||||||
result, err := remote_http.AiApi.Completions(ctx, req.Prompt, groupId)
|
result, err := remote_http.AiApi.Completions(ctx, req.Prompt, groupId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -86,6 +86,6 @@ func initCf() *Conf {
|
|||||||
//根据配置参数更新 consul token
|
//根据配置参数更新 consul token
|
||||||
cf.FbConsul.Token = utils.FillValOfKey("CONSUL_HTTP_TOKEN", cf.FbConsul.Token)
|
cf.FbConsul.Token = utils.FillValOfKey("CONSUL_HTTP_TOKEN", cf.FbConsul.Token)
|
||||||
|
|
||||||
fbl.Log().Sugar().Infof("start in %s", env)
|
//fbl.Log().Sugar().Infof("start in %s", env)
|
||||||
return cf
|
return cf
|
||||||
}
|
}
|
||||||
|
9
common/utils/if.go
Normal file
9
common/utils/if.go
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
func If[T any](condition bool, trueVal, falseVal T) T {
|
||||||
|
if condition {
|
||||||
|
return trueVal
|
||||||
|
}
|
||||||
|
|
||||||
|
return falseVal
|
||||||
|
}
|
26
common/utils/num.go
Normal file
26
common/utils/num.go
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
import "strconv"
|
||||||
|
|
||||||
|
func ToUint64(val string) uint64 {
|
||||||
|
result, err := strconv.ParseUint(val, 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
func ToInt(val string) int {
|
||||||
|
result, err := strconv.Atoi(val)
|
||||||
|
if err != nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsNum(s string) bool {
|
||||||
|
_, err := strconv.ParseFloat(s, 64)
|
||||||
|
return err == nil
|
||||||
|
}
|
@ -32,7 +32,7 @@ func OkPageResult[T any](anchor any, end bool, list []T) Result {
|
|||||||
Code: ok.ToInt(),
|
Code: ok.ToInt(),
|
||||||
Data: PageResult[T]{
|
Data: PageResult[T]{
|
||||||
List: list,
|
List: list,
|
||||||
Anchor: fbl.ToString(anchor),
|
Anchor: utils.ToString(anchor),
|
||||||
End: &end,
|
End: &end,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -42,7 +42,7 @@ func OkEmptyPageResult(anchor any) Result {
|
|||||||
return Result{
|
return Result{
|
||||||
Code: ok.ToInt(),
|
Code: ok.ToInt(),
|
||||||
Data: PageResult[interface{}]{
|
Data: PageResult[interface{}]{
|
||||||
Anchor: fbl.ToString(anchor),
|
Anchor: utils.ToString(anchor),
|
||||||
End: fbl.ToPtr(true),
|
End: fbl.ToPtr(true),
|
||||||
List: emptyList,
|
List: emptyList,
|
||||||
},
|
},
|
||||||
|
29
common/utils/to_string.go
Normal file
29
common/utils/to_string.go
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"reflect"
|
||||||
|
)
|
||||||
|
|
||||||
|
func ToString(arg any) string {
|
||||||
|
buf := bytes.NewBufferString("")
|
||||||
|
_, err := fmt.Fprint(buf, arg)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Errorf("ToString err %s %+v", arg, err)
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return buf.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
func ToStringCompatiblePtr(arg any) string {
|
||||||
|
if arg == nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
if reflect.TypeOf(arg).Kind() != reflect.Ptr {
|
||||||
|
return ToString(arg)
|
||||||
|
}
|
||||||
|
|
||||||
|
return ToStringCompatiblePtr(reflect.Indirect(reflect.ValueOf(arg)))
|
||||||
|
}
|
@ -10,7 +10,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
fbcontext "code.freebrio.com/fb-go/lib/context"
|
fbcontext "code.freebrio.com/fb-go/lib/context"
|
||||||
"code.freebrio.com/fb-go/lib/fbl"
|
|
||||||
"code.freebrio.com/fb-go/lib/gorm/logger"
|
"code.freebrio.com/fb-go/lib/gorm/logger"
|
||||||
|
|
||||||
_ "github.com/spf13/viper/remote"
|
_ "github.com/spf13/viper/remote"
|
||||||
@ -41,14 +40,14 @@ func getInstance() *gorm.DB {
|
|||||||
})
|
})
|
||||||
|
|
||||||
if instanceErr != nil {
|
if instanceErr != nil {
|
||||||
fbl.Log().Sugar().Errorf("mysql_getInstance instanceErr: %v", instanceErr)
|
utils.Log().Sugar().Errorf("mysql_getInstance instanceErr: %v", instanceErr)
|
||||||
os.Exit(-1)
|
os.Exit(-1)
|
||||||
}
|
}
|
||||||
|
|
||||||
var sqlDB *sql.DB
|
var sqlDB *sql.DB
|
||||||
sqlDB, instanceErr = db.DB()
|
sqlDB, instanceErr = db.DB()
|
||||||
if instanceErr != nil {
|
if instanceErr != nil {
|
||||||
fbl.Log().Sugar().Errorf("mysql_getInstance sqlDB: %v", instanceErr)
|
//fbl.Log().Sugar().Errorf("mysql_getInstance sqlDB: %v", instanceErr)
|
||||||
os.Exit(-1)
|
os.Exit(-1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package repository
|
package repository
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"ai-gateway/common/utils"
|
||||||
"code.freebrio.com/fb-go/lib/context"
|
"code.freebrio.com/fb-go/lib/context"
|
||||||
"code.freebrio.com/fb-go/lib/fbl"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ func (thirdAgentCorpRepositoryImpl) QueryPage(ctx context.GormWithZap, page, siz
|
|||||||
}
|
}
|
||||||
|
|
||||||
offset := (page - 1) * size
|
offset := (page - 1) * size
|
||||||
offset = fbl.If(offset >= 0, offset, 0)
|
offset = utils.If(offset >= 0, offset, 0)
|
||||||
var dataList []FThirdAgentCorpRelationDO
|
var dataList []FThirdAgentCorpRelationDO
|
||||||
sqlErr := db.Model(&FThirdAgentCorpRelationDO{}).Order("id DESC").Limit(size).Offset(offset).Find(&dataList).Error
|
sqlErr := db.Model(&FThirdAgentCorpRelationDO{}).Order("id DESC").Limit(size).Offset(offset).Find(&dataList).Error
|
||||||
if sqlErr != nil {
|
if sqlErr != nil {
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package repository
|
package repository
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"ai-gateway/common/utils"
|
||||||
"code.freebrio.com/fb-go/lib/context"
|
"code.freebrio.com/fb-go/lib/context"
|
||||||
"code.freebrio.com/fb-go/lib/fbl"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -36,7 +36,7 @@ func (thirdAgentInfoRepositoryImpl) QueryPage(ctx context.GormWithZap, page, siz
|
|||||||
}
|
}
|
||||||
|
|
||||||
offset := (page - 1) * size
|
offset := (page - 1) * size
|
||||||
offset = fbl.If(offset >= 0, offset, 0)
|
offset = utils.If(offset >= 0, offset, 0)
|
||||||
var dataList []FThirdAgentInfoDO
|
var dataList []FThirdAgentInfoDO
|
||||||
sqlErr := db.Model(&FThirdAgentInfoDO{}).Order("id DESC").Limit(size).Offset(offset).Find(&dataList).Error
|
sqlErr := db.Model(&FThirdAgentInfoDO{}).Order("id DESC").Limit(size).Offset(offset).Find(&dataList).Error
|
||||||
if sqlErr != nil {
|
if sqlErr != nil {
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package repository
|
package repository
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"ai-gateway/common/utils"
|
||||||
"code.freebrio.com/fb-go/lib/context"
|
"code.freebrio.com/fb-go/lib/context"
|
||||||
"code.freebrio.com/fb-go/lib/fbl"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -35,7 +35,7 @@ func (thirdCorpInfoRepositoryImpl) QueryPage(ctx context.GormWithZap, page, size
|
|||||||
}
|
}
|
||||||
|
|
||||||
offset := (page - 1) * size
|
offset := (page - 1) * size
|
||||||
offset = fbl.If(offset >= 0, offset, 0)
|
offset = utils.If(offset >= 0, offset, 0)
|
||||||
var dataList []FThirdCorpInfoDO
|
var dataList []FThirdCorpInfoDO
|
||||||
sqlErr := db.Model(&FThirdCorpInfoDO{}).Order("id DESC").Limit(size).Offset(offset).Find(&dataList).Error
|
sqlErr := db.Model(&FThirdCorpInfoDO{}).Order("id DESC").Limit(size).Offset(offset).Find(&dataList).Error
|
||||||
if sqlErr != nil {
|
if sqlErr != nil {
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package repository
|
package repository
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"ai-gateway/common/utils"
|
||||||
"code.freebrio.com/fb-go/lib/context"
|
"code.freebrio.com/fb-go/lib/context"
|
||||||
"code.freebrio.com/fb-go/lib/fbl"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -36,7 +36,7 @@ func (thirdCorpUserAccountRepositoryImpl) QueryPage(ctx context.GormWithZap, pag
|
|||||||
}
|
}
|
||||||
|
|
||||||
offset := (page - 1) * size
|
offset := (page - 1) * size
|
||||||
offset = fbl.If(offset >= 0, offset, 0)
|
offset = utils.If(offset >= 0, offset, 0)
|
||||||
var dataList []FThirdCorpUserAccountDO
|
var dataList []FThirdCorpUserAccountDO
|
||||||
sqlErr := db.Model(&FThirdCorpUserAccountDO{}).Order("id DESC").Limit(size).Offset(offset).Find(&dataList).Error
|
sqlErr := db.Model(&FThirdCorpUserAccountDO{}).Order("id DESC").Limit(size).Offset(offset).Find(&dataList).Error
|
||||||
if sqlErr != nil {
|
if sqlErr != nil {
|
||||||
|
2
main.go
2
main.go
@ -5,7 +5,6 @@ import (
|
|||||||
"ai-gateway/common/constant"
|
"ai-gateway/common/constant"
|
||||||
"ai-gateway/common/filter"
|
"ai-gateway/common/filter"
|
||||||
"ai-gateway/common/utils"
|
"ai-gateway/common/utils"
|
||||||
"code.freebrio.com/fb-go/lib/echo/helper"
|
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
@ -23,7 +22,6 @@ func main() {
|
|||||||
e.HideBanner = true
|
e.HideBanner = true
|
||||||
e.HidePort = true
|
e.HidePort = true
|
||||||
e.Validator = utils.NewValidator()
|
e.Validator = utils.NewValidator()
|
||||||
e.HTTPErrorHandler = helper.FBHTTPErrorHandler
|
|
||||||
e.Use(middleware.Recover())
|
e.Use(middleware.Recover())
|
||||||
|
|
||||||
// Middleware
|
// Middleware
|
||||||
|
@ -7,7 +7,6 @@ import (
|
|||||||
"ai-gateway/infrastructure/redis"
|
"ai-gateway/infrastructure/redis"
|
||||||
"ai-gateway/infrastructure/repository"
|
"ai-gateway/infrastructure/repository"
|
||||||
"code.freebrio.com/fb-go/lib/context"
|
"code.freebrio.com/fb-go/lib/context"
|
||||||
"code.freebrio.com/fb-go/lib/fbl"
|
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
@ -107,20 +106,20 @@ func (login) ParseThirdUserLoginTokenByToken(accessToken string) *dto.ThirdUserL
|
|||||||
}
|
}
|
||||||
|
|
||||||
return &dto.ThirdUserLoginToken{
|
return &dto.ThirdUserLoginToken{
|
||||||
CorpId: fbl.ToUint64(splits[0]),
|
CorpId: utils.ToUint64(splits[0]),
|
||||||
BizId: fbl.ToUint64(splits[1]),
|
BizId: utils.ToUint64(splits[1]),
|
||||||
Uid: fbl.ToUint64(splits[2]),
|
Uid: utils.ToUint64(splits[2]),
|
||||||
AccessToken: splits[3],
|
AccessToken: splits[3],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (login) GenAccessToken(data *repository.FThirdUserTokenDO) string {
|
func (login) GenAccessToken(data *repository.FThirdUserTokenDO) string {
|
||||||
var buf strings.Builder
|
var buf strings.Builder
|
||||||
buf.WriteString(fbl.ToString(data.CorpId))
|
buf.WriteString(utils.ToString(data.CorpId))
|
||||||
buf.WriteString("_")
|
buf.WriteString("_")
|
||||||
buf.WriteString(fbl.ToString(data.BizId))
|
buf.WriteString(utils.ToString(data.BizId))
|
||||||
buf.WriteString("_")
|
buf.WriteString("_")
|
||||||
buf.WriteString(fbl.ToString(data.CorpUid))
|
buf.WriteString(utils.ToString(data.CorpUid))
|
||||||
buf.WriteString("_")
|
buf.WriteString("_")
|
||||||
buf.WriteString(data.AccessToken)
|
buf.WriteString(data.AccessToken)
|
||||||
return buf.String()
|
return buf.String()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user