将go Httpserver.Run() 挪到 routeregister方法

This commit is contained in:
Cold
2025-12-19 17:57:46 +08:00
committed by 张斌
parent 5d22d07a3b
commit 2a31e3faac
2 changed files with 13 additions and 13 deletions

View File

@@ -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)

View File

@@ -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
} }