Files
tyapi-server/internal/shared/payment/context.go
2025-12-12 15:27:15 +08:00

26 lines
434 B
Go

package payment
import (
"context"
"fmt"
)
// GetUidFromCtx 从context中获取用户ID
func GetUidFromCtx(ctx context.Context) (string, error) {
userID := ctx.Value("user_id")
if userID == nil {
return "", fmt.Errorf("用户ID不存在于上下文中")
}
id, ok := userID.(string)
if !ok {
return "", fmt.Errorf("用户ID类型错误")
}
if id == "" {
return "", fmt.Errorf("用户ID为空")
}
return id, nil
}