2026-05-23 22:10:20 +08:00
|
|
|
package httpx
|
2026-04-09 10:01:23 +08:00
|
|
|
|
|
|
|
|
import (
|
2026-08-21 00:41:07 +08:00
|
|
|
"code.tczkiot.com/wlw/ai-agent/internal/pkg/httpx/params"
|
|
|
|
|
"code.tczkiot.com/wlw/ai-agent/internal/pkg/openidentity"
|
|
|
|
|
"code.tczkiot.com/wlw/ai-agent/internal/pkg/tracex"
|
2026-04-09 10:01:23 +08:00
|
|
|
|
2026-05-23 22:10:20 +08:00
|
|
|
"github.com/gin-gonic/gin"
|
2026-04-25 10:27:43 +08:00
|
|
|
"github.com/mlogclub/simple/common/strs"
|
2026-04-09 10:01:23 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const (
|
2026-04-28 11:10:47 +08:00
|
|
|
ctxKeyExternalUser = "externalUser"
|
2026-04-09 10:01:23 +08:00
|
|
|
)
|
|
|
|
|
|
2026-05-23 22:10:20 +08:00
|
|
|
func SetExternalUser(ctx *gin.Context, ext *openidentity.ExternalUser) {
|
|
|
|
|
ctx.Set(ctxKeyExternalUser, ext)
|
2026-04-09 10:01:23 +08:00
|
|
|
}
|
|
|
|
|
|
2026-05-23 22:10:20 +08:00
|
|
|
func GetExternalUser(ctx *gin.Context) *openidentity.ExternalUser {
|
|
|
|
|
v, _ := ctx.Get(ctxKeyExternalUser)
|
2026-04-28 11:10:47 +08:00
|
|
|
ext, _ := v.(*openidentity.ExternalUser)
|
2026-04-09 10:01:23 +08:00
|
|
|
return ext
|
|
|
|
|
}
|
2026-04-25 10:27:43 +08:00
|
|
|
|
2026-05-23 22:10:20 +08:00
|
|
|
func GetChannelID(ctx *gin.Context) string {
|
2026-04-25 10:27:43 +08:00
|
|
|
if channelID := ctx.GetHeader("X-Channel-ID"); strs.IsNotBlank(channelID) {
|
|
|
|
|
return channelID
|
|
|
|
|
}
|
2026-08-28 22:23:13 +08:00
|
|
|
if channelID, _ := params.Get(ctx, "channel_id"); strs.IsNotBlank(channelID) {
|
2026-04-25 10:27:43 +08:00
|
|
|
return channelID
|
|
|
|
|
}
|
|
|
|
|
return ""
|
|
|
|
|
}
|
2026-05-27 22:18:43 +08:00
|
|
|
|
|
|
|
|
func GetRequestID(ctx *gin.Context) string {
|
|
|
|
|
if ctx == nil {
|
|
|
|
|
return ""
|
|
|
|
|
}
|
|
|
|
|
if value, ok := ctx.Get(tracex.GinRequestIDKey); ok {
|
|
|
|
|
if requestID, ok := value.(string); ok {
|
|
|
|
|
return tracex.NormalizeRequestID(requestID)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return tracex.NormalizeRequestID(ctx.GetHeader(tracex.RequestIDHeader))
|
|
|
|
|
}
|