将go Httpserver.Run() 挪到 routeregister方法
This commit is contained in:
@@ -44,7 +44,6 @@ func init() {
|
|||||||
Httpserver.SetOpenApiPath("/api.json")
|
Httpserver.SetOpenApiPath("/api.json")
|
||||||
Httpserver.SetDumpRouterMap(true) //关闭打印路由注册信息
|
Httpserver.SetDumpRouterMap(true) //关闭打印路由注册信息
|
||||||
Httpserver.BindMiddlewareDefault(ghttp.MiddlewareHandlerResponse)
|
Httpserver.BindMiddlewareDefault(ghttp.MiddlewareHandlerResponse)
|
||||||
go Httpserver.Run()
|
|
||||||
Httpclient.SetDiscovery(gsvc.GetRegistry())
|
Httpclient.SetDiscovery(gsvc.GetRegistry())
|
||||||
}
|
}
|
||||||
func RouteRegister(controllers []interface{}) {
|
func RouteRegister(controllers []interface{}) {
|
||||||
@@ -59,6 +58,7 @@ func RouteRegister(controllers []interface{}) {
|
|||||||
group.Bind(t)
|
group.Bind(t)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
go Httpserver.Run()
|
||||||
}
|
}
|
||||||
func doRequest(ctx context.Context, method string, url string, target any, data ...any) (err error) {
|
func doRequest(ctx context.Context, method string, url string, target any, data ...any) (err error) {
|
||||||
err = utils.ValidStructPtr(target)
|
err = utils.ValidStructPtr(target)
|
||||||
|
|||||||
@@ -567,9 +567,9 @@ const (
|
|||||||
ConversationCacheExpireSeconds = 600
|
ConversationCacheExpireSeconds = 600
|
||||||
)
|
)
|
||||||
|
|
||||||
// CacheConversation 缓存单条对话到Redis List
|
// CacheConversation 缓存单条对话到Redis List(按sessionId存储)
|
||||||
func CacheConversation(ctx context.Context, userId, platform string, data []byte) error {
|
func CacheConversation(ctx context.Context, sessionId string, data []byte) error {
|
||||||
key := ConversationCacheKeyPrefix + userId + "_" + platform
|
key := ConversationCacheKeyPrefix + sessionId
|
||||||
_, err := redisClient.Do(ctx, "RPUSH", key, string(data))
|
_, err := redisClient.Do(ctx, "RPUSH", key, string(data))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -578,9 +578,9 @@ func CacheConversation(ctx context.Context, userId, platform string, data []byte
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetCachedConversations 获取缓存的对话列表并清空
|
// GetCachedConversations 获取缓存的对话列表并清空(按sessionId查询)
|
||||||
func GetCachedConversations(ctx context.Context, userId, platform string) (list []string, err error) {
|
func GetCachedConversations(ctx context.Context, sessionId string) (list []string, err error) {
|
||||||
key := ConversationCacheKeyPrefix + userId + "_" + platform
|
key := ConversationCacheKeyPrefix + sessionId
|
||||||
result, err := redisClient.Do(ctx, "LRANGE", key, 0, -1)
|
result, err := redisClient.Do(ctx, "LRANGE", key, 0, -1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
@@ -594,9 +594,9 @@ func GetCachedConversations(ctx context.Context, userId, platform string) (list
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetCachedConversationCount 获取缓存的对话数量
|
// GetCachedConversationCount 获取缓存的对话数量(按sessionId查询)
|
||||||
func GetCachedConversationCount(ctx context.Context, userId, platform string) (count int64, err error) {
|
func GetCachedConversationCount(ctx context.Context, sessionId string) (count int64, err error) {
|
||||||
key := ConversationCacheKeyPrefix + userId + "_" + platform
|
key := ConversationCacheKeyPrefix + sessionId
|
||||||
result, err := redisClient.Do(ctx, "LLEN", key)
|
result, err := redisClient.Do(ctx, "LLEN", key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
@@ -604,9 +604,9 @@ func GetCachedConversationCount(ctx context.Context, userId, platform string) (c
|
|||||||
return result.Int64(), nil
|
return result.Int64(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ClearCachedConversations 清空对话缓存(归档时调用)
|
// ClearCachedConversations 清空对话缓存(归档时调用,按sessionId)
|
||||||
func ClearCachedConversations(ctx context.Context, userId, platform string) error {
|
func ClearCachedConversations(ctx context.Context, sessionId string) error {
|
||||||
key := ConversationCacheKeyPrefix + userId + "_" + platform
|
key := ConversationCacheKeyPrefix + sessionId
|
||||||
_, err := redisClient.Del(ctx, key)
|
_, err := redisClient.Del(ctx, key)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user