package controllers import ( "errors" "github.com/gin-gonic/gin" ) func getCode(ctx *gin.Context) (string, error) { userIDInterface, exists := ctx.Get("code") if !exists { return "", errors.New("用户ID不存在") } code, ok := userIDInterface.(string) if !ok { return "", errors.New("用户ID类型错误") } return code, nil }