🏗️ microservice fabric splitting
This commit is contained in:
120
app/auth/api/Dockerfile
Normal file
120
app/auth/api/Dockerfile
Normal file
@@ -0,0 +1,120 @@
|
||||
# to build this docker image:
|
||||
# docker build -f Dockerfile -t schisandra-cloud-album-server .
|
||||
# docker build --build-arg OPENCV_VERSION="4.x" --build-arg OPENCV_FILE="https://github.com/opencv/opencv/archive/refs/heads/4.x.zip" --build-arg OPENCV_CONTRIB_FILE="https://github.com/opencv/opencv_contrib/archive/refs/heads/4.x.zip" -f Dockerfile -t schisandra-cloud-album-server .
|
||||
|
||||
FROM ubuntu:20.04 AS opencv-builder
|
||||
|
||||
LABEL maintainer="landaiqing <<landaiqing@126.com>>"
|
||||
|
||||
RUN sed -i 's|http://archive.ubuntu.com/ubuntu/|http://mirrors.aliyun.com/ubuntu/|g' /etc/apt/sources.list
|
||||
|
||||
ENV TZ=Europe/Madrid
|
||||
|
||||
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
|
||||
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends --fix-missing \
|
||||
tzdata git build-essential cmake pkg-config wget unzip libgtk2.0-dev \
|
||||
curl ca-certificates libcurl4-openssl-dev libssl-dev \
|
||||
libavcodec-dev libavformat-dev libswscale-dev libtbb2 libtbb-dev \
|
||||
libharfbuzz-dev libfreetype6-dev \
|
||||
libjpeg-turbo8-dev libpng-dev libtiff-dev libdc1394-22-dev nasm && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
ARG OPENCV_VERSION="4.10.0"
|
||||
|
||||
ENV OPENCV_VERSION=$OPENCV_VERSION
|
||||
|
||||
ARG OPENCV_FILE="https://github.com/opencv/opencv/archive/${OPENCV_VERSION}.zip"
|
||||
|
||||
ENV OPENCV_FILE=$OPENCV_FILE
|
||||
|
||||
ARG OPENCV_CONTRIB_FILE="https://github.com/opencv/opencv_contrib/archive/${OPENCV_VERSION}.zip"
|
||||
|
||||
ENV OPENCV_CONTRIB_FILE=$OPENCV_CONTRIB_FILE
|
||||
|
||||
RUN curl -Lo opencv.zip ${OPENCV_FILE} && \
|
||||
unzip -q opencv.zip && \
|
||||
curl -Lo opencv_contrib.zip ${OPENCV_CONTRIB_FILE} && \
|
||||
unzip -q opencv_contrib.zip && \
|
||||
rm opencv.zip opencv_contrib.zip && \
|
||||
cd opencv-${OPENCV_VERSION} && \
|
||||
mkdir build && cd build && \
|
||||
cmake -D CMAKE_BUILD_TYPE=RELEASE \
|
||||
-D WITH_IPP=OFF \
|
||||
-D WITH_OPENGL=OFF \
|
||||
-D WITH_QT=OFF \
|
||||
-D WITH_FREETYPE=ON \
|
||||
-D CMAKE_INSTALL_PREFIX=/usr/local \
|
||||
-D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-${OPENCV_VERSION}/modules \
|
||||
-D OPENCV_ENABLE_NONFREE=ON \
|
||||
-D WITH_JASPER=OFF \
|
||||
-D WITH_TBB=ON \
|
||||
-D BUILD_JPEG=ON \
|
||||
-D WITH_SIMD=ON \
|
||||
-D ENABLE_LIBJPEG_TURBO_SIMD=ON \
|
||||
-D BUILD_DOCS=OFF \
|
||||
-D BUILD_EXAMPLES=OFF \
|
||||
-D BUILD_TESTS=OFF \
|
||||
-D BUILD_PERF_TESTS=ON \
|
||||
-D BUILD_opencv_java=NO \
|
||||
-D BUILD_opencv_python=NO \
|
||||
-D BUILD_opencv_python2=NO \
|
||||
-D BUILD_opencv_python3=NO \
|
||||
-D OPENCV_GENERATE_PKGCONFIG=ON .. && \
|
||||
make -j $(nproc --all) && \
|
||||
make preinstall && make install && ldconfig && \
|
||||
cd / && rm -rf opencv*
|
||||
|
||||
|
||||
FROM golang:1.23.1-alpine AS go-builder
|
||||
|
||||
RUN apk add --no-cache gcc musl-dev libgcc libstdc++ cmake
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY . .
|
||||
|
||||
ENV CGO_ENABLED=1
|
||||
|
||||
ENV CGO_CFLAGS="-I/usr/local/include/opencv4"
|
||||
|
||||
ENV CGO_LDFLAGS="-L/usr/local/lib -lopencv_core -lopencv_imgproc -lopencv_highgui"
|
||||
|
||||
ENV GOOS=linux
|
||||
|
||||
ENV GOARCH=amd64
|
||||
|
||||
ENV GOPROXY=https://goproxy.cn,direct
|
||||
|
||||
COPY --from=opencv-builder /usr/local/lib /usr/local/lib
|
||||
COPY --from=opencv-builder /usr/local/include/opencv4 /usr/local/include/opencv4
|
||||
|
||||
RUN go mod download
|
||||
|
||||
RUN go build -o schisandra-cloud-album-server
|
||||
|
||||
FROM alpine:latest
|
||||
|
||||
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
|
||||
|
||||
RUN apk add --no-cache tzdata
|
||||
|
||||
ENV TZ=Asia/Shanghai
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY --from=go-builder /app/schisandra-cloud-album-server .
|
||||
|
||||
COPY --from=go-builder /app/config.yaml .
|
||||
|
||||
COPY --from=go-builder /app/resource ./resource
|
||||
|
||||
COPY --from=go-builder /app/config/rbac_model.conf ./config/rbac_model.conf
|
||||
|
||||
COPY --from=opencv-builder /usr/local/lib /usr/local/lib
|
||||
|
||||
COPY --from=opencv-builder /usr/local/include/opencv4 /usr/local/include/opencv4
|
||||
|
||||
EXPOSE 80
|
||||
|
||||
CMD ["./schisandra-cloud-album-server"]
|
251
app/auth/api/auth.api
Normal file
251
app/auth/api/auth.api
Normal file
@@ -0,0 +1,251 @@
|
||||
syntax = "v1"
|
||||
|
||||
info (
|
||||
title: "鉴权服务"
|
||||
desc: "鉴权服务"
|
||||
author: "landaiqing"
|
||||
email: "landaiqing@126.com"
|
||||
version: "v1.0.0"
|
||||
)
|
||||
|
||||
// 登录请求参数
|
||||
type (
|
||||
// 账户登录请求参数
|
||||
AccountLoginRequest {
|
||||
Account string `json:"account"`
|
||||
Password string `json:"password"`
|
||||
AutoLogin bool `json:"auto_login"`
|
||||
Angle int64 `json:"angle"`
|
||||
Key string `json:"key"`
|
||||
}
|
||||
// 手机号登录请求参数
|
||||
PhoneLoginRequest {
|
||||
Phone string `json:"phone"`
|
||||
Captcha string `json:"captcha"`
|
||||
AutoLogin bool `json:"auto_login"`
|
||||
}
|
||||
// 重置密码请求参数
|
||||
ResetPasswordRequest {
|
||||
Phone string `json:"phone"`
|
||||
Captcha string `json:"captcha"`
|
||||
Password string `json:"password"`
|
||||
Repassword string `json:"repassword"`
|
||||
}
|
||||
WechatOffiaccountLoginRequest {
|
||||
Openid string `json:"openid"`
|
||||
ClientId string `json:"client_id"`
|
||||
}
|
||||
// 登录响应参数
|
||||
LoginResponse {
|
||||
AccessToken string `json:"access_token"`
|
||||
ExpireAt int64 `json:"expire_at"`
|
||||
UID string `json:"uid"`
|
||||
Username string `json:"username,omitempty"`
|
||||
Nickname string `json:"nickname"`
|
||||
Avatar string `json:"avatar"`
|
||||
Status int64 `json:"status"`
|
||||
}
|
||||
)
|
||||
|
||||
// OAuth请求参数
|
||||
type (
|
||||
// OAuth请求参数
|
||||
OAuthRequest {
|
||||
state string `form:"state"`
|
||||
}
|
||||
// OAuth回调请求参数
|
||||
OAuthCallbackRequest {
|
||||
Code string `form:"code"`
|
||||
}
|
||||
OAuthWechatRequest {
|
||||
clientId string `json:"client_id"`
|
||||
}
|
||||
)
|
||||
|
||||
// 短信发送请求参数
|
||||
type (
|
||||
SmsSendRequest {
|
||||
Phone string `json:"phone"`
|
||||
Angle int64 `json:"angle"`
|
||||
Key string `json:"key"`
|
||||
}
|
||||
)
|
||||
|
||||
// 刷新token响应参数
|
||||
type (
|
||||
RefreshTokenResponse {
|
||||
AccessToken string `json:"access_token"`
|
||||
ExpireAt int64 `json:"expire_at"`
|
||||
}
|
||||
)
|
||||
|
||||
// 验证码响应参数
|
||||
type (
|
||||
RotateCaptchaResponse {
|
||||
Key string `json:"key"`
|
||||
Image string `json:"image"`
|
||||
Thumb string `json:"thumb"`
|
||||
}
|
||||
SlideCaptchaResponse {
|
||||
Key string `json:"key"`
|
||||
Image string `json:"image"`
|
||||
Thumb string `json:"thumb"`
|
||||
ThumbWidth int64 `json:"thumb_width"`
|
||||
ThumbHeight int64 `json:"thumb_height"`
|
||||
ThumbX int64 `json:"thumb_x"`
|
||||
ThumbY int64 `json:"thumb_y"`
|
||||
}
|
||||
)
|
||||
|
||||
// 用户服务
|
||||
@server (
|
||||
group: user // 微服务分组
|
||||
prefix: /api/user // 微服务前缀
|
||||
timeout: 10s // 超时时间
|
||||
maxBytes: 1048576 // 最大请求大小
|
||||
signature: true // 是否开启签名验证
|
||||
middleware: SecurityHeadersMiddleware,NonceMiddleware // 注册中间件
|
||||
MaxConns: true // 是否开启最大连接数限制
|
||||
Recover: true // 是否开启自动恢复
|
||||
)
|
||||
service auth {
|
||||
// 账户登录
|
||||
@handler accountLogin
|
||||
post /login (AccountLoginRequest) returns (LoginResponse)
|
||||
|
||||
// 手机号登录
|
||||
@handler phoneLogin
|
||||
post /phone/login (PhoneLoginRequest) returns (LoginResponse)
|
||||
|
||||
// 重置密码
|
||||
@handler resetPassword
|
||||
post /reset/password (ResetPasswordRequest)
|
||||
|
||||
// 微信公众号登录
|
||||
@handler wechatOffiaccountLogin
|
||||
post /wechat/offiaccount/login (WechatOffiaccountLoginRequest) returns (LoginResponse)
|
||||
|
||||
// 获取微信公众号二维码
|
||||
@handler getWechatOffiaccountQrcode
|
||||
post /wechat/offiaccount/qrcode (OAuthWechatRequest) returns (string)
|
||||
}
|
||||
|
||||
@server (
|
||||
group: token // 微服务分组
|
||||
prefix: /api/auth // 微服务前缀
|
||||
timeout: 10s // 超时时间
|
||||
maxBytes: 1048576 // 最大请求大小
|
||||
signature: true // 是否开启签名验证
|
||||
middleware: SecurityHeadersMiddleware,CasbinVerifyMiddleware,NonceMiddleware // 注册中间件
|
||||
MaxConns: true // 是否开启最大连接数限制
|
||||
Recover: true // 是否开启自动恢复
|
||||
)
|
||||
service auth {
|
||||
@handler refreshToken
|
||||
post /token/refresh returns (RefreshTokenResponse)
|
||||
}
|
||||
|
||||
// 客户端服务
|
||||
@server (
|
||||
group: client // 微服务分组
|
||||
prefix: /api/client // 微服务前缀
|
||||
timeout: 10s // 超时时间
|
||||
maxBytes: 1048576 // 最大请求大小
|
||||
signature: false // 是否开启签名验证
|
||||
middleware: SecurityHeadersMiddleware,NonceMiddleware // 注册中间件
|
||||
MaxConns: true // 是否开启最大连接数限制
|
||||
Recover: true // 是否开启自动恢复
|
||||
)
|
||||
service auth {
|
||||
@handler generateClientId
|
||||
get /generate returns (string)
|
||||
}
|
||||
|
||||
@server (
|
||||
group: websocket // 微服务分组
|
||||
prefix: /api/ws // 微服务前缀
|
||||
)
|
||||
service auth {
|
||||
@handler qrcodeWebsocket
|
||||
get /qrcode
|
||||
|
||||
@handler messageWebsocket
|
||||
get /message
|
||||
}
|
||||
|
||||
@server (
|
||||
group: oauth // 微服务分组
|
||||
prefix: /api/oauth // 微服务前缀
|
||||
timeout: 10s // 超时时间
|
||||
maxBytes: 1048576 // 最大请求大小
|
||||
signature: false // 是否开启签名验证
|
||||
middleware: SecurityHeadersMiddleware // 注册中间件
|
||||
MaxConns: true // 是否开启最大连接数限制
|
||||
Recover: true // 是否开启自动恢复
|
||||
)
|
||||
service auth {
|
||||
@handler getGiteeOauthUrl
|
||||
get /gitee/url returns (string)
|
||||
|
||||
@handler getGithubOauthUrl
|
||||
get /github/url (OAuthRequest) returns (string)
|
||||
|
||||
@handler getQqOauthUrl
|
||||
get /qq/url (OAuthRequest) returns (string)
|
||||
|
||||
@handler giteeCallback
|
||||
get /gitee/callback (OAuthCallbackRequest) returns (string)
|
||||
|
||||
@handler githubCallback
|
||||
get /github/callback (OAuthCallbackRequest) returns (string)
|
||||
|
||||
@handler qqCallback
|
||||
get /qq/callback (OAuthCallbackRequest) returns (string)
|
||||
|
||||
@handler wechatOffiaccountCallback
|
||||
post /wechat/offiaccount/callback
|
||||
|
||||
// important!
|
||||
@handler wechatOffiaccountCallbackVerify
|
||||
get /wechat/offiaccount/callback
|
||||
}
|
||||
|
||||
@server (
|
||||
group: sms // 微服务分组
|
||||
prefix: /api/sms // 微服务前缀
|
||||
timeout: 10s // 超时时间
|
||||
maxBytes: 1048576 // 最大请求大小
|
||||
signature: false // 是否开启签名验证
|
||||
middleware: SecurityHeadersMiddleware,NonceMiddleware // 注册中间件
|
||||
MaxConns: true // 是否开启最大连接数限制
|
||||
Recover: true // 是否开启自动恢复
|
||||
)
|
||||
service auth {
|
||||
@handler sendSmsByAliyun
|
||||
post /ali/send (SmsSendRequest)
|
||||
|
||||
@handler sendSmsBySmsbao
|
||||
post /smsbao/send (SmsSendRequest)
|
||||
|
||||
@handler sendSmsByTest
|
||||
post /test/send (SmsSendRequest) returns (string)
|
||||
}
|
||||
|
||||
@server (
|
||||
group: captcha // 微服务分组
|
||||
prefix: /api/captcha // 微服务前缀
|
||||
timeout: 10s // 超时时间
|
||||
maxBytes: 1048576 // 最大请求大小
|
||||
signature: false // 是否开启签名验证
|
||||
middleware: SecurityHeadersMiddleware,NonceMiddleware // 注册中间件
|
||||
MaxConns: true // 是否开启最大连接数限制
|
||||
Recover: true // 是否开启自动恢复
|
||||
)
|
||||
service auth {
|
||||
@handler generateRotateCaptcha
|
||||
get /rotate/generate returns (RotateCaptchaResponse)
|
||||
|
||||
@handler generateSlideBasicCaptcha
|
||||
get /slide/generate returns (SlideCaptchaResponse)
|
||||
}
|
||||
|
38
app/auth/api/auth.go
Normal file
38
app/auth/api/auth.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/conf"
|
||||
"github.com/zeromicro/go-zero/rest"
|
||||
"schisandra-album-cloud-microservices/common/idgenerator"
|
||||
"schisandra-album-cloud-microservices/common/middleware"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/config"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/handler"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
|
||||
)
|
||||
|
||||
var configFile = flag.String("f", "etc/auth.yaml", "the config file")
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
var c config.Config
|
||||
conf.MustLoad(*configFile, &c)
|
||||
|
||||
server := rest.MustNewServer(
|
||||
c.RestConf,
|
||||
rest.WithCustomCors(middleware.CORSMiddleware(), nil),
|
||||
rest.WithUnauthorizedCallback(middleware.UnauthorizedCallbackMiddleware()),
|
||||
rest.WithUnsignedCallback(middleware.UnsignedCallbackMiddleware()))
|
||||
defer server.Stop()
|
||||
// i18n middleware
|
||||
server.Use(middleware.I18nMiddleware)
|
||||
ctx := svc.NewServiceContext(c)
|
||||
handler.RegisterHandlers(server, ctx)
|
||||
// initialize id generator
|
||||
idgenerator.NewIDGenerator(0)
|
||||
fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
|
||||
server.Start()
|
||||
}
|
150
app/auth/api/etc/auth.yaml
Normal file
150
app/auth/api/etc/auth.yaml
Normal file
@@ -0,0 +1,150 @@
|
||||
# 定义服务的名称,会出现在 log 和 tracer 中
|
||||
Name: schisandra-auth-service
|
||||
# 监听地址
|
||||
Host: 0.0.0.0
|
||||
# 监听端口
|
||||
Port: 8080
|
||||
# 服务的环境,目前我们预定义了 dev。在dev 环境我们会开启反射 dev,test,rt,pre, pro
|
||||
Mode: pro
|
||||
# 打点上报,将一些 metrics 上报到对应的地址,如果为空,则不上报
|
||||
MetricsUrl:
|
||||
# 并发请求数
|
||||
MaxConns: 100
|
||||
# 超时时间(ms)
|
||||
Timeout: 5000
|
||||
# 降载阈值,默认900(90%),可允许设置范围0到1000
|
||||
CpuThreshold: 900
|
||||
# 最大ContentLength
|
||||
MaxBytes: 10485760
|
||||
# 是否打印详细日志
|
||||
Verbose: false
|
||||
# 日志配置
|
||||
Log:
|
||||
# 服务名称
|
||||
ServiceName: schisandra-auth-service
|
||||
# 日志打印模式,console 控制台 file, console
|
||||
Mode: console
|
||||
# 日志格式, json 格式 或者 plain 纯文本
|
||||
Encoding: plain
|
||||
# 日期格式化
|
||||
TimeFormat:
|
||||
# 日志在文件输出模式下,日志输出路径
|
||||
Path: logs/system
|
||||
# 日志输出级别 debug,info,error,severe
|
||||
Level: debug
|
||||
# 日志长度限制,打印单个日志的时候会对日志进行裁剪,只有对 content 进行裁剪
|
||||
MaxContentLength: 0
|
||||
# 是否压缩日志
|
||||
Compress: true
|
||||
# 是否开启 stat 日志,go-zero 版本大于等于1.5.0才支持
|
||||
Stat: false
|
||||
# 日志保留天数,只有在文件模式才会生效
|
||||
KeepDays: 7
|
||||
# 堆栈打印冷却时间
|
||||
StackCooldownMillis: 100
|
||||
# 文件输出模式,按照大小分割时,最多文件保留个数
|
||||
MaxBackups: 5
|
||||
# 文件输出模式,按照大小分割时,单个文件大小
|
||||
MaxSize: 0
|
||||
# 文件分割模式, daily 按日期 daily,size
|
||||
Rotation: daily
|
||||
# 文件名日期格式
|
||||
FileTimeFormat:
|
||||
Web:
|
||||
URL: http://localhost:5173/
|
||||
# 启用中间件
|
||||
Middlewares:
|
||||
# 访问日志中间件
|
||||
Log: true
|
||||
# MySQL 配置
|
||||
Mysql:
|
||||
# 数据源dsn
|
||||
DataSource: root:LDQ20020618xxx@tcp(1.95.0.111:3306)/schisandra-cloud-album?charset=utf8mb4&parseTime=True&loc=Local
|
||||
# 最大连接数
|
||||
MaxOpenConn: 10
|
||||
# 最大空闲连接数
|
||||
MaxIdleConn: 5
|
||||
# Auth 配置
|
||||
Auth:
|
||||
# 访问密钥
|
||||
AccessSecret: uOvKLmVfztaXGpNYd4Z0I1SiT7MweJhl
|
||||
# 签名配置
|
||||
Signature:
|
||||
# 签名模式
|
||||
Strict: true
|
||||
# 签名过期时间
|
||||
Expiry: 1h
|
||||
# 签名私钥文件
|
||||
PrivateKeys:
|
||||
- Fingerprint: idm0jdoau38lwourb4pbjk4dxkat0kcx
|
||||
KeyFile: etc/rsa_private_key.pem
|
||||
# 加密配置
|
||||
Encrypt:
|
||||
# 密钥(32)
|
||||
Key: p3380puliiep184buh8d5dvujeerqtem
|
||||
# 向量 (16)
|
||||
IV: spb7er04k2vz3dtk
|
||||
# Redis 配置
|
||||
Redis:
|
||||
# Redis 地址
|
||||
Host: 1.95.0.111:6379
|
||||
# Redis 密码
|
||||
Pass: LDQ20020618xxx
|
||||
# Redis 数据库
|
||||
DB: 0
|
||||
# 微信配置
|
||||
Wechat:
|
||||
# 微信公众号APPID
|
||||
AppID: wx55251c2f83b9fc25
|
||||
# 微信公众号APPSECRET
|
||||
AppSecret: d511800cd53d248afe1260bb8aeed230
|
||||
# 微信公众号Token
|
||||
Token: LDQ20020618xxx
|
||||
# 微信公众号EncodingAESKey
|
||||
AESKey:
|
||||
# OAuth 配置
|
||||
OAuth:
|
||||
# Github配置
|
||||
Github:
|
||||
# Github客户端ID
|
||||
ClientID: Ov23limqLtbVhBngctSl
|
||||
# Github客户端密钥
|
||||
ClientSecret: 84a5be0317b8f4c6b55039a0eb23ea4606676e66
|
||||
# Github回调地址
|
||||
RedirectURI: https://landaiqing.cn/api/oauth/github/callback
|
||||
# Gitee配置
|
||||
Gitee:
|
||||
# Gitee客户端ID
|
||||
ClientID: bd2ff03b5f644242d862832b8cc749015d0a7c8f163fbd5ab67886d436fb198b
|
||||
# Gitee客户端密钥
|
||||
ClientSecret: 3994b463aa962c878a58a1255f59a92e050e205e9204cffe48a25ad17a758f97
|
||||
# Gitee回调地址
|
||||
RedirectURI: https://landaiqing.cn/api/oauth/gitee/callback
|
||||
# QQ配置
|
||||
QQ:
|
||||
# QQ客户端ID
|
||||
ClientID: '102296211'
|
||||
# QQ客户端密钥
|
||||
ClientSecret: ukOo10SggRxHVVIr
|
||||
# QQ回调地址
|
||||
RedirectURI: https://landaiqing.cn/api/oauth/qq/callback
|
||||
# 短信配置
|
||||
SMS:
|
||||
# 短信服务商配置
|
||||
Ali:
|
||||
# 阿里云API地址
|
||||
Host: http://dysmsapi.aliyuncs.com
|
||||
# 阿里云AccessKeyId
|
||||
AccessKeyId: LTAI5tDy2edL9LhW43rnus69
|
||||
# 阿里云AccessKeySecret
|
||||
AccessKeySecret: YWp44dcFrBICrjZgqvJBE7ZHArZfIP
|
||||
# 短信模板ID
|
||||
TemplateCode: SMS_154950909
|
||||
# 短信签名
|
||||
Signature: 阿里云短信测试
|
||||
# 短信宝配置
|
||||
SMSBao:
|
||||
# 短信宝用户账号
|
||||
Username: landaiqing
|
||||
# 短信宝用户密码
|
||||
Password: $LDQ20020618xxx$
|
14
app/auth/api/etc/rbac_model.conf
Normal file
14
app/auth/api/etc/rbac_model.conf
Normal file
@@ -0,0 +1,14 @@
|
||||
[request_definition]
|
||||
r = sub, obj, act
|
||||
|
||||
[policy_definition]
|
||||
p = sub, obj, act
|
||||
|
||||
[role_definition]
|
||||
g = _, _
|
||||
|
||||
[policy_effect]
|
||||
e = some(where (p.eft == allow)) && !some(where (p_eft == deny))
|
||||
|
||||
[matchers]
|
||||
m = g(r.sub, p.sub) && r.obj == p.obj && r.act == p.act
|
15
app/auth/api/etc/rsa_private_key.pem
Normal file
15
app/auth/api/etc/rsa_private_key.pem
Normal file
@@ -0,0 +1,15 @@
|
||||
-----BEGIN RSA PRIVATE KEY-----
|
||||
MIICXQIBAAKBgQCFe70Zi3OF7NuFi2saenJPjADWLn402d142LOLBeN6cuWpItE3
|
||||
qgFsaMSorQApSM0recmAHMg4M4ly7+NgFPsaTzteMrO/LFCagwLWyyFJeqV4oQWR
|
||||
NQcFcGev8sTkUbIhhKpNAcmg37q8cmfI2eumycfl2FXuSyoJOa7hJgYNNQIDAQAB
|
||||
AoGAebmhdE4LBzI77ch53yeSXqAZkzfKt3+Fy9IxyLGSA/QLIvYxPEW4Dphr3jYF
|
||||
U6CkGOVyr3WP0FCPI1VHUDNR2BP1oDUjw4X7EknUJxys+EamsFKyaJLlafDSGpu/
|
||||
Is6ReNV+76QzxfQjY1CuSpugLBxJmG0mNiQ1fHOFS4I/n/ECQQDTmDr9QR9IBNK+
|
||||
6QpCxNN1RODQAMiv0/25RCqJqMoi5sDum2gH/tmDbprQuI+DmDgdC32xWePTU3W6
|
||||
Y+rIMZjvAkEAoX8JDOQ82XTH7voUbHMOiGxMzDE7btBRNf/ILJFSlLCDfh91TLTS
|
||||
HwDLlYMs48FzhY9o5PkLo9cNlxoIGivUGwJAccsDpmFYXlXhtLQFRaUuh3mUYaia
|
||||
RRz/7ZvAOKoikySAC5JeHzaqaamY7rjizYWWX+BnJ3LNOEBBJw1HHYS21wJBAIpi
|
||||
bwDq+vFjzocLKEEd/pAMLWqzrTfxrgVVntQB2v+qmaKTllIaiAslBU6izu6DMFh8
|
||||
YOgEOGM2vmCCX/r9H40CQQC0YgVuVtEk1noqwqs8mEH7GJmA+KfzLPbt4Ekvi56m
|
||||
B9JJ5GAOo4lxmHD4h6GuQJPE6PD0a+tsTJ5n0IOGRj1g
|
||||
-----END RSA PRIVATE KEY-----
|
3
app/auth/api/generate.go
Normal file
3
app/auth/api/generate.go
Normal file
@@ -0,0 +1,3 @@
|
||||
package main
|
||||
|
||||
//go:generate goctl api go -api auth.api -dir . --style=go_zero
|
63
app/auth/api/internal/config/config.go
Normal file
63
app/auth/api/internal/config/config.go
Normal file
@@ -0,0 +1,63 @@
|
||||
package config
|
||||
|
||||
import "github.com/zeromicro/go-zero/rest"
|
||||
|
||||
type Config struct {
|
||||
rest.RestConf
|
||||
Web struct {
|
||||
URL string
|
||||
}
|
||||
Auth struct {
|
||||
AccessSecret string
|
||||
}
|
||||
Encrypt struct {
|
||||
Key string
|
||||
IV string
|
||||
}
|
||||
Mysql struct {
|
||||
DataSource string
|
||||
MaxOpenConn int
|
||||
MaxIdleConn int
|
||||
}
|
||||
Redis struct {
|
||||
Host string
|
||||
Pass string
|
||||
DB int
|
||||
}
|
||||
Wechat struct {
|
||||
AppID string
|
||||
AppSecret string
|
||||
Token string
|
||||
AESKey string
|
||||
}
|
||||
OAuth struct {
|
||||
Github struct {
|
||||
ClientID string
|
||||
ClientSecret string
|
||||
RedirectURI string
|
||||
}
|
||||
QQ struct {
|
||||
ClientID string
|
||||
ClientSecret string
|
||||
RedirectURI string
|
||||
}
|
||||
Gitee struct {
|
||||
ClientID string
|
||||
ClientSecret string
|
||||
RedirectURI string
|
||||
}
|
||||
}
|
||||
SMS struct {
|
||||
Ali struct {
|
||||
Host string
|
||||
AccessKeyId string
|
||||
AccessKeySecret string
|
||||
Signature string
|
||||
TemplateCode string
|
||||
}
|
||||
SMSBao struct {
|
||||
Username string
|
||||
Password string
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,21 @@
|
||||
package captcha
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/common/xhttp"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/logic/captcha"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
|
||||
)
|
||||
|
||||
func GenerateRotateCaptchaHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := captcha.NewGenerateRotateCaptchaLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GenerateRotateCaptcha()
|
||||
if err != nil {
|
||||
xhttp.JsonBaseResponseCtx(r.Context(), w, err)
|
||||
} else {
|
||||
xhttp.JsonBaseResponseCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,21 @@
|
||||
package captcha
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/common/xhttp"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/logic/captcha"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
|
||||
)
|
||||
|
||||
func GenerateSlideBasicCaptchaHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := captcha.NewGenerateSlideBasicCaptchaLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GenerateSlideBasicCaptcha()
|
||||
if err != nil {
|
||||
xhttp.JsonBaseResponseCtx(r.Context(), w, err)
|
||||
} else {
|
||||
xhttp.JsonBaseResponseCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,23 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/common/utils"
|
||||
"schisandra-album-cloud-microservices/common/xhttp"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/logic/client"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
|
||||
)
|
||||
|
||||
func GenerateClientIdHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
clientIP := utils.GetClientIP(r)
|
||||
l := client.NewGenerateClientIdLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GenerateClientId(clientIP)
|
||||
if err != nil {
|
||||
xhttp.JsonBaseResponseCtx(r.Context(), w, err)
|
||||
} else {
|
||||
xhttp.JsonBaseResponseCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,21 @@
|
||||
package oauth
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/common/xhttp"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/logic/oauth"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
|
||||
)
|
||||
|
||||
func GetGiteeOauthUrlHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := oauth.NewGetGiteeOauthUrlLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetGiteeOauthUrl()
|
||||
if err != nil {
|
||||
xhttp.JsonBaseResponseCtx(r.Context(), w, err)
|
||||
} else {
|
||||
xhttp.JsonBaseResponseCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
package oauth
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/common/xhttp"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/logic/oauth"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/types"
|
||||
)
|
||||
|
||||
func GetGithubOauthUrlHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.OAuthRequest
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := oauth.NewGetGithubOauthUrlLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetGithubOauthUrl(&req)
|
||||
if err != nil {
|
||||
xhttp.JsonBaseResponseCtx(r.Context(), w, err)
|
||||
} else {
|
||||
xhttp.JsonBaseResponseCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
package oauth
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/common/xhttp"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/logic/oauth"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/types"
|
||||
)
|
||||
|
||||
func GetQqOauthUrlHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.OAuthRequest
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := oauth.NewGetQqOauthUrlLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetQqOauthUrl(&req)
|
||||
if err != nil {
|
||||
xhttp.JsonBaseResponseCtx(r.Context(), w, err)
|
||||
} else {
|
||||
xhttp.JsonBaseResponseCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
package oauth
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/common/xhttp"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/logic/oauth"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/types"
|
||||
)
|
||||
|
||||
func GiteeCallbackHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.OAuthCallbackRequest
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
xhttp.JsonBaseResponseCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := oauth.NewGiteeCallbackLogic(r.Context(), svcCtx)
|
||||
data, err := l.GiteeCallback(r, &req)
|
||||
if err != nil {
|
||||
xhttp.JsonBaseResponseCtx(r.Context(), w, err)
|
||||
} else {
|
||||
xhttp.OkHTML(w, data)
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,28 @@
|
||||
package oauth
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/logic/oauth"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/types"
|
||||
"schisandra-album-cloud-microservices/common/xhttp"
|
||||
)
|
||||
|
||||
func GithubCallbackHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.OAuthCallbackRequest
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
xhttp.JsonBaseResponseCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := oauth.NewGithubCallbackLogic(r.Context(), svcCtx)
|
||||
data, err := l.GithubCallback(r, &req)
|
||||
if err != nil {
|
||||
xhttp.JsonBaseResponseCtx(r.Context(), w, err)
|
||||
} else {
|
||||
xhttp.OkHTML(w, data)
|
||||
}
|
||||
}
|
||||
}
|
28
app/auth/api/internal/handler/oauth/qq_callback_handler.go
Normal file
28
app/auth/api/internal/handler/oauth/qq_callback_handler.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package oauth
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/logic/oauth"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/types"
|
||||
"schisandra-album-cloud-microservices/common/xhttp"
|
||||
)
|
||||
|
||||
func QqCallbackHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.OAuthCallbackRequest
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
xhttp.JsonBaseResponseCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := oauth.NewQqCallbackLogic(r.Context(), svcCtx)
|
||||
data, err := l.QqCallback(r, &req)
|
||||
if err != nil {
|
||||
xhttp.JsonBaseResponseCtx(r.Context(), w, err)
|
||||
} else {
|
||||
xhttp.OkHTML(w, data)
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,21 @@
|
||||
package oauth
|
||||
|
||||
import (
|
||||
"github.com/ArtisanCloud/PowerLibs/v3/http/helper"
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/logic/oauth"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/common/xhttp"
|
||||
)
|
||||
|
||||
func WechatOffiaccountCallbackHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := oauth.NewWechatOffiaccountCallbackLogic(r.Context(), svcCtx)
|
||||
res, err := l.WechatOffiaccountCallback(r)
|
||||
if err != nil {
|
||||
xhttp.JsonBaseResponseCtx(r.Context(), w, err)
|
||||
} else {
|
||||
_ = helper.HttpResponseSend(res, w)
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,21 @@
|
||||
package oauth
|
||||
|
||||
import (
|
||||
"github.com/ArtisanCloud/PowerLibs/v3/http/helper"
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/logic/oauth"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/common/xhttp"
|
||||
)
|
||||
|
||||
func WechatOffiaccountCallbackVerifyHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := oauth.NewWechatOffiaccountCallbackVerifyLogic(r.Context(), svcCtx)
|
||||
res, err := l.WechatOffiaccountCallbackVerify(r)
|
||||
if err != nil {
|
||||
xhttp.JsonBaseResponseCtx(r.Context(), w, err)
|
||||
} else {
|
||||
_ = helper.HttpResponseSend(res, w)
|
||||
}
|
||||
}
|
||||
}
|
206
app/auth/api/internal/handler/routes.go
Normal file
206
app/auth/api/internal/handler/routes.go
Normal file
@@ -0,0 +1,206 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// goctl 1.7.3
|
||||
|
||||
package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
captcha "schisandra-album-cloud-microservices/app/auth/api/internal/handler/captcha"
|
||||
client "schisandra-album-cloud-microservices/app/auth/api/internal/handler/client"
|
||||
oauth "schisandra-album-cloud-microservices/app/auth/api/internal/handler/oauth"
|
||||
sms "schisandra-album-cloud-microservices/app/auth/api/internal/handler/sms"
|
||||
token "schisandra-album-cloud-microservices/app/auth/api/internal/handler/token"
|
||||
user "schisandra-album-cloud-microservices/app/auth/api/internal/handler/user"
|
||||
websocket "schisandra-album-cloud-microservices/app/auth/api/internal/handler/websocket"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest"
|
||||
)
|
||||
|
||||
func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
server.AddRoutes(
|
||||
rest.WithMiddlewares(
|
||||
[]rest.Middleware{serverCtx.SecurityHeadersMiddleware, serverCtx.NonceMiddleware},
|
||||
[]rest.Route{
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/rotate/generate",
|
||||
Handler: captcha.GenerateRotateCaptchaHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/slide/generate",
|
||||
Handler: captcha.GenerateSlideBasicCaptchaHandler(serverCtx),
|
||||
},
|
||||
}...,
|
||||
),
|
||||
rest.WithPrefix("/api/captcha"),
|
||||
rest.WithTimeout(10000*time.Millisecond),
|
||||
rest.WithMaxBytes(1048576),
|
||||
)
|
||||
|
||||
server.AddRoutes(
|
||||
rest.WithMiddlewares(
|
||||
[]rest.Middleware{serverCtx.SecurityHeadersMiddleware, serverCtx.NonceMiddleware},
|
||||
[]rest.Route{
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/generate",
|
||||
Handler: client.GenerateClientIdHandler(serverCtx),
|
||||
},
|
||||
}...,
|
||||
),
|
||||
rest.WithPrefix("/api/client"),
|
||||
rest.WithTimeout(10000*time.Millisecond),
|
||||
rest.WithMaxBytes(1048576),
|
||||
)
|
||||
|
||||
server.AddRoutes(
|
||||
rest.WithMiddlewares(
|
||||
[]rest.Middleware{serverCtx.SecurityHeadersMiddleware},
|
||||
[]rest.Route{
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/gitee/callback",
|
||||
Handler: oauth.GiteeCallbackHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/gitee/url",
|
||||
Handler: oauth.GetGiteeOauthUrlHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/github/callback",
|
||||
Handler: oauth.GithubCallbackHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/github/url",
|
||||
Handler: oauth.GetGithubOauthUrlHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/qq/callback",
|
||||
Handler: oauth.QqCallbackHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/qq/url",
|
||||
Handler: oauth.GetQqOauthUrlHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/wechat/offiaccount/callback",
|
||||
Handler: oauth.WechatOffiaccountCallbackHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/wechat/offiaccount/callback",
|
||||
Handler: oauth.WechatOffiaccountCallbackVerifyHandler(serverCtx),
|
||||
},
|
||||
}...,
|
||||
),
|
||||
rest.WithPrefix("/api/oauth"),
|
||||
rest.WithTimeout(10000*time.Millisecond),
|
||||
rest.WithMaxBytes(1048576),
|
||||
)
|
||||
|
||||
server.AddRoutes(
|
||||
rest.WithMiddlewares(
|
||||
[]rest.Middleware{serverCtx.SecurityHeadersMiddleware, serverCtx.NonceMiddleware},
|
||||
[]rest.Route{
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/ali/send",
|
||||
Handler: sms.SendSmsByAliyunHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/smsbao/send",
|
||||
Handler: sms.SendSmsBySmsbaoHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/test/send",
|
||||
Handler: sms.SendSmsByTestHandler(serverCtx),
|
||||
},
|
||||
}...,
|
||||
),
|
||||
rest.WithPrefix("/api/sms"),
|
||||
rest.WithTimeout(10000*time.Millisecond),
|
||||
rest.WithMaxBytes(1048576),
|
||||
)
|
||||
|
||||
server.AddRoutes(
|
||||
rest.WithMiddlewares(
|
||||
[]rest.Middleware{serverCtx.SecurityHeadersMiddleware, serverCtx.CasbinVerifyMiddleware, serverCtx.NonceMiddleware},
|
||||
[]rest.Route{
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/token/refresh",
|
||||
Handler: token.RefreshTokenHandler(serverCtx),
|
||||
},
|
||||
}...,
|
||||
),
|
||||
rest.WithSignature(serverCtx.Config.Signature),
|
||||
rest.WithPrefix("/api/auth"),
|
||||
rest.WithTimeout(10000*time.Millisecond),
|
||||
rest.WithMaxBytes(1048576),
|
||||
)
|
||||
|
||||
server.AddRoutes(
|
||||
rest.WithMiddlewares(
|
||||
[]rest.Middleware{serverCtx.SecurityHeadersMiddleware, serverCtx.NonceMiddleware},
|
||||
[]rest.Route{
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/login",
|
||||
Handler: user.AccountLoginHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/phone/login",
|
||||
Handler: user.PhoneLoginHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/reset/password",
|
||||
Handler: user.ResetPasswordHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/wechat/offiaccount/login",
|
||||
Handler: user.WechatOffiaccountLoginHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/wechat/offiaccount/qrcode",
|
||||
Handler: user.GetWechatOffiaccountQrcodeHandler(serverCtx),
|
||||
},
|
||||
}...,
|
||||
),
|
||||
rest.WithSignature(serverCtx.Config.Signature),
|
||||
rest.WithPrefix("/api/user"),
|
||||
rest.WithTimeout(10000*time.Millisecond),
|
||||
rest.WithMaxBytes(1048576),
|
||||
)
|
||||
|
||||
server.AddRoutes(
|
||||
[]rest.Route{
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/message",
|
||||
Handler: websocket.MessageWebsocketHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/qrcode",
|
||||
Handler: websocket.QrcodeWebsocketHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
rest.WithPrefix("/api/ws"),
|
||||
)
|
||||
}
|
@@ -0,0 +1,25 @@
|
||||
package sms
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/common/xhttp"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/logic/sms"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/types"
|
||||
)
|
||||
|
||||
func SendSmsByAliyunHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.SmsSendRequest
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
xhttp.JsonBaseResponseCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := sms.NewSendSmsByAliyunLogic(r.Context(), svcCtx)
|
||||
err := l.SendSmsByAliyun(&req)
|
||||
xhttp.JsonBaseResponseCtx(r.Context(), w, err)
|
||||
}
|
||||
}
|
@@ -0,0 +1,25 @@
|
||||
package sms
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/common/xhttp"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/logic/sms"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/types"
|
||||
)
|
||||
|
||||
func SendSmsBySmsbaoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.SmsSendRequest
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
xhttp.JsonBaseResponseCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
l := sms.NewSendSmsBySmsbaoLogic(r.Context(), svcCtx)
|
||||
err := l.SendSmsBySmsbao(&req)
|
||||
|
||||
xhttp.JsonBaseResponseCtx(r.Context(), w, err)
|
||||
}
|
||||
}
|
@@ -0,0 +1,25 @@
|
||||
package sms
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/common/xhttp"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/logic/sms"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/types"
|
||||
)
|
||||
|
||||
func SendSmsByTestHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.SmsSendRequest
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
xhttp.JsonBaseResponseCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := sms.NewSendSmsByTestLogic(r.Context(), svcCtx)
|
||||
err := l.SendSmsByTest(&req)
|
||||
xhttp.JsonBaseResponseCtx(r.Context(), w, err)
|
||||
}
|
||||
}
|
21
app/auth/api/internal/handler/token/refresh_token_handler.go
Normal file
21
app/auth/api/internal/handler/token/refresh_token_handler.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package token
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/common/xhttp"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/logic/token"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
|
||||
)
|
||||
|
||||
func RefreshTokenHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := token.NewRefreshTokenLogic(r.Context(), svcCtx)
|
||||
resp, err := l.RefreshToken(r)
|
||||
if err != nil {
|
||||
xhttp.JsonBaseResponseCtx(r.Context(), w, err)
|
||||
} else {
|
||||
xhttp.JsonBaseResponseCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
29
app/auth/api/internal/handler/user/account_login_handler.go
Normal file
29
app/auth/api/internal/handler/user/account_login_handler.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/common/xhttp"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/logic/user"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/types"
|
||||
)
|
||||
|
||||
func AccountLoginHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.AccountLoginRequest
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
xhttp.JsonBaseResponseCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := user.NewAccountLoginLogic(r.Context(), svcCtx)
|
||||
resp, err := l.AccountLogin(r, &req)
|
||||
if err != nil {
|
||||
xhttp.JsonBaseResponseCtx(r.Context(), w, err)
|
||||
} else {
|
||||
xhttp.JsonBaseResponseCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,28 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/logic/user"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/types"
|
||||
"schisandra-album-cloud-microservices/common/xhttp"
|
||||
)
|
||||
|
||||
func GetWechatOffiaccountQrcodeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.OAuthWechatRequest
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
xhttp.JsonBaseResponseCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := user.NewGetWechatOffiaccountQrcodeLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetWechatOffiaccountQrcode(r, &req)
|
||||
if err != nil {
|
||||
xhttp.JsonBaseResponseCtx(r.Context(), w, err)
|
||||
} else {
|
||||
xhttp.JsonBaseResponseCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
29
app/auth/api/internal/handler/user/phone_login_handler.go
Normal file
29
app/auth/api/internal/handler/user/phone_login_handler.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/common/xhttp"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/logic/user"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/types"
|
||||
)
|
||||
|
||||
func PhoneLoginHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.PhoneLoginRequest
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
xhttp.JsonBaseResponseCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := user.NewPhoneLoginLogic(r.Context(), svcCtx)
|
||||
resp, err := l.PhoneLogin(r, &req)
|
||||
if err != nil {
|
||||
xhttp.JsonBaseResponseCtx(r.Context(), w, err)
|
||||
} else {
|
||||
xhttp.JsonBaseResponseCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
24
app/auth/api/internal/handler/user/reset_password_handler.go
Normal file
24
app/auth/api/internal/handler/user/reset_password_handler.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/common/xhttp"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/logic/user"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/types"
|
||||
)
|
||||
|
||||
func ResetPasswordHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.ResetPasswordRequest
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
xhttp.JsonBaseResponseCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
l := user.NewResetPasswordLogic(r.Context(), svcCtx)
|
||||
err := l.ResetPassword(&req)
|
||||
xhttp.JsonBaseResponseCtx(r.Context(), w, err)
|
||||
}
|
||||
}
|
@@ -0,0 +1,28 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/logic/user"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/types"
|
||||
"schisandra-album-cloud-microservices/common/xhttp"
|
||||
)
|
||||
|
||||
func WechatOffiaccountLoginHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.WechatOffiaccountLoginRequest
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
xhttp.JsonBaseResponseCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := user.NewWechatOffiaccountLoginLogic(r.Context(), svcCtx)
|
||||
resp, err := l.WechatOffiaccountLogin(r, &req)
|
||||
if err != nil {
|
||||
xhttp.JsonBaseResponseCtx(r.Context(), w, err)
|
||||
} else {
|
||||
xhttp.JsonBaseResponseCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,15 @@
|
||||
package websocket
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/logic/websocket"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
|
||||
)
|
||||
|
||||
func MessageWebsocketHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := websocket.NewMessageWebsocketLogic(r.Context(), svcCtx)
|
||||
l.MessageWebsocket(w, r)
|
||||
}
|
||||
}
|
@@ -0,0 +1,15 @@
|
||||
package websocket
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/logic/websocket"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
|
||||
)
|
||||
|
||||
func QrcodeWebsocketHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := websocket.NewQrcodeWebsocketLogic(r.Context(), svcCtx)
|
||||
l.QrcodeWebsocket(w, r)
|
||||
}
|
||||
}
|
@@ -0,0 +1,33 @@
|
||||
package captcha
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/common/captcha/generate"
|
||||
"schisandra-album-cloud-microservices/common/errors"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GenerateRotateCaptchaLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGenerateRotateCaptchaLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GenerateRotateCaptchaLogic {
|
||||
return &GenerateRotateCaptchaLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GenerateRotateCaptchaLogic) GenerateRotateCaptcha() (resp map[string]interface{}, err error) {
|
||||
captcha, err := generate.GenerateRotateCaptcha(l.svcCtx.RotateCaptcha, l.svcCtx.RedisClient, l.ctx)
|
||||
if err != nil {
|
||||
return nil, errors.New(http.StatusInternalServerError, err.Error())
|
||||
}
|
||||
return captcha, nil
|
||||
}
|
@@ -0,0 +1,33 @@
|
||||
package captcha
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/common/captcha/generate"
|
||||
"schisandra-album-cloud-microservices/common/errors"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GenerateSlideBasicCaptchaLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGenerateSlideBasicCaptchaLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GenerateSlideBasicCaptchaLogic {
|
||||
return &GenerateSlideBasicCaptchaLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GenerateSlideBasicCaptchaLogic) GenerateSlideBasicCaptcha() (resp map[string]interface{}, err error) {
|
||||
captcha, err := generate.GenerateSlideBasicCaptcha(l.svcCtx.SlideCaptcha, l.svcCtx.RedisClient, l.ctx)
|
||||
if err != nil {
|
||||
return nil, errors.New(http.StatusInternalServerError, err.Error())
|
||||
}
|
||||
return captcha, nil
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/common/constant"
|
||||
"schisandra-album-cloud-microservices/common/errors"
|
||||
"time"
|
||||
|
||||
"github.com/ccpwcn/kgo"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
|
||||
)
|
||||
|
||||
type GenerateClientIdLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGenerateClientIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GenerateClientIdLogic {
|
||||
return &GenerateClientIdLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GenerateClientIdLogic) GenerateClientId(clientIP string) (resp string, err error) {
|
||||
clientId := l.svcCtx.RedisClient.Get(l.ctx, constant.UserClientPrefix+clientIP).Val()
|
||||
|
||||
if clientId != "" {
|
||||
return clientId, nil
|
||||
}
|
||||
simpleUuid := kgo.SimpleUuid()
|
||||
if err = l.svcCtx.RedisClient.SetEx(l.ctx, constant.UserClientPrefix+clientIP, simpleUuid, time.Hour*24*7).Err(); err != nil {
|
||||
return "", errors.New(http.StatusInternalServerError, err.Error())
|
||||
}
|
||||
return simpleUuid, nil
|
||||
}
|
@@ -0,0 +1,28 @@
|
||||
package oauth
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
|
||||
)
|
||||
|
||||
type GetGiteeOauthUrlLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGetGiteeOauthUrlLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetGiteeOauthUrlLogic {
|
||||
return &GetGiteeOauthUrlLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetGiteeOauthUrlLogic) GetGiteeOauthUrl() (resp string, err error) {
|
||||
clientID := l.svcCtx.Config.OAuth.Gitee.ClientID
|
||||
redirectURI := l.svcCtx.Config.OAuth.Gitee.RedirectURI
|
||||
url := "https://gitee.com/oauth/authorize?client_id=" + clientID + "&redirect_uri=" + redirectURI + "&response_type=code"
|
||||
return url, nil
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
package oauth
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/types"
|
||||
)
|
||||
|
||||
type GetGithubOauthUrlLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGetGithubOauthUrlLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetGithubOauthUrlLogic {
|
||||
return &GetGithubOauthUrlLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetGithubOauthUrlLogic) GetGithubOauthUrl(req *types.OAuthRequest) (resp string, err error) {
|
||||
clientId := l.svcCtx.Config.OAuth.Github.ClientID
|
||||
redirectUrl := l.svcCtx.Config.OAuth.Github.RedirectURI
|
||||
url := "https://github.com/login/oauth/authorize?client_id=" + clientId + "&redirect_uri=" + redirectUrl + "&state=" + req.State
|
||||
return url, nil
|
||||
}
|
29
app/auth/api/internal/logic/oauth/get_qq_oauth_url_logic.go
Normal file
29
app/auth/api/internal/logic/oauth/get_qq_oauth_url_logic.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package oauth
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/types"
|
||||
)
|
||||
|
||||
type GetQqOauthUrlLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGetQqOauthUrlLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetQqOauthUrlLogic {
|
||||
return &GetQqOauthUrlLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetQqOauthUrlLogic) GetQqOauthUrl(req *types.OAuthRequest) (resp string, err error) {
|
||||
clientId := l.svcCtx.Config.OAuth.QQ.ClientID
|
||||
redirectURI := l.svcCtx.Config.OAuth.QQ.RedirectURI
|
||||
url := "https://graph.qq.com/oauth2.0/authorize?response_type=code&client_id=" + clientId + "&redirect_uri=" + redirectURI + "&state=" + req.State
|
||||
return url, nil
|
||||
}
|
262
app/auth/api/internal/logic/oauth/gitee_callback_logic.go
Normal file
262
app/auth/api/internal/logic/oauth/gitee_callback_logic.go
Normal file
@@ -0,0 +1,262 @@
|
||||
package oauth
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/model/mysql/model"
|
||||
"schisandra-album-cloud-microservices/common/constant"
|
||||
"schisandra-album-cloud-microservices/common/xhttp"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/yitter/idgenerator-go/idgen"
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/logic/user"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/types"
|
||||
)
|
||||
|
||||
type GiteeCallbackLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
type GiteeUser struct {
|
||||
AvatarURL string `json:"avatar_url"`
|
||||
Bio string `json:"bio"`
|
||||
Blog string `json:"blog"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
Email string `json:"email"`
|
||||
EventsURL string `json:"events_url"`
|
||||
Followers int `json:"followers"`
|
||||
FollowersURL string `json:"followers_url"`
|
||||
Following int `json:"following"`
|
||||
FollowingURL string `json:"following_url"`
|
||||
GistsURL string `json:"gists_url"`
|
||||
HTMLURL string `json:"html_url"`
|
||||
ID int `json:"id"`
|
||||
Login string `json:"login"`
|
||||
Name string `json:"name"`
|
||||
OrganizationsURL string `json:"organizations_url"`
|
||||
PublicGists int `json:"public_gists"`
|
||||
PublicRepos int `json:"public_repos"`
|
||||
ReceivedEventsURL string `json:"received_events_url"`
|
||||
Remark string `json:"remark"`
|
||||
ReposURL string `json:"repos_url"`
|
||||
Stared int `json:"stared"`
|
||||
StarredURL string `json:"starred_url"`
|
||||
SubscriptionsURL string `json:"subscriptions_url"`
|
||||
Type string `json:"type"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
URL string `json:"url"`
|
||||
Watched int `json:"watched"`
|
||||
Weibo interface{} `json:"weibo"`
|
||||
}
|
||||
type Token struct {
|
||||
AccessToken string `json:"access_token"`
|
||||
}
|
||||
|
||||
var Script = `
|
||||
<script>
|
||||
window.opener.postMessage('%s', '%s');
|
||||
window.close();
|
||||
</script>
|
||||
`
|
||||
|
||||
func NewGiteeCallbackLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GiteeCallbackLogic {
|
||||
return &GiteeCallbackLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GiteeCallbackLogic) GiteeCallback(r *http.Request, req *types.OAuthCallbackRequest) (string, error) {
|
||||
// 获取 token
|
||||
tokenAuthUrl := l.GetGiteeTokenAuthUrl(req.Code)
|
||||
token, err := l.GetGiteeToken(tokenAuthUrl)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if token == nil {
|
||||
return "", errors.New("get gitee token failed")
|
||||
}
|
||||
|
||||
// 获取用户信息
|
||||
userInfo, err := l.GetGiteeUserInfo(token)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if userInfo == nil {
|
||||
return "", errors.New("get gitee user info failed")
|
||||
}
|
||||
|
||||
var giteeUser GiteeUser
|
||||
marshal, err := json.Marshal(userInfo)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if err = json.Unmarshal(marshal, &giteeUser); err != nil {
|
||||
return "", err
|
||||
}
|
||||
Id := strconv.Itoa(giteeUser.ID)
|
||||
|
||||
tx := l.svcCtx.DB.Begin()
|
||||
|
||||
userSocial := l.svcCtx.DB.ScaAuthUserSocial
|
||||
socialUser, err := tx.ScaAuthUserSocial.Where(userSocial.OpenID.Eq(Id), userSocial.Source.Eq(constant.OAuthSourceGitee)).First()
|
||||
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if socialUser == nil {
|
||||
// 创建用户
|
||||
uid := idgen.NextId()
|
||||
uidStr := strconv.FormatInt(uid, 10)
|
||||
addUser := &model.ScaAuthUser{
|
||||
UID: uidStr,
|
||||
Avatar: giteeUser.AvatarURL,
|
||||
Username: giteeUser.Login,
|
||||
Nickname: giteeUser.Name,
|
||||
Blog: giteeUser.Blog,
|
||||
Email: giteeUser.Email,
|
||||
Gender: constant.Male,
|
||||
}
|
||||
err = tx.ScaAuthUser.Create(addUser)
|
||||
if err != nil {
|
||||
_ = tx.Rollback()
|
||||
return "", err
|
||||
}
|
||||
gitee := constant.OAuthSourceGitee
|
||||
newSocialUser := &model.ScaAuthUserSocial{
|
||||
UserID: uidStr,
|
||||
OpenID: Id,
|
||||
Source: gitee,
|
||||
}
|
||||
err = tx.ScaAuthUserSocial.Create(newSocialUser)
|
||||
if err != nil {
|
||||
_ = tx.Rollback()
|
||||
return "", err
|
||||
}
|
||||
|
||||
if res, err := l.svcCtx.CasbinEnforcer.AddRoleForUser(uidStr, constant.User); !res || err != nil {
|
||||
_ = tx.Rollback()
|
||||
return "", err
|
||||
}
|
||||
data, err := HandleOauthLoginResponse(addUser, l.svcCtx, r, l.ctx)
|
||||
if err != nil {
|
||||
_ = tx.Rollback()
|
||||
return "", err
|
||||
}
|
||||
if err = tx.Commit(); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return data, nil
|
||||
} else {
|
||||
authUser := l.svcCtx.DB.ScaAuthUser
|
||||
|
||||
authUserInfo, err := tx.ScaAuthUser.Where(authUser.UID.Eq(socialUser.UserID)).First()
|
||||
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
_ = tx.Rollback()
|
||||
return "", err
|
||||
}
|
||||
|
||||
data, err := HandleOauthLoginResponse(authUserInfo, l.svcCtx, r, l.ctx)
|
||||
if err != nil {
|
||||
_ = tx.Rollback()
|
||||
return "", err
|
||||
}
|
||||
if err = tx.Commit(); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
}
|
||||
|
||||
// HandleOauthLoginResponse 处理登录响应
|
||||
func HandleOauthLoginResponse(scaAuthUser *model.ScaAuthUser, svcCtx *svc.ServiceContext, r *http.Request, ctx context.Context) (string, error) {
|
||||
data, err := user.HandleLoginJWT(scaAuthUser, svcCtx, true, r, ctx)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
marshalData, err := json.Marshal(xhttp.BaseResponse[*types.LoginResponse]{
|
||||
Data: data,
|
||||
Code: 200,
|
||||
Msg: "success",
|
||||
})
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
formattedScript := fmt.Sprintf(Script, marshalData, svcCtx.Config.Web.URL)
|
||||
return formattedScript, nil
|
||||
}
|
||||
|
||||
// GetGiteeTokenAuthUrl 获取Gitee token
|
||||
func (l *GiteeCallbackLogic) GetGiteeTokenAuthUrl(code string) string {
|
||||
clientId := l.svcCtx.Config.OAuth.Gitee.ClientID
|
||||
clientSecret := l.svcCtx.Config.OAuth.Gitee.ClientSecret
|
||||
redirectURI := l.svcCtx.Config.OAuth.Gitee.RedirectURI
|
||||
return fmt.Sprintf(
|
||||
"https://gitee.com/oauth/token?grant_type=authorization_code&code=%s&client_id=%s&redirect_uri=%s&client_secret=%s",
|
||||
code, clientId, redirectURI, clientSecret,
|
||||
)
|
||||
}
|
||||
|
||||
// GetGiteeToken 获取 token
|
||||
func (l *GiteeCallbackLogic) GetGiteeToken(url string) (*Token, error) {
|
||||
|
||||
// 形成请求
|
||||
var req *http.Request
|
||||
var err error
|
||||
if req, err = http.NewRequest(http.MethodPost, url, nil); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req.Header.Set("accept", "application/json")
|
||||
|
||||
// 发送请求并获得响应
|
||||
var httpClient = http.Client{}
|
||||
var res *http.Response
|
||||
if res, err = httpClient.Do(req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 将响应体解析为 token,并返回
|
||||
var token Token
|
||||
if err = json.NewDecoder(res.Body).Decode(&token); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &token, nil
|
||||
}
|
||||
|
||||
// GetGiteeUserInfo 获取用户信息
|
||||
func (l *GiteeCallbackLogic) GetGiteeUserInfo(token *Token) (map[string]interface{}, error) {
|
||||
|
||||
// 形成请求
|
||||
var userInfoUrl = "https://gitee.com/api/v5/user" // github用户信息获取接口
|
||||
var req *http.Request
|
||||
var err error
|
||||
if req, err = http.NewRequest(http.MethodGet, userInfoUrl, nil); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req.Header.Set("accept", "application/json")
|
||||
req.Header.Set("Authorization", fmt.Sprintf("token %s", token.AccessToken))
|
||||
// 发送请求并获取响应
|
||||
var client = http.Client{}
|
||||
var res *http.Response
|
||||
if res, err = client.Do(req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 将响应的数据写入 userInfo 中,并返回
|
||||
var userInfo = make(map[string]interface{})
|
||||
if err = json.NewDecoder(res.Body).Decode(&userInfo); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return userInfo, nil
|
||||
}
|
244
app/auth/api/internal/logic/oauth/github_callback_logic.go
Normal file
244
app/auth/api/internal/logic/oauth/github_callback_logic.go
Normal file
@@ -0,0 +1,244 @@
|
||||
package oauth
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/model/mysql/model"
|
||||
"schisandra-album-cloud-microservices/common/constant"
|
||||
"strconv"
|
||||
|
||||
"github.com/yitter/idgenerator-go/idgen"
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/types"
|
||||
)
|
||||
|
||||
type GithubCallbackLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
type GitHubUser struct {
|
||||
AvatarURL string `json:"avatar_url"`
|
||||
Bio interface{} `json:"bio"`
|
||||
Blog string `json:"blog"`
|
||||
Company interface{} `json:"company"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
Email string `json:"email"`
|
||||
EventsURL string `json:"events_url"`
|
||||
Followers int `json:"followers"`
|
||||
FollowersURL string `json:"followers_url"`
|
||||
Following int `json:"following"`
|
||||
FollowingURL string `json:"following_url"`
|
||||
GistsURL string `json:"gists_url"`
|
||||
GravatarID string `json:"gravatar_id"`
|
||||
Hireable interface{} `json:"hireable"`
|
||||
HTMLURL string `json:"html_url"`
|
||||
ID int `json:"id"`
|
||||
Location interface{} `json:"location"`
|
||||
Login string `json:"login"`
|
||||
Name string `json:"name"`
|
||||
NodeID string `json:"node_id"`
|
||||
NotificationEmail interface{} `json:"notification_email"`
|
||||
OrganizationsURL string `json:"organizations_url"`
|
||||
PublicGists int `json:"public_gists"`
|
||||
PublicRepos int `json:"public_repos"`
|
||||
ReceivedEventsURL string `json:"received_events_url"`
|
||||
ReposURL string `json:"repos_url"`
|
||||
SiteAdmin bool `json:"site_admin"`
|
||||
StarredURL string `json:"starred_url"`
|
||||
SubscriptionsURL string `json:"subscriptions_url"`
|
||||
TwitterUsername interface{} `json:"twitter_username"`
|
||||
Type string `json:"type"`
|
||||
UpdatedAt string `json:"updated_at"`
|
||||
URL string `json:"url"`
|
||||
}
|
||||
|
||||
func NewGithubCallbackLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GithubCallbackLogic {
|
||||
return &GithubCallbackLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GithubCallbackLogic) GithubCallback(r *http.Request, req *types.OAuthCallbackRequest) (string, error) {
|
||||
|
||||
// 获取 token
|
||||
tokenAuthUrl := l.GetTokenAuthUrl(req.Code)
|
||||
token, err := l.GetToken(tokenAuthUrl)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if token == nil {
|
||||
|
||||
return "", errors.New("get github token failed")
|
||||
}
|
||||
|
||||
// 获取用户信息
|
||||
userInfo, err := l.GetUserInfo(token)
|
||||
if err != nil {
|
||||
|
||||
return "", err
|
||||
}
|
||||
|
||||
if userInfo == nil {
|
||||
return "", errors.New("get github user info failed")
|
||||
}
|
||||
|
||||
// 处理用户信息
|
||||
userInfoBytes, err := json.Marshal(userInfo)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
var gitHubUser GitHubUser
|
||||
err = json.Unmarshal(userInfoBytes, &gitHubUser)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
Id := strconv.Itoa(gitHubUser.ID)
|
||||
tx := l.svcCtx.DB.Begin()
|
||||
|
||||
userSocial := l.svcCtx.DB.ScaAuthUserSocial
|
||||
socialUser, err := tx.ScaAuthUserSocial.Where(userSocial.OpenID.Eq(Id), userSocial.Source.Eq(constant.OAuthSourceGithub)).First()
|
||||
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if socialUser == nil {
|
||||
// 创建用户
|
||||
uid := idgen.NextId()
|
||||
uidStr := strconv.FormatInt(uid, 10)
|
||||
|
||||
male := constant.Male
|
||||
addUser := &model.ScaAuthUser{
|
||||
UID: uidStr,
|
||||
Avatar: gitHubUser.AvatarURL,
|
||||
Username: gitHubUser.Login,
|
||||
Nickname: gitHubUser.Name,
|
||||
Blog: gitHubUser.Blog,
|
||||
Email: gitHubUser.Email,
|
||||
|
||||
Gender: male,
|
||||
}
|
||||
err = tx.ScaAuthUser.Create(addUser)
|
||||
if err != nil {
|
||||
_ = tx.Rollback()
|
||||
return "", err
|
||||
}
|
||||
githubUser := constant.OAuthSourceGithub
|
||||
newSocialUser := &model.ScaAuthUserSocial{
|
||||
UserID: uidStr,
|
||||
OpenID: Id,
|
||||
Source: githubUser,
|
||||
}
|
||||
err = tx.ScaAuthUserSocial.Create(newSocialUser)
|
||||
if err != nil {
|
||||
_ = tx.Rollback()
|
||||
return "", err
|
||||
}
|
||||
|
||||
if res, err := l.svcCtx.CasbinEnforcer.AddRoleForUser(uidStr, constant.User); !res || err != nil {
|
||||
_ = tx.Rollback()
|
||||
return "", err
|
||||
}
|
||||
|
||||
data, err := HandleOauthLoginResponse(addUser, l.svcCtx, r, l.ctx)
|
||||
if err != nil {
|
||||
_ = tx.Rollback()
|
||||
return "", err
|
||||
}
|
||||
if err = tx.Commit(); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return data, nil
|
||||
} else {
|
||||
authUser := l.svcCtx.DB.ScaAuthUser
|
||||
|
||||
authUserInfo, err := tx.ScaAuthUser.Where(authUser.UID.Eq(socialUser.UserID)).First()
|
||||
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
_ = tx.Rollback()
|
||||
return "", err
|
||||
}
|
||||
|
||||
data, err := HandleOauthLoginResponse(authUserInfo, l.svcCtx, r, l.ctx)
|
||||
if err != nil {
|
||||
_ = tx.Rollback()
|
||||
return "", err
|
||||
}
|
||||
if err = tx.Commit(); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
}
|
||||
|
||||
// GetTokenAuthUrl 通过code获取token认证url
|
||||
func (l *GithubCallbackLogic) GetTokenAuthUrl(code string) string {
|
||||
clientId := l.svcCtx.Config.OAuth.Github.ClientID
|
||||
clientSecret := l.svcCtx.Config.OAuth.Github.ClientSecret
|
||||
return fmt.Sprintf(
|
||||
"https://github.com/login/oauth/access_token?client_id=%s&client_secret=%s&code=%s",
|
||||
clientId, clientSecret, code,
|
||||
)
|
||||
}
|
||||
|
||||
// GetToken 获取 token
|
||||
func (l *GithubCallbackLogic) GetToken(url string) (*Token, error) {
|
||||
|
||||
// 形成请求
|
||||
var req *http.Request
|
||||
var err error
|
||||
if req, err = http.NewRequest(http.MethodGet, url, nil); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req.Header.Set("accept", "application/json")
|
||||
|
||||
// 发送请求并获得响应
|
||||
var httpClient = http.Client{}
|
||||
var res *http.Response
|
||||
if res, err = httpClient.Do(req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 将响应体解析为 token,并返回
|
||||
var token Token
|
||||
if err = json.NewDecoder(res.Body).Decode(&token); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &token, nil
|
||||
}
|
||||
|
||||
// GetUserInfo 获取用户信息
|
||||
func (l *GithubCallbackLogic) GetUserInfo(token *Token) (map[string]interface{}, error) {
|
||||
|
||||
// 形成请求
|
||||
var userInfoUrl = "https://api.github.com/user" // github用户信息获取接口
|
||||
var req *http.Request
|
||||
var err error
|
||||
if req, err = http.NewRequest(http.MethodGet, userInfoUrl, nil); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req.Header.Set("accept", "application/json")
|
||||
req.Header.Set("Authorization", fmt.Sprintf("token %s", token.AccessToken))
|
||||
|
||||
// 发送请求并获取响应
|
||||
var client = http.Client{}
|
||||
var res *http.Response
|
||||
if res, err = client.Do(req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 将响应的数据写入 userInfo 中,并返回
|
||||
var userInfo = make(map[string]interface{})
|
||||
if err = json.NewDecoder(res.Body).Decode(&userInfo); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return userInfo, nil
|
||||
}
|
266
app/auth/api/internal/logic/oauth/qq_callback_logic.go
Normal file
266
app/auth/api/internal/logic/oauth/qq_callback_logic.go
Normal file
@@ -0,0 +1,266 @@
|
||||
package oauth
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/model/mysql/model"
|
||||
"schisandra-album-cloud-microservices/common/constant"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/yitter/idgenerator-go/idgen"
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/types"
|
||||
)
|
||||
|
||||
type QqCallbackLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
type AuthQQme struct {
|
||||
ClientID string `json:"client_id"`
|
||||
OpenID string `json:"openid"`
|
||||
}
|
||||
type QQToken struct {
|
||||
AccessToken string `json:"access_token"`
|
||||
ExpireIn string `json:"expire_in"`
|
||||
RefreshToken string `json:"refresh_token"`
|
||||
}
|
||||
|
||||
type QQUserInfo struct {
|
||||
City string `json:"city"`
|
||||
Figureurl string `json:"figureurl"`
|
||||
Figureurl1 string `json:"figureurl_1"`
|
||||
Figureurl2 string `json:"figureurl_2"`
|
||||
FigureurlQq string `json:"figureurl_qq"`
|
||||
FigureurlQq1 string `json:"figureurl_qq_1"`
|
||||
FigureurlQq2 string `json:"figureurl_qq_2"`
|
||||
Gender string `json:"gender"`
|
||||
GenderType int `json:"gender_type"`
|
||||
IsLost int `json:"is_lost"`
|
||||
IsYellowVip string `json:"is_yellow_vip"`
|
||||
IsYellowYearVip string `json:"is_yellow_year_vip"`
|
||||
Level string `json:"level"`
|
||||
Msg string `json:"msg"`
|
||||
Nickname string `json:"nickname"`
|
||||
Province string `json:"province"`
|
||||
Ret int `json:"ret"`
|
||||
Vip string `json:"vip"`
|
||||
Year string `json:"year"`
|
||||
YellowVipLevel string `json:"yellow_vip_level"`
|
||||
}
|
||||
|
||||
func NewQqCallbackLogic(ctx context.Context, svcCtx *svc.ServiceContext) *QqCallbackLogic {
|
||||
return &QqCallbackLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *QqCallbackLogic) QqCallback(r *http.Request, req *types.OAuthCallbackRequest) (string, error) {
|
||||
|
||||
tokenAuthUrl := l.GetQQTokenAuthUrl(req.Code)
|
||||
token, err := l.GetQQToken(tokenAuthUrl)
|
||||
if err != nil {
|
||||
|
||||
return "", err
|
||||
}
|
||||
if token == nil {
|
||||
return "", errors.New("get qq token failed")
|
||||
}
|
||||
|
||||
// 通过 token 获取 openid
|
||||
authQQme, err := l.GetQQUserOpenID(token)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// 通过 token 和 openid 获取用户信息
|
||||
userInfo, err := l.GetQQUserUserInfo(token, authQQme.OpenID)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if userInfo == nil {
|
||||
return "", errors.New("get qq user info failed")
|
||||
}
|
||||
|
||||
// 处理用户信息
|
||||
userInfoBytes, err := json.Marshal(userInfo)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
var qqUserInfo QQUserInfo
|
||||
err = json.Unmarshal(userInfoBytes, &qqUserInfo)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
tx := l.svcCtx.DB.Begin()
|
||||
|
||||
userSocial := l.svcCtx.DB.ScaAuthUserSocial
|
||||
socialUser, err := tx.ScaAuthUserSocial.Where(userSocial.OpenID.Eq(authQQme.OpenID), userSocial.Source.Eq(constant.OAuthSourceQQ)).First()
|
||||
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if socialUser == nil {
|
||||
// 创建用户
|
||||
uid := idgen.NextId()
|
||||
uidStr := strconv.FormatInt(uid, 10)
|
||||
|
||||
male := constant.Male
|
||||
avatarUrl := strings.Replace(qqUserInfo.FigureurlQq1, "http://", "https://", 1)
|
||||
addUser := &model.ScaAuthUser{
|
||||
UID: uidStr,
|
||||
Avatar: avatarUrl,
|
||||
Username: authQQme.OpenID,
|
||||
Nickname: qqUserInfo.Nickname,
|
||||
Gender: male,
|
||||
}
|
||||
err = tx.ScaAuthUser.Create(addUser)
|
||||
if err != nil {
|
||||
_ = tx.Rollback()
|
||||
return "", err
|
||||
}
|
||||
|
||||
githubUser := constant.OAuthSourceQQ
|
||||
newSocialUser := &model.ScaAuthUserSocial{
|
||||
UserID: uidStr,
|
||||
OpenID: authQQme.OpenID,
|
||||
Source: githubUser,
|
||||
}
|
||||
err = tx.ScaAuthUserSocial.Create(newSocialUser)
|
||||
if err != nil {
|
||||
_ = tx.Rollback()
|
||||
return "", err
|
||||
}
|
||||
|
||||
if res, err := l.svcCtx.CasbinEnforcer.AddRoleForUser(uidStr, constant.User); !res || err != nil {
|
||||
_ = tx.Rollback()
|
||||
return "", err
|
||||
}
|
||||
|
||||
data, err := HandleOauthLoginResponse(addUser, l.svcCtx, r, l.ctx)
|
||||
if err != nil {
|
||||
_ = tx.Rollback()
|
||||
return "", err
|
||||
}
|
||||
if err = tx.Commit(); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return data, nil
|
||||
} else {
|
||||
authUser := l.svcCtx.DB.ScaAuthUser
|
||||
|
||||
authUserInfo, err := tx.ScaAuthUser.Where(authUser.UID.Eq(socialUser.UserID)).First()
|
||||
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
_ = tx.Rollback()
|
||||
return "", err
|
||||
}
|
||||
|
||||
data, err := HandleOauthLoginResponse(authUserInfo, l.svcCtx, r, l.ctx)
|
||||
if err != nil {
|
||||
_ = tx.Rollback()
|
||||
return "", err
|
||||
}
|
||||
if err = tx.Commit(); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
}
|
||||
|
||||
// GetQQTokenAuthUrl 通过code获取token认证url
|
||||
func (l *QqCallbackLogic) GetQQTokenAuthUrl(code string) string {
|
||||
clientId := l.svcCtx.Config.OAuth.QQ.ClientID
|
||||
clientSecret := l.svcCtx.Config.OAuth.QQ.ClientSecret
|
||||
redirectURI := l.svcCtx.Config.OAuth.QQ.RedirectURI
|
||||
return fmt.Sprintf(
|
||||
"https://graph.qq.com/oauth2.0/token?grant_type=authorization_code&client_id=%s&client_secret=%s&code=%s&redirect_uri=%s&fmt=json",
|
||||
clientId, clientSecret, code, redirectURI,
|
||||
)
|
||||
}
|
||||
|
||||
// GetQQToken 获取 token
|
||||
func (l *QqCallbackLogic) GetQQToken(url string) (*QQToken, error) {
|
||||
|
||||
// 形成请求
|
||||
var req *http.Request
|
||||
var err error
|
||||
if req, err = http.NewRequest(http.MethodGet, url, nil); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 发送请求并获得响应
|
||||
var httpClient = http.Client{}
|
||||
var res *http.Response
|
||||
if res, err = httpClient.Do(req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// 将响应体解析为 token,并返回
|
||||
var token QQToken
|
||||
if err = json.NewDecoder(res.Body).Decode(&token); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &token, nil
|
||||
}
|
||||
|
||||
// GetQQUserOpenID 获取用户 openid
|
||||
func (l *QqCallbackLogic) GetQQUserOpenID(token *QQToken) (*AuthQQme, error) {
|
||||
|
||||
// 形成请求
|
||||
var userInfoUrl = "https://graph.qq.com/oauth2.0/me?access_token=" + token.AccessToken + "&fmt=json"
|
||||
var req *http.Request
|
||||
var err error
|
||||
if req, err = http.NewRequest(http.MethodGet, userInfoUrl, nil); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// 发送请求并获取响应
|
||||
var client = http.Client{}
|
||||
var res *http.Response
|
||||
if res, err = client.Do(req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 将响应体解析为 AuthQQme,并返回
|
||||
var authQQme AuthQQme
|
||||
if err = json.NewDecoder(res.Body).Decode(&authQQme); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &authQQme, nil
|
||||
}
|
||||
|
||||
// GetQQUserUserInfo 获取用户信息
|
||||
func (l *QqCallbackLogic) GetQQUserUserInfo(token *QQToken, openId string) (map[string]interface{}, error) {
|
||||
|
||||
clientId := l.svcCtx.Config.OAuth.QQ.ClientID
|
||||
// 形成请求
|
||||
var userInfoUrl = "https://graph.qq.com/user/get_user_info?access_token=" + token.AccessToken + "&oauth_consumer_key=" + clientId + "&openid=" + openId
|
||||
var req *http.Request
|
||||
var err error
|
||||
if req, err = http.NewRequest(http.MethodGet, userInfoUrl, nil); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// 发送请求并获取响应
|
||||
var client = http.Client{}
|
||||
var res *http.Response
|
||||
if res, err = client.Do(req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 将响应的数据写入 userInfo 中,并返回
|
||||
var userInfo = make(map[string]interface{})
|
||||
if err = json.NewDecoder(res.Body).Decode(&userInfo); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return userInfo, nil
|
||||
}
|
@@ -0,0 +1,125 @@
|
||||
package oauth
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"github.com/ArtisanCloud/PowerWeChat/v3/src/kernel/contract"
|
||||
"github.com/ArtisanCloud/PowerWeChat/v3/src/kernel/messages"
|
||||
models2 "github.com/ArtisanCloud/PowerWeChat/v3/src/kernel/models"
|
||||
"github.com/ArtisanCloud/PowerWeChat/v3/src/officialAccount/server/handlers/models"
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/logic/websocket"
|
||||
"schisandra-album-cloud-microservices/common/encrypt"
|
||||
"schisandra-album-cloud-microservices/common/i18n"
|
||||
"schisandra-album-cloud-microservices/common/xhttp"
|
||||
"strings"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
|
||||
)
|
||||
|
||||
type WechatOffiaccountCallbackLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
type MessageData struct {
|
||||
Openid string `json:"openid"`
|
||||
ClientId string `json:"client_id"`
|
||||
}
|
||||
|
||||
func NewWechatOffiaccountCallbackLogic(ctx context.Context, svcCtx *svc.ServiceContext) *WechatOffiaccountCallbackLogic {
|
||||
return &WechatOffiaccountCallbackLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *WechatOffiaccountCallbackLogic) WechatOffiaccountCallback(r *http.Request) (*http.Response, error) {
|
||||
rs, err := l.svcCtx.WechatOfficial.Server.Notify(r, func(event contract.EventInterface) interface{} {
|
||||
switch event.GetMsgType() {
|
||||
case models2.CALLBACK_MSG_TYPE_EVENT:
|
||||
switch event.GetEvent() {
|
||||
case models.CALLBACK_EVENT_SUBSCRIBE:
|
||||
msg := models.EventSubscribe{}
|
||||
err := event.ReadMessage(&msg)
|
||||
if err != nil {
|
||||
logx.Error(err.Error())
|
||||
return "error"
|
||||
}
|
||||
key := strings.TrimPrefix(msg.EventKey, "qrscene_")
|
||||
err = l.SendMessage(msg.FromUserName, key)
|
||||
if err != nil {
|
||||
return messages.NewText(i18n.FormatText(l.ctx, "login.loginFailed"))
|
||||
}
|
||||
return messages.NewText(i18n.FormatText(l.ctx, "login.loginSuccess"))
|
||||
|
||||
case models.CALLBACK_EVENT_UNSUBSCRIBE:
|
||||
msg := models.EventUnSubscribe{}
|
||||
err := event.ReadMessage(&msg)
|
||||
if err != nil {
|
||||
logx.Error(err.Error())
|
||||
return "error"
|
||||
}
|
||||
return messages.NewText("ok")
|
||||
|
||||
case models.CALLBACK_EVENT_SCAN:
|
||||
msg := models.EventScan{}
|
||||
err := event.ReadMessage(&msg)
|
||||
if err != nil {
|
||||
logx.Error(err.Error())
|
||||
return "error"
|
||||
}
|
||||
err = l.SendMessage(msg.FromUserName, msg.EventKey)
|
||||
if err != nil {
|
||||
return messages.NewText(i18n.FormatText(l.ctx, "login.loginFailed"))
|
||||
}
|
||||
return messages.NewText(i18n.FormatText(l.ctx, "login.loginSuccess"))
|
||||
|
||||
}
|
||||
|
||||
case models2.CALLBACK_MSG_TYPE_TEXT:
|
||||
msg := models.MessageText{}
|
||||
err := event.ReadMessage(&msg)
|
||||
if err != nil {
|
||||
logx.Error(err.Error())
|
||||
return "error"
|
||||
}
|
||||
}
|
||||
return messages.NewText("ok")
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return rs, nil
|
||||
}
|
||||
|
||||
// SendMessage 发送消息到客户端
|
||||
func (l *WechatOffiaccountCallbackLogic) SendMessage(openId string, clientId string) error {
|
||||
encryptClientId, err := encrypt.Encrypt(clientId, l.svcCtx.Config.Encrypt.Key, l.svcCtx.Config.Encrypt.IV)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
encryptOpenId, err := encrypt.Encrypt(openId, l.svcCtx.Config.Encrypt.Key, l.svcCtx.Config.Encrypt.IV)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
messageData := MessageData{
|
||||
Openid: encryptOpenId,
|
||||
ClientId: encryptClientId,
|
||||
}
|
||||
jsonData, err := json.Marshal(xhttp.BaseResponse[MessageData]{
|
||||
Code: 200,
|
||||
Data: messageData,
|
||||
Msg: "success",
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = websocket.QrcodeWebSocketHandler.SendMessageToClient(clientId, jsonData)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
package oauth
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
|
||||
)
|
||||
|
||||
type WechatOffiaccountCallbackVerifyLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewWechatOffiaccountCallbackVerifyLogic(ctx context.Context, svcCtx *svc.ServiceContext) *WechatOffiaccountCallbackVerifyLogic {
|
||||
return &WechatOffiaccountCallbackVerifyLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *WechatOffiaccountCallbackVerifyLogic) WechatOffiaccountCallbackVerify(r *http.Request) (*http.Response, error) {
|
||||
rs, err := l.svcCtx.WechatOfficial.Server.VerifyURL(r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return rs, nil
|
||||
}
|
74
app/auth/api/internal/logic/sms/send_sms_by_aliyun_logic.go
Normal file
74
app/auth/api/internal/logic/sms/send_sms_by_aliyun_logic.go
Normal file
@@ -0,0 +1,74 @@
|
||||
package sms
|
||||
|
||||
import (
|
||||
"context"
|
||||
gosms "github.com/pkg6/go-sms"
|
||||
"github.com/pkg6/go-sms/gateways"
|
||||
"github.com/pkg6/go-sms/gateways/aliyun"
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/common/captcha/verify"
|
||||
"schisandra-album-cloud-microservices/common/constant"
|
||||
"schisandra-album-cloud-microservices/common/errors"
|
||||
"schisandra-album-cloud-microservices/common/i18n"
|
||||
"schisandra-album-cloud-microservices/common/utils"
|
||||
"time"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type SendSmsByAliyunLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewSendSmsByAliyunLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SendSmsByAliyunLogic {
|
||||
return &SendSmsByAliyunLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *SendSmsByAliyunLogic) SendSmsByAliyun(req *types.SmsSendRequest) error {
|
||||
checkRotateData := verify.VerifyRotateCaptcha(l.ctx, l.svcCtx.RedisClient, req.Angle, req.Key)
|
||||
if !checkRotateData {
|
||||
return errors.New(http.StatusInternalServerError, i18n.FormatText(l.ctx, i18n.FormatText(l.ctx, "sms.verificationFailure")))
|
||||
}
|
||||
isPhone := utils.IsPhone(req.Phone)
|
||||
if !isPhone {
|
||||
return errors.New(http.StatusInternalServerError, i18n.FormatText(l.ctx, "login.phoneFormatError"))
|
||||
}
|
||||
val := l.svcCtx.RedisClient.Get(l.ctx, constant.UserSmsRedisPrefix+req.Phone).Val()
|
||||
if val != "" {
|
||||
return errors.New(http.StatusInternalServerError, i18n.FormatText(l.ctx, "sms.smsSendTooFrequently"))
|
||||
}
|
||||
sms := gosms.NewParser(gateways.Gateways{
|
||||
ALiYun: aliyun.ALiYun{
|
||||
Host: l.svcCtx.Config.SMS.Ali.Host,
|
||||
AccessKeyId: l.svcCtx.Config.SMS.Ali.AccessKeyId,
|
||||
AccessKeySecret: l.svcCtx.Config.SMS.Ali.AccessKeySecret,
|
||||
},
|
||||
})
|
||||
code := utils.GenValidateCode(6)
|
||||
wrong := l.svcCtx.RedisClient.Set(l.ctx, constant.UserSmsRedisPrefix+req.Phone, code, time.Minute).Err()
|
||||
if wrong != nil {
|
||||
return errors.New(http.StatusInternalServerError, wrong.Error())
|
||||
}
|
||||
_, err := sms.Send(req.Phone, gosms.MapStringAny{
|
||||
"content": "您的验证码是:****。请不要把验证码泄露给其他人。",
|
||||
"template": l.svcCtx.Config.SMS.Ali.TemplateCode,
|
||||
"signName": l.svcCtx.Config.SMS.Ali.Signature,
|
||||
"data": gosms.MapStrings{
|
||||
"code": code,
|
||||
},
|
||||
}, nil)
|
||||
if err != nil {
|
||||
return errors.New(http.StatusInternalServerError, err.Error())
|
||||
}
|
||||
return nil
|
||||
|
||||
}
|
68
app/auth/api/internal/logic/sms/send_sms_by_smsbao_logic.go
Normal file
68
app/auth/api/internal/logic/sms/send_sms_by_smsbao_logic.go
Normal file
@@ -0,0 +1,68 @@
|
||||
package sms
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/common/captcha/verify"
|
||||
"schisandra-album-cloud-microservices/common/constant"
|
||||
"schisandra-album-cloud-microservices/common/errors"
|
||||
"schisandra-album-cloud-microservices/common/i18n"
|
||||
utils2 "schisandra-album-cloud-microservices/common/utils"
|
||||
"time"
|
||||
|
||||
gosms "github.com/pkg6/go-sms"
|
||||
"github.com/pkg6/go-sms/gateways"
|
||||
"github.com/pkg6/go-sms/gateways/smsbao"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type SendSmsBySmsbaoLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewSendSmsBySmsbaoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SendSmsBySmsbaoLogic {
|
||||
return &SendSmsBySmsbaoLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *SendSmsBySmsbaoLogic) SendSmsBySmsbao(req *types.SmsSendRequest) (err error) {
|
||||
checkRotateData := verify.VerifyRotateCaptcha(l.ctx, l.svcCtx.RedisClient, req.Angle, req.Key)
|
||||
if !checkRotateData {
|
||||
return errors.New(http.StatusInternalServerError, i18n.FormatText(l.ctx, "captcha.verificationFailure"))
|
||||
}
|
||||
isPhone := utils2.IsPhone(req.Phone)
|
||||
if !isPhone {
|
||||
return errors.New(http.StatusInternalServerError, i18n.FormatText(l.ctx, "login.phoneFormatError"))
|
||||
}
|
||||
val := l.svcCtx.RedisClient.Get(l.ctx, constant.UserSmsRedisPrefix+req.Phone).Val()
|
||||
if val != "" {
|
||||
return errors.New(http.StatusInternalServerError, i18n.FormatText(l.ctx, "sms.smsSendTooFrequently"))
|
||||
}
|
||||
sms := gosms.NewParser(gateways.Gateways{
|
||||
SmsBao: smsbao.SmsBao{
|
||||
User: l.svcCtx.Config.SMS.SMSBao.Username,
|
||||
Password: l.svcCtx.Config.SMS.SMSBao.Password,
|
||||
},
|
||||
})
|
||||
code := utils2.GenValidateCode(6)
|
||||
wrong := l.svcCtx.RedisClient.Set(l.ctx, constant.UserSmsRedisPrefix+req.Phone, code, time.Minute).Err()
|
||||
if wrong != nil {
|
||||
return errors.New(http.StatusInternalServerError, wrong.Error())
|
||||
}
|
||||
_, err = sms.Send(req.Phone, gosms.MapStringAny{
|
||||
"content": "您的验证码是:" + code + "。请不要把验证码泄露给其他人。",
|
||||
}, nil)
|
||||
if err != nil {
|
||||
return errors.New(http.StatusInternalServerError, err.Error())
|
||||
}
|
||||
return nil
|
||||
}
|
52
app/auth/api/internal/logic/sms/send_sms_by_test_logic.go
Normal file
52
app/auth/api/internal/logic/sms/send_sms_by_test_logic.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package sms
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/common/captcha/verify"
|
||||
"schisandra-album-cloud-microservices/common/constant"
|
||||
"schisandra-album-cloud-microservices/common/errors"
|
||||
"schisandra-album-cloud-microservices/common/i18n"
|
||||
"schisandra-album-cloud-microservices/common/utils"
|
||||
"time"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type SendSmsByTestLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewSendSmsByTestLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SendSmsByTestLogic {
|
||||
return &SendSmsByTestLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *SendSmsByTestLogic) SendSmsByTest(req *types.SmsSendRequest) (err error) {
|
||||
checkRotateData := verify.VerifyRotateCaptcha(l.ctx, l.svcCtx.RedisClient, req.Angle, req.Key)
|
||||
if !checkRotateData {
|
||||
return errors.New(http.StatusInternalServerError, i18n.FormatText(l.ctx, "captcha.verificationFailure"))
|
||||
}
|
||||
isPhone := utils.IsPhone(req.Phone)
|
||||
if !isPhone {
|
||||
return errors.New(http.StatusInternalServerError, i18n.FormatText(l.ctx, "login.phoneFormatError"))
|
||||
}
|
||||
val := l.svcCtx.RedisClient.Get(l.ctx, constant.UserSmsRedisPrefix+req.Phone).Val()
|
||||
if val != "" {
|
||||
return errors.New(http.StatusInternalServerError, i18n.FormatText(l.ctx, "sms.smsSendTooFrequently"))
|
||||
}
|
||||
code := utils.GenValidateCode(6)
|
||||
wrong := l.svcCtx.RedisClient.Set(l.ctx, constant.UserSmsRedisPrefix+req.Phone, code, time.Minute).Err()
|
||||
if wrong != nil {
|
||||
return errors.New(http.StatusInternalServerError, wrong.Error())
|
||||
}
|
||||
return nil
|
||||
}
|
85
app/auth/api/internal/logic/token/refresh_token_logic.go
Normal file
85
app/auth/api/internal/logic/token/refresh_token_logic.go
Normal file
@@ -0,0 +1,85 @@
|
||||
package token
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/common/constant"
|
||||
"schisandra-album-cloud-microservices/common/errors"
|
||||
jwt2 "schisandra-album-cloud-microservices/common/jwt"
|
||||
"time"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type RefreshTokenLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewRefreshTokenLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RefreshTokenLogic {
|
||||
return &RefreshTokenLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *RefreshTokenLogic) RefreshToken(r *http.Request) (resp *types.RefreshTokenResponse, err error) {
|
||||
userId := r.Header.Get(constant.UID_HEADER_KEY)
|
||||
if userId == "" {
|
||||
return nil, errors.New(http.StatusForbidden, "user id is empty")
|
||||
}
|
||||
// 从redis中获取refresh token
|
||||
tokenData := l.svcCtx.RedisClient.Get(l.ctx, constant.UserTokenPrefix+userId).Val()
|
||||
if tokenData == "" {
|
||||
return nil, errors.New(http.StatusForbidden, "refresh token is empty")
|
||||
}
|
||||
redisTokenData := types.RedisToken{}
|
||||
err = json.Unmarshal([]byte(tokenData), &redisTokenData)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// 判断是否已经被吊销
|
||||
if redisTokenData.Revoked {
|
||||
return nil, errors.New(http.StatusForbidden, "refresh token is revoked")
|
||||
}
|
||||
// 判断是否是同一个设备
|
||||
if redisTokenData.AllowAgent != r.UserAgent() {
|
||||
return nil, errors.New(http.StatusForbidden, "refresh token is not allowed for this agent")
|
||||
}
|
||||
// 判断refresh token是否在有效期内
|
||||
refreshToken, result := jwt2.ParseRefreshToken(l.svcCtx.Config.Auth.AccessSecret, redisTokenData.RefreshToken)
|
||||
if !result {
|
||||
return nil, errors.New(http.StatusForbidden, "refresh token is invalid")
|
||||
}
|
||||
// 生成新的access token
|
||||
accessToken, expireAt := jwt2.GenerateAccessToken(l.svcCtx.Config.Auth.AccessSecret, jwt2.AccessJWTPayload{
|
||||
UserID: refreshToken.UserID,
|
||||
Type: constant.JWT_TYPE_ACCESS,
|
||||
})
|
||||
// 更新redis中的access token
|
||||
redisToken := types.RedisToken{
|
||||
AccessToken: accessToken,
|
||||
RefreshToken: redisTokenData.RefreshToken,
|
||||
UID: refreshToken.UserID,
|
||||
Revoked: false,
|
||||
GeneratedAt: redisTokenData.GeneratedAt,
|
||||
AllowAgent: redisTokenData.AllowAgent,
|
||||
GeneratedIP: redisTokenData.GeneratedIP,
|
||||
UpdatedAt: time.Now().Format(constant.TimeFormat),
|
||||
}
|
||||
err = l.svcCtx.RedisClient.Set(l.ctx, constant.UserTokenPrefix+refreshToken.UserID, redisToken, time.Hour*24*7).Err()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
token := &types.RefreshTokenResponse{
|
||||
AccessToken: accessToken,
|
||||
ExpireAt: expireAt,
|
||||
}
|
||||
return token, nil
|
||||
}
|
189
app/auth/api/internal/logic/user/account_login_logic.go
Normal file
189
app/auth/api/internal/logic/user/account_login_logic.go
Normal file
@@ -0,0 +1,189 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
errors2 "errors"
|
||||
"github.com/lionsoul2014/ip2region/binding/golang/xdb"
|
||||
"github.com/mssola/useragent"
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/model/mysql/model"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/model/mysql/query"
|
||||
"schisandra-album-cloud-microservices/common/captcha/verify"
|
||||
"schisandra-album-cloud-microservices/common/constant"
|
||||
"schisandra-album-cloud-microservices/common/errors"
|
||||
"schisandra-album-cloud-microservices/common/i18n"
|
||||
"schisandra-album-cloud-microservices/common/jwt"
|
||||
"schisandra-album-cloud-microservices/common/utils"
|
||||
"time"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"gorm.io/gorm"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/types"
|
||||
)
|
||||
|
||||
type AccountLoginLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewAccountLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AccountLoginLogic {
|
||||
return &AccountLoginLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *AccountLoginLogic) AccountLogin(r *http.Request, req *types.AccountLoginRequest) (resp *types.LoginResponse, err error) {
|
||||
verifyResult := verify.VerifyRotateCaptcha(l.ctx, l.svcCtx.RedisClient, req.Angle, req.Key)
|
||||
if !verifyResult {
|
||||
return nil, errors.New(http.StatusInternalServerError, i18n.FormatText(l.ctx, "captcha.verificationFailure"))
|
||||
}
|
||||
|
||||
user := l.svcCtx.DB.ScaAuthUser
|
||||
var selectedUser query.IScaAuthUserDo
|
||||
|
||||
switch {
|
||||
case utils.IsPhone(req.Account):
|
||||
selectedUser = user.Where(user.Phone.Eq(req.Account))
|
||||
case utils.IsEmail(req.Account):
|
||||
selectedUser = user.Where(user.Email.Eq(req.Account))
|
||||
case utils.IsUsername(req.Account):
|
||||
selectedUser = user.Where(user.Username.Eq(req.Account))
|
||||
default:
|
||||
return nil, errors.New(http.StatusInternalServerError, i18n.FormatText(l.ctx, "login.invalidAccount"))
|
||||
}
|
||||
userInfo, err := selectedUser.First()
|
||||
if err != nil {
|
||||
if errors2.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, errors.New(http.StatusInternalServerError, i18n.FormatText(l.ctx, "login.notFoundAccount"))
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if !utils.Verify(userInfo.Password, req.Password) {
|
||||
return nil, errors.New(http.StatusInternalServerError, i18n.FormatText(l.ctx, "login.invalidPassword"))
|
||||
}
|
||||
data, err := HandleLoginJWT(userInfo, l.svcCtx, req.AutoLogin, r, l.ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// HandleLoginJWT 处理用户登录
|
||||
func HandleLoginJWT(user *model.ScaAuthUser, svcCtx *svc.ServiceContext, autoLogin bool, r *http.Request, ctx context.Context) (*types.LoginResponse, error) {
|
||||
// 获取用户登录设备
|
||||
err := GetUserLoginDevice(user.UID, r, svcCtx.Ip2Region, svcCtx.DB)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// 生成jwt token
|
||||
accessToken, expireAt := jwt.GenerateAccessToken(svcCtx.Config.Auth.AccessSecret, jwt.AccessJWTPayload{
|
||||
UserID: user.UID,
|
||||
Type: constant.JWT_TYPE_ACCESS,
|
||||
})
|
||||
var days time.Duration
|
||||
if autoLogin {
|
||||
days = 3 * 24 * time.Hour
|
||||
} else {
|
||||
days = time.Hour * 24
|
||||
}
|
||||
refreshToken := jwt.GenerateRefreshToken(svcCtx.Config.Auth.AccessSecret, jwt.RefreshJWTPayload{
|
||||
UserID: user.UID,
|
||||
Type: constant.JWT_TYPE_REFRESH,
|
||||
}, days)
|
||||
data := types.LoginResponse{
|
||||
AccessToken: accessToken,
|
||||
ExpireAt: expireAt,
|
||||
UID: user.UID,
|
||||
Username: user.Username,
|
||||
Nickname: user.Nickname,
|
||||
Avatar: user.Avatar,
|
||||
Status: user.Status,
|
||||
}
|
||||
|
||||
redisToken := types.RedisToken{
|
||||
AccessToken: accessToken,
|
||||
RefreshToken: refreshToken,
|
||||
UID: user.UID,
|
||||
Revoked: false,
|
||||
GeneratedAt: time.Now().Format(constant.TimeFormat),
|
||||
AllowAgent: r.UserAgent(),
|
||||
GeneratedIP: utils.GetClientIP(r),
|
||||
UpdatedAt: time.Now().Format(constant.TimeFormat),
|
||||
}
|
||||
err = svcCtx.RedisClient.Set(ctx, constant.UserTokenPrefix+user.UID, redisToken, days).Err()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &data, nil
|
||||
}
|
||||
|
||||
// GetUserLoginDevice 获取用户登录设备
|
||||
func GetUserLoginDevice(userId string, r *http.Request, ip2location *xdb.Searcher, DB *query.Query) error {
|
||||
userAgent := r.UserAgent()
|
||||
if userAgent == "" {
|
||||
return errors2.New("user agent not found")
|
||||
}
|
||||
ip := utils.GetClientIP(r)
|
||||
location, err := ip2location.SearchByStr(ip)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
location = utils.RemoveZeroAndAdjust(location)
|
||||
|
||||
ua := useragent.New(userAgent)
|
||||
isBot := ua.Bot()
|
||||
browser, browserVersion := ua.Browser()
|
||||
os := ua.OS()
|
||||
mobile := ua.Mobile()
|
||||
mozilla := ua.Mozilla()
|
||||
platform := ua.Platform()
|
||||
engine, engineVersion := ua.Engine()
|
||||
var newIsBot int64 = 0
|
||||
var newIsMobile int64 = 0
|
||||
if isBot {
|
||||
newIsBot = 1
|
||||
}
|
||||
if mobile {
|
||||
newIsMobile = 1
|
||||
}
|
||||
userDevice := DB.ScaAuthUserDevice
|
||||
device, err := userDevice.Where(userDevice.UserID.Eq(userId), userDevice.IP.Eq(ip), userDevice.Agent.Eq(userAgent)).First()
|
||||
if err != nil && !errors2.Is(err, gorm.ErrRecordNotFound) {
|
||||
return err
|
||||
}
|
||||
newDevice := &model.ScaAuthUserDevice{
|
||||
UserID: userId,
|
||||
Bot: newIsBot,
|
||||
Agent: userAgent,
|
||||
Browser: browser,
|
||||
BrowserVersion: browserVersion,
|
||||
EngineName: engine,
|
||||
EngineVersion: engineVersion,
|
||||
IP: ip,
|
||||
Location: location,
|
||||
OperatingSystem: os,
|
||||
Mobile: newIsMobile,
|
||||
Mozilla: mozilla,
|
||||
Platform: platform,
|
||||
}
|
||||
if device == nil {
|
||||
// 创建新的设备记录
|
||||
err = DB.ScaAuthUserDevice.Create(newDevice)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
} else {
|
||||
resultInfo, err := userDevice.Where(userDevice.ID.Eq(device.ID)).Updates(newDevice)
|
||||
if err != nil || resultInfo.RowsAffected == 0 {
|
||||
return errors2.New("update device failed")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
@@ -0,0 +1,62 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"github.com/ArtisanCloud/PowerWeChat/v3/src/basicService/qrCode/response"
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/common/constant"
|
||||
"schisandra-album-cloud-microservices/common/utils"
|
||||
"time"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetWechatOffiaccountQrcodeLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGetWechatOffiaccountQrcodeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetWechatOffiaccountQrcodeLogic {
|
||||
return &GetWechatOffiaccountQrcodeLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetWechatOffiaccountQrcodeLogic) GetWechatOffiaccountQrcode(r *http.Request, req *types.OAuthWechatRequest) (resp string, err error) {
|
||||
ip := utils.GetClientIP(r)
|
||||
key := constant.UserQrcodePrefix + ip
|
||||
|
||||
// 从Redis获取二维码数据
|
||||
qrcode := l.svcCtx.RedisClient.Get(l.ctx, key).Val()
|
||||
if qrcode != "" {
|
||||
data := new(response.ResponseQRCodeCreate)
|
||||
if err = json.Unmarshal([]byte(qrcode), data); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return data.Url, nil
|
||||
}
|
||||
|
||||
// 生成临时二维码
|
||||
data, err := l.svcCtx.WechatOfficial.QRCode.Temporary(l.ctx, req.ClientId, 7*24*3600)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// 序列化数据并存储到Redis
|
||||
serializedData, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if err = l.svcCtx.RedisClient.Set(l.ctx, key, serializedData, time.Hour*24*7).Err(); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return data.Url, nil
|
||||
}
|
105
app/auth/api/internal/logic/user/phone_login_logic.go
Normal file
105
app/auth/api/internal/logic/user/phone_login_logic.go
Normal file
@@ -0,0 +1,105 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/model/mysql/model"
|
||||
constant2 "schisandra-album-cloud-microservices/common/constant"
|
||||
errors2 "schisandra-album-cloud-microservices/common/errors"
|
||||
"schisandra-album-cloud-microservices/common/i18n"
|
||||
"schisandra-album-cloud-microservices/common/random_name"
|
||||
utils2 "schisandra-album-cloud-microservices/common/utils"
|
||||
"strconv"
|
||||
|
||||
"github.com/yitter/idgenerator-go/idgen"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"gorm.io/gorm"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/types"
|
||||
)
|
||||
|
||||
type PhoneLoginLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewPhoneLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PhoneLoginLogic {
|
||||
return &PhoneLoginLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *PhoneLoginLogic) PhoneLogin(r *http.Request, req *types.PhoneLoginRequest) (resp *types.LoginResponse, err error) {
|
||||
if !utils2.IsPhone(req.Phone) {
|
||||
return nil, errors2.New(http.StatusInternalServerError, i18n.FormatText(l.ctx, "captcha.verificationFailure"))
|
||||
}
|
||||
code := l.svcCtx.RedisClient.Get(l.ctx, constant2.UserSmsRedisPrefix+req.Phone).Val()
|
||||
if code == "" {
|
||||
return nil, errors2.New(http.StatusInternalServerError, i18n.FormatText(l.ctx, "login.captchaExpired"))
|
||||
}
|
||||
if req.Captcha != code {
|
||||
return nil, errors2.New(http.StatusInternalServerError, i18n.FormatText(l.ctx, "login.captchaError"))
|
||||
}
|
||||
authUser := l.svcCtx.DB.ScaAuthUser
|
||||
userInfo, err := authUser.Where(authUser.Phone.Eq(req.Phone)).First()
|
||||
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, err
|
||||
}
|
||||
tx := l.svcCtx.DB.Begin()
|
||||
defer func() {
|
||||
if recover() != nil || err != nil {
|
||||
_ = tx.Rollback()
|
||||
}
|
||||
}()
|
||||
|
||||
if userInfo == nil {
|
||||
uid := idgen.NextId()
|
||||
uidStr := strconv.FormatInt(uid, 10)
|
||||
avatar := utils2.GenerateAvatar(uidStr)
|
||||
name := randomname.GenerateName()
|
||||
male := constant2.Male
|
||||
user := &model.ScaAuthUser{
|
||||
UID: uidStr,
|
||||
Phone: req.Phone,
|
||||
Avatar: avatar,
|
||||
Nickname: name,
|
||||
Gender: male,
|
||||
}
|
||||
err = tx.ScaAuthUser.Create(user)
|
||||
if err != nil {
|
||||
_ = tx.Rollback()
|
||||
return nil, err
|
||||
}
|
||||
_, err = l.svcCtx.CasbinEnforcer.AddRoleForUser(uidStr, constant2.User)
|
||||
if err != nil {
|
||||
_ = tx.Rollback()
|
||||
return nil, err
|
||||
}
|
||||
data, err := HandleLoginJWT(user, l.svcCtx, req.AutoLogin, r, l.ctx)
|
||||
if err != nil {
|
||||
_ = tx.Rollback()
|
||||
return nil, err
|
||||
}
|
||||
err = tx.Commit()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return data, nil
|
||||
} else {
|
||||
data, err := HandleLoginJWT(userInfo, l.svcCtx, req.AutoLogin, r, l.ctx)
|
||||
if err != nil {
|
||||
_ = tx.Rollback()
|
||||
return nil, err
|
||||
}
|
||||
err = tx.Commit()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
}
|
76
app/auth/api/internal/logic/user/reset_password_logic.go
Normal file
76
app/auth/api/internal/logic/user/reset_password_logic.go
Normal file
@@ -0,0 +1,76 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/common/constant"
|
||||
errors2 "schisandra-album-cloud-microservices/common/errors"
|
||||
"schisandra-album-cloud-microservices/common/i18n"
|
||||
utils2 "schisandra-album-cloud-microservices/common/utils"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"gorm.io/gorm"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/types"
|
||||
)
|
||||
|
||||
type ResetPasswordLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewResetPasswordLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ResetPasswordLogic {
|
||||
return &ResetPasswordLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *ResetPasswordLogic) ResetPassword(req *types.ResetPasswordRequest) (err error) {
|
||||
if !utils2.IsPhone(req.Phone) {
|
||||
return errors2.New(http.StatusInternalServerError, i18n.FormatText(l.ctx, "login.phoneFormatError"))
|
||||
}
|
||||
if req.Password != req.Repassword {
|
||||
return errors2.New(http.StatusInternalServerError, i18n.FormatText(l.ctx, "login.passwordNotMatch"))
|
||||
}
|
||||
if !utils2.IsPassword(req.Password) {
|
||||
return errors2.New(http.StatusInternalServerError, i18n.FormatText(l.ctx, "login.passwordFormatError"))
|
||||
}
|
||||
code := l.svcCtx.RedisClient.Get(l.ctx, constant.UserSmsRedisPrefix+req.Phone).Val()
|
||||
if code == "" {
|
||||
return errors2.New(http.StatusInternalServerError, i18n.FormatText(l.ctx, "login.captchaExpired"))
|
||||
}
|
||||
if req.Captcha != code {
|
||||
return errors2.New(http.StatusInternalServerError, i18n.FormatText(l.ctx, "login.captchaError"))
|
||||
}
|
||||
// 验证码检查通过后立即删除或标记为已使用
|
||||
if err = l.svcCtx.RedisClient.Del(l.ctx, constant.UserSmsRedisPrefix+req.Phone).Err(); err != nil {
|
||||
return errors2.New(http.StatusInternalServerError, err.Error())
|
||||
}
|
||||
authUser := l.svcCtx.DB.ScaAuthUser
|
||||
|
||||
userInfo, err := authUser.Where(authUser.Phone.Eq(req.Phone)).First()
|
||||
if err != nil && errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return errors2.New(http.StatusInternalServerError, i18n.FormatText(l.ctx, "login.userNotRegistered"))
|
||||
}
|
||||
if err != nil {
|
||||
return errors2.New(http.StatusInternalServerError, err.Error())
|
||||
}
|
||||
encrypt, err := utils2.Encrypt(req.Password)
|
||||
if err != nil {
|
||||
return errors2.New(http.StatusInternalServerError, err.Error())
|
||||
}
|
||||
|
||||
affected, err := authUser.Where(authUser.ID.Eq(userInfo.ID), authUser.Phone.Eq(req.Phone)).Update(authUser.Password, encrypt)
|
||||
if err != nil {
|
||||
return errors2.New(http.StatusInternalServerError, err.Error())
|
||||
}
|
||||
if affected.RowsAffected == 0 {
|
||||
return errors2.New(http.StatusInternalServerError, i18n.FormatText(l.ctx, "login.resetPasswordError"))
|
||||
}
|
||||
return nil
|
||||
}
|
@@ -0,0 +1,121 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"github.com/yitter/idgenerator-go/idgen"
|
||||
"gorm.io/gorm"
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/model/mysql/model"
|
||||
"schisandra-album-cloud-microservices/common/constant"
|
||||
"schisandra-album-cloud-microservices/common/encrypt"
|
||||
errors2 "schisandra-album-cloud-microservices/common/errors"
|
||||
"schisandra-album-cloud-microservices/common/i18n"
|
||||
"schisandra-album-cloud-microservices/common/random_name"
|
||||
"schisandra-album-cloud-microservices/common/utils"
|
||||
"strconv"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type WechatOffiaccountLoginLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewWechatOffiaccountLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *WechatOffiaccountLoginLogic {
|
||||
return &WechatOffiaccountLoginLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *WechatOffiaccountLoginLogic) WechatOffiaccountLogin(r *http.Request, req *types.WechatOffiaccountLoginRequest) (resp *types.LoginResponse, err error) {
|
||||
decryptedClientId, err := encrypt.Decrypt(req.ClientId, l.svcCtx.Config.Encrypt.Key, l.svcCtx.Config.Encrypt.IV)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
clientId := l.svcCtx.RedisClient.Get(r.Context(), constant.UserClientPrefix+decryptedClientId).Val()
|
||||
if clientId == "" {
|
||||
return nil, errors2.New(http.StatusUnauthorized, i18n.FormatText(l.ctx, "login.loginFailed"))
|
||||
}
|
||||
Openid, err := encrypt.Decrypt(req.Openid, l.svcCtx.Config.Encrypt.Key, l.svcCtx.Config.Encrypt.IV)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
tx := l.svcCtx.DB.Begin()
|
||||
userSocial := l.svcCtx.DB.ScaAuthUserSocial
|
||||
socialUser, err := tx.ScaAuthUserSocial.Where(userSocial.OpenID.Eq(Openid), userSocial.Source.Eq(constant.OAuthSourceWechat)).First()
|
||||
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, err
|
||||
}
|
||||
if socialUser == nil {
|
||||
// 创建用户
|
||||
uid := idgen.NextId()
|
||||
uidStr := strconv.FormatInt(uid, 10)
|
||||
avatar := utils.GenerateAvatar(uidStr)
|
||||
name := randomname.GenerateName()
|
||||
|
||||
addUser := &model.ScaAuthUser{
|
||||
UID: uidStr,
|
||||
Avatar: avatar,
|
||||
Username: Openid,
|
||||
Nickname: name,
|
||||
Gender: constant.Male,
|
||||
}
|
||||
err = tx.ScaAuthUser.Create(addUser)
|
||||
if err != nil {
|
||||
_ = tx.Rollback()
|
||||
return nil, err
|
||||
}
|
||||
|
||||
newSocialUser := &model.ScaAuthUserSocial{
|
||||
UserID: uidStr,
|
||||
OpenID: Openid,
|
||||
Source: constant.OAuthSourceWechat,
|
||||
}
|
||||
err = tx.ScaAuthUserSocial.Create(newSocialUser)
|
||||
if err != nil {
|
||||
_ = tx.Rollback()
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if res, err := l.svcCtx.CasbinEnforcer.AddRoleForUser(uidStr, constant.User); !res || err != nil {
|
||||
_ = tx.Rollback()
|
||||
return nil, err
|
||||
}
|
||||
|
||||
data, err := HandleLoginJWT(addUser, l.svcCtx, true, r, l.ctx)
|
||||
if err != nil {
|
||||
_ = tx.Rollback()
|
||||
return nil, err
|
||||
}
|
||||
if err = tx.Commit(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return data, nil
|
||||
} else {
|
||||
authUser := l.svcCtx.DB.ScaAuthUser
|
||||
|
||||
authUserInfo, err := tx.ScaAuthUser.Where(authUser.UID.Eq(socialUser.UserID)).First()
|
||||
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
_ = tx.Rollback()
|
||||
return nil, err
|
||||
}
|
||||
data, err := HandleLoginJWT(authUserInfo, l.svcCtx, true, r, l.ctx)
|
||||
if err != nil {
|
||||
_ = tx.Rollback()
|
||||
return nil, err
|
||||
}
|
||||
if err = tx.Commit(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return data, nil
|
||||
|
||||
}
|
||||
}
|
126
app/auth/api/internal/logic/websocket/message_websocket_logic.go
Normal file
126
app/auth/api/internal/logic/websocket/message_websocket_logic.go
Normal file
@@ -0,0 +1,126 @@
|
||||
package websocket
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/common/jwt"
|
||||
"time"
|
||||
|
||||
"github.com/lxzan/gws"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
|
||||
)
|
||||
|
||||
type MessageWebsocketLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewMessageWebsocketLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MessageWebsocketLogic {
|
||||
return &MessageWebsocketLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
type MessageWebSocket struct {
|
||||
ctx context.Context
|
||||
gws.BuiltinEventHandler
|
||||
sessions *gws.ConcurrentMap[string, *gws.Conn] // 使用内置的ConcurrentMap存储连接, 可以减少锁冲突
|
||||
}
|
||||
|
||||
var MessageWebSocketHandler = NewMessageWebSocket()
|
||||
|
||||
func (l *MessageWebsocketLogic) MessageWebsocket(w http.ResponseWriter, r *http.Request) {
|
||||
token := r.Header.Get("Sec-Websocket-Protocol")
|
||||
accessToken, res := jwt.ParseAccessToken(l.svcCtx.Config.Auth.AccessSecret, token)
|
||||
if !res {
|
||||
return
|
||||
}
|
||||
upgrader := gws.NewUpgrader(MessageWebSocketHandler, &gws.ServerOption{
|
||||
HandshakeTimeout: 5 * time.Second, // 握手超时时间
|
||||
ReadBufferSize: 1024, // 读缓冲区大小
|
||||
ParallelEnabled: true, // 开启并行消息处理
|
||||
Recovery: gws.Recovery, // 开启异常恢复
|
||||
CheckUtf8Enabled: false, // 关闭UTF8校验
|
||||
PermessageDeflate: gws.PermessageDeflate{
|
||||
Enabled: true, // 开启压缩
|
||||
},
|
||||
Authorize: func(r *http.Request, session gws.SessionStorage) bool {
|
||||
var clientId = r.URL.Query().Get("user_id")
|
||||
if clientId == "" {
|
||||
return false
|
||||
}
|
||||
if accessToken.UserID != clientId {
|
||||
return false
|
||||
}
|
||||
//token := r.URL.Query().Get("token")
|
||||
//if token == "" {
|
||||
// return false
|
||||
//}
|
||||
//accessToken, res := jwt.ParseAccessToken(l.svcCtx.Config.Auth.AccessSecret, token)
|
||||
//if !res || accessToken.UserID != clientId {
|
||||
// return false
|
||||
//}
|
||||
session.Store("user_id", clientId)
|
||||
return true
|
||||
},
|
||||
SubProtocols: []string{token},
|
||||
})
|
||||
socket, err := upgrader.Upgrade(w, r)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
go func() {
|
||||
socket.ReadLoop()
|
||||
}()
|
||||
}
|
||||
|
||||
// NewMessageWebSocket 创建WebSocket实例
|
||||
func NewMessageWebSocket() *MessageWebSocket {
|
||||
return &MessageWebSocket{
|
||||
ctx: context.Background(),
|
||||
sessions: gws.NewConcurrentMap[string, *gws.Conn](64, 128),
|
||||
}
|
||||
}
|
||||
|
||||
// OnOpen 连接建立
|
||||
func (c *MessageWebSocket) OnOpen(socket *gws.Conn) {
|
||||
clientId := MustLoad[string](socket.Session(), "user_id")
|
||||
c.sessions.Store(clientId, socket)
|
||||
// 订阅该用户的频道
|
||||
fmt.Printf("websocket client %s connected\n", clientId)
|
||||
}
|
||||
|
||||
// OnClose 关闭连接
|
||||
func (c *MessageWebSocket) OnClose(socket *gws.Conn, err error) {
|
||||
name := MustLoad[string](socket.Session(), "user_id")
|
||||
sharding := c.sessions.GetSharding(name)
|
||||
c.sessions.Delete(name)
|
||||
sharding.Lock()
|
||||
defer sharding.Unlock()
|
||||
fmt.Printf("websocket closed, name=%s, msg=%s\n", name, err.Error())
|
||||
}
|
||||
|
||||
// OnPing 处理客户端的Ping消息
|
||||
func (c *MessageWebSocket) OnPing(socket *gws.Conn, payload []byte) {
|
||||
_ = socket.SetDeadline(time.Now().Add(PingInterval + HeartbeatWaitTimeout))
|
||||
_ = socket.WritePong(payload)
|
||||
}
|
||||
|
||||
// OnPong 处理客户端的Pong消息
|
||||
func (c *MessageWebSocket) OnPong(_ *gws.Conn, _ []byte) {}
|
||||
|
||||
// OnMessage 接受消息
|
||||
func (c *MessageWebSocket) OnMessage(socket *gws.Conn, message *gws.Message) {
|
||||
defer message.Close()
|
||||
clientId := MustLoad[string](socket.Session(), "user_id")
|
||||
if conn, ok := c.sessions.Load(clientId); ok {
|
||||
_ = conn.WriteMessage(gws.OpcodeText, message.Bytes())
|
||||
}
|
||||
// fmt.Printf("received message from client %s\n", message.Data)
|
||||
}
|
133
app/auth/api/internal/logic/websocket/qrcode_websocket_logic.go
Normal file
133
app/auth/api/internal/logic/websocket/qrcode_websocket_logic.go
Normal file
@@ -0,0 +1,133 @@
|
||||
package websocket
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/common/constant"
|
||||
"schisandra-album-cloud-microservices/common/utils"
|
||||
"time"
|
||||
|
||||
"github.com/lxzan/gws"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
|
||||
)
|
||||
|
||||
type QrcodeWebsocketLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewQrcodeWebsocketLogic(ctx context.Context, svcCtx *svc.ServiceContext) *QrcodeWebsocketLogic {
|
||||
return &QrcodeWebsocketLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
const (
|
||||
PingInterval = 5 * time.Second // 客户端心跳间隔
|
||||
HeartbeatWaitTimeout = 10 * time.Second // 心跳等待超时时间
|
||||
)
|
||||
|
||||
type QrcodeWebSocket struct {
|
||||
gws.BuiltinEventHandler
|
||||
sessions *gws.ConcurrentMap[string, *gws.Conn] // 使用内置的ConcurrentMap存储连接, 可以减少锁冲突
|
||||
}
|
||||
|
||||
var QrcodeWebSocketHandler = NewWebSocket()
|
||||
|
||||
func (l *QrcodeWebsocketLogic) QrcodeWebsocket(w http.ResponseWriter, r *http.Request) {
|
||||
upgrader := gws.NewUpgrader(QrcodeWebSocketHandler, &gws.ServerOption{
|
||||
HandshakeTimeout: 5 * time.Second, // 握手超时时间
|
||||
ReadBufferSize: 1024, // 读缓冲区大小
|
||||
ParallelEnabled: true, // 开启并行消息处理
|
||||
Recovery: gws.Recovery, // 开启异常恢复
|
||||
CheckUtf8Enabled: false, // 关闭UTF8校验
|
||||
PermessageDeflate: gws.PermessageDeflate{
|
||||
Enabled: true, // 开启压缩
|
||||
},
|
||||
Authorize: func(r *http.Request, session gws.SessionStorage) bool {
|
||||
var clientId = r.URL.Query().Get("client_id")
|
||||
if clientId == "" {
|
||||
return false
|
||||
}
|
||||
ip := utils.GetClientIP(r)
|
||||
exists := l.svcCtx.RedisClient.Get(l.ctx, constant.UserClientPrefix+ip).Val()
|
||||
if clientId != exists {
|
||||
return false
|
||||
}
|
||||
session.Store("client_id", clientId)
|
||||
return true
|
||||
},
|
||||
})
|
||||
socket, err := upgrader.Upgrade(w, r)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
go func() {
|
||||
socket.ReadLoop() // 此处阻塞会使请求上下文不能顺利被GC
|
||||
}()
|
||||
}
|
||||
|
||||
// MustLoad 从session中加载数据
|
||||
func MustLoad[T any](session gws.SessionStorage, key string) (v T) {
|
||||
if value, exist := session.Load(key); exist {
|
||||
v = value.(T)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// NewWebSocket 创建WebSocket实例
|
||||
func NewWebSocket() *QrcodeWebSocket {
|
||||
return &QrcodeWebSocket{
|
||||
sessions: gws.NewConcurrentMap[string, *gws.Conn](64, 128),
|
||||
}
|
||||
}
|
||||
|
||||
// OnOpen 连接建立
|
||||
func (c *QrcodeWebSocket) OnOpen(socket *gws.Conn) {
|
||||
clientId := MustLoad[string](socket.Session(), "client_id")
|
||||
c.sessions.Store(clientId, socket)
|
||||
fmt.Printf("websocket client %s connected\n", clientId)
|
||||
}
|
||||
|
||||
// OnClose 关闭连接
|
||||
func (c *QrcodeWebSocket) OnClose(socket *gws.Conn, err error) {
|
||||
name := MustLoad[string](socket.Session(), "client_id")
|
||||
sharding := c.sessions.GetSharding(name)
|
||||
c.sessions.Delete(name)
|
||||
sharding.Lock()
|
||||
defer sharding.Unlock()
|
||||
fmt.Printf("websocket closed, name=%s, err=%s\n", name, err.Error())
|
||||
}
|
||||
|
||||
// OnPing 处理客户端的Ping消息
|
||||
func (c *QrcodeWebSocket) OnPing(socket *gws.Conn, payload []byte) {
|
||||
_ = socket.SetDeadline(time.Now().Add(PingInterval + HeartbeatWaitTimeout))
|
||||
_ = socket.WritePong(payload)
|
||||
}
|
||||
|
||||
// OnPong 处理客户端的Pong消息
|
||||
func (c *QrcodeWebSocket) OnPong(_ *gws.Conn, _ []byte) {}
|
||||
|
||||
// OnMessage 接受消息
|
||||
func (c *QrcodeWebSocket) OnMessage(socket *gws.Conn, message *gws.Message) {
|
||||
defer message.Close()
|
||||
clientId := MustLoad[string](socket.Session(), "client_id")
|
||||
if conn, ok := c.sessions.Load(clientId); ok {
|
||||
_ = conn.WriteMessage(gws.OpcodeText, message.Bytes())
|
||||
}
|
||||
}
|
||||
|
||||
// SendMessageToClient 向指定客户端发送消息
|
||||
func (c *QrcodeWebSocket) SendMessageToClient(clientId string, message []byte) error {
|
||||
conn, ok := c.sessions.Load(clientId)
|
||||
if ok {
|
||||
return conn.WriteMessage(gws.OpcodeText, message)
|
||||
}
|
||||
return fmt.Errorf("client %s not found", clientId)
|
||||
}
|
20
app/auth/api/internal/middleware/authorization_middleware.go
Normal file
20
app/auth/api/internal/middleware/authorization_middleware.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/common/middleware"
|
||||
)
|
||||
|
||||
type AuthorizationMiddleware struct {
|
||||
}
|
||||
|
||||
func NewAuthorizationMiddleware() *AuthorizationMiddleware {
|
||||
return &AuthorizationMiddleware{}
|
||||
}
|
||||
|
||||
func (m *AuthorizationMiddleware) Handle(next http.HandlerFunc) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
middleware.AuthorizationMiddleware(w, r)
|
||||
next(w, r)
|
||||
}
|
||||
}
|
24
app/auth/api/internal/middleware/casbinverify_middleware.go
Normal file
24
app/auth/api/internal/middleware/casbinverify_middleware.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"github.com/casbin/casbin/v2"
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/common/middleware"
|
||||
)
|
||||
|
||||
type CasbinVerifyMiddleware struct {
|
||||
casbin *casbin.SyncedCachedEnforcer
|
||||
}
|
||||
|
||||
func NewCasbinVerifyMiddleware(casbin *casbin.SyncedCachedEnforcer) *CasbinVerifyMiddleware {
|
||||
return &CasbinVerifyMiddleware{
|
||||
casbin: casbin,
|
||||
}
|
||||
}
|
||||
|
||||
func (m *CasbinVerifyMiddleware) Handle(next http.HandlerFunc) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
middleware.CasbinMiddleware(w, r, m.casbin)
|
||||
next(w, r)
|
||||
}
|
||||
}
|
24
app/auth/api/internal/middleware/nonce_middleware.go
Normal file
24
app/auth/api/internal/middleware/nonce_middleware.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"github.com/redis/go-redis/v9"
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/common/middleware"
|
||||
)
|
||||
|
||||
type NonceMiddleware struct {
|
||||
RedisClient *redis.Client
|
||||
}
|
||||
|
||||
func NewNonceMiddleware(redisClient *redis.Client) *NonceMiddleware {
|
||||
return &NonceMiddleware{
|
||||
RedisClient: redisClient,
|
||||
}
|
||||
}
|
||||
|
||||
func (m *NonceMiddleware) Handle(next http.HandlerFunc) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
middleware.NonceMiddleware(w, r, m.RedisClient)
|
||||
next(w, r)
|
||||
}
|
||||
}
|
@@ -0,0 +1,20 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/common/middleware"
|
||||
)
|
||||
|
||||
type SecurityHeadersMiddleware struct {
|
||||
}
|
||||
|
||||
func NewSecurityHeadersMiddleware() *SecurityHeadersMiddleware {
|
||||
return &SecurityHeadersMiddleware{}
|
||||
}
|
||||
|
||||
func (m *SecurityHeadersMiddleware) Handle(next http.HandlerFunc) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
middleware.SecurityHeadersMiddleware(r)
|
||||
next(w, r)
|
||||
}
|
||||
}
|
56
app/auth/api/internal/svc/service_context.go
Normal file
56
app/auth/api/internal/svc/service_context.go
Normal file
@@ -0,0 +1,56 @@
|
||||
package svc
|
||||
|
||||
import (
|
||||
"github.com/ArtisanCloud/PowerWeChat/v3/src/officialAccount"
|
||||
"github.com/casbin/casbin/v2"
|
||||
"github.com/lionsoul2014/ip2region/binding/golang/xdb"
|
||||
"github.com/redis/go-redis/v9"
|
||||
"github.com/wenlng/go-captcha/v2/rotate"
|
||||
"github.com/wenlng/go-captcha/v2/slide"
|
||||
"github.com/zeromicro/go-zero/rest"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/config"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/internal/middleware"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/model/mysql"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/model/mysql/query"
|
||||
"schisandra-album-cloud-microservices/common/captcha/initialize"
|
||||
"schisandra-album-cloud-microservices/common/casbinx"
|
||||
"schisandra-album-cloud-microservices/common/ip2region"
|
||||
"schisandra-album-cloud-microservices/common/redisx"
|
||||
"schisandra-album-cloud-microservices/common/wechat_official"
|
||||
)
|
||||
|
||||
type ServiceContext struct {
|
||||
Config config.Config
|
||||
SecurityHeadersMiddleware rest.Middleware
|
||||
CasbinVerifyMiddleware rest.Middleware
|
||||
AuthorizationMiddleware rest.Middleware
|
||||
NonceMiddleware rest.Middleware
|
||||
DB *query.Query
|
||||
RedisClient *redis.Client
|
||||
Ip2Region *xdb.Searcher
|
||||
CasbinEnforcer *casbin.SyncedCachedEnforcer
|
||||
WechatOfficial *officialAccount.OfficialAccount
|
||||
|
||||
RotateCaptcha rotate.Captcha
|
||||
SlideCaptcha slide.Captcha
|
||||
}
|
||||
|
||||
func NewServiceContext(c config.Config) *ServiceContext {
|
||||
redisClient := redisx.NewRedis(c.Redis.Host, c.Redis.Pass, c.Redis.DB)
|
||||
db, queryDB := mysql.NewMySQL(c.Mysql.DataSource, c.Mysql.MaxOpenConn, c.Mysql.MaxIdleConn, redisClient)
|
||||
casbinEnforcer := casbinx.NewCasbin(db)
|
||||
return &ServiceContext{
|
||||
Config: c,
|
||||
SecurityHeadersMiddleware: middleware.NewSecurityHeadersMiddleware().Handle,
|
||||
CasbinVerifyMiddleware: middleware.NewCasbinVerifyMiddleware(casbinEnforcer).Handle,
|
||||
AuthorizationMiddleware: middleware.NewAuthorizationMiddleware().Handle,
|
||||
NonceMiddleware: middleware.NewNonceMiddleware(redisClient).Handle,
|
||||
DB: queryDB,
|
||||
RedisClient: redisClient,
|
||||
Ip2Region: ip2region.NewIP2Region(),
|
||||
CasbinEnforcer: casbinEnforcer,
|
||||
WechatOfficial: wechat_official.NewWechatPublic(c.Wechat.AppID, c.Wechat.AppSecret, c.Wechat.Token, c.Wechat.AESKey, c.Redis.Host, c.Redis.Pass, c.Redis.DB),
|
||||
RotateCaptcha: initialize.NewRotateCaptcha(),
|
||||
SlideCaptcha: initialize.NewSlideCaptcha(),
|
||||
}
|
||||
}
|
22
app/auth/api/internal/types/token.go
Normal file
22
app/auth/api/internal/types/token.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package types
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
type RedisToken struct {
|
||||
AccessToken string `json:"access_token"`
|
||||
RefreshToken string `json:"refresh_token"`
|
||||
UID string `json:"uid"`
|
||||
Revoked bool `json:"revoked" default:"false"`
|
||||
AllowAgent string `json:"allow_agent"`
|
||||
GeneratedAt string `json:"generated_at"`
|
||||
UpdatedAt string `json:"updated_at"`
|
||||
GeneratedIP string `json:"generated_ip"`
|
||||
}
|
||||
|
||||
func (res RedisToken) MarshalBinary() ([]byte, error) {
|
||||
return json.Marshal(res)
|
||||
}
|
||||
|
||||
func (res RedisToken) UnmarshalBinary(data []byte) error {
|
||||
return json.Unmarshal(data, &res)
|
||||
}
|
79
app/auth/api/internal/types/types.go
Normal file
79
app/auth/api/internal/types/types.go
Normal file
@@ -0,0 +1,79 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// goctl 1.7.3
|
||||
|
||||
package types
|
||||
|
||||
type AccountLoginRequest struct {
|
||||
Account string `json:"account"`
|
||||
Password string `json:"password"`
|
||||
AutoLogin bool `json:"auto_login"`
|
||||
Angle int64 `json:"angle"`
|
||||
Key string `json:"key"`
|
||||
}
|
||||
|
||||
type LoginResponse struct {
|
||||
AccessToken string `json:"access_token"`
|
||||
ExpireAt int64 `json:"expire_at"`
|
||||
UID string `json:"uid"`
|
||||
Username string `json:"username,omitempty"`
|
||||
Nickname string `json:"nickname"`
|
||||
Avatar string `json:"avatar"`
|
||||
Status int64 `json:"status"`
|
||||
}
|
||||
|
||||
type OAuthCallbackRequest struct {
|
||||
Code string `form:"code"`
|
||||
}
|
||||
|
||||
type OAuthRequest struct {
|
||||
State string `form:"state"`
|
||||
}
|
||||
|
||||
type OAuthWechatRequest struct {
|
||||
ClientId string `json:"client_id"`
|
||||
}
|
||||
|
||||
type PhoneLoginRequest struct {
|
||||
Phone string `json:"phone"`
|
||||
Captcha string `json:"captcha"`
|
||||
AutoLogin bool `json:"auto_login"`
|
||||
}
|
||||
|
||||
type RefreshTokenResponse struct {
|
||||
AccessToken string `json:"access_token"`
|
||||
ExpireAt int64 `json:"expire_at"`
|
||||
}
|
||||
|
||||
type ResetPasswordRequest struct {
|
||||
Phone string `json:"phone"`
|
||||
Captcha string `json:"captcha"`
|
||||
Password string `json:"password"`
|
||||
Repassword string `json:"repassword"`
|
||||
}
|
||||
|
||||
type RotateCaptchaResponse struct {
|
||||
Key string `json:"key"`
|
||||
Image string `json:"image"`
|
||||
Thumb string `json:"thumb"`
|
||||
}
|
||||
|
||||
type SlideCaptchaResponse struct {
|
||||
Key string `json:"key"`
|
||||
Image string `json:"image"`
|
||||
Thumb string `json:"thumb"`
|
||||
ThumbWidth int64 `json:"thumb_width"`
|
||||
ThumbHeight int64 `json:"thumb_height"`
|
||||
ThumbX int64 `json:"thumb_x"`
|
||||
ThumbY int64 `json:"thumb_y"`
|
||||
}
|
||||
|
||||
type SmsSendRequest struct {
|
||||
Phone string `json:"phone"`
|
||||
Angle int64 `json:"angle"`
|
||||
Key string `json:"key"`
|
||||
}
|
||||
|
||||
type WechatOffiaccountLoginRequest struct {
|
||||
Openid string `json:"openid"`
|
||||
ClientId string `json:"client_id"`
|
||||
}
|
107
app/auth/api/model/mysql/generate/generate.go
Normal file
107
app/auth/api/model/mysql/generate/generate.go
Normal file
@@ -0,0 +1,107 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"gorm.io/driver/mysql"
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
const MySQLDSN = "root:1611@(localhost:3306)/schisandra-cloud-album?charset=utf8mb4&parseTime=True&loc=Local"
|
||||
|
||||
func main() {
|
||||
|
||||
// 连接数据库
|
||||
db, err := gorm.Open(mysql.Open(MySQLDSN))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
dir, err := os.Getwd()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
path := filepath.Join(dir, "app/auth/api/model/mysql/", "query")
|
||||
// 生成实例
|
||||
g := gen.NewGenerator(gen.Config{
|
||||
// 相对执行`go run`时的路径, 会自动创建目录
|
||||
OutPath: path,
|
||||
// 生成的文件名,默认gen.go
|
||||
OutFile: "gen.go",
|
||||
// 生成DAO代码的包名,默认是:model
|
||||
ModelPkgPath: "model",
|
||||
// 是否为DAO包生成单元测试代码,默认:false
|
||||
WithUnitTest: false,
|
||||
|
||||
// WithDefaultQuery 生成默认查询结构体(作为全局变量使用), 即`Q`结构体和其字段(各表模型)
|
||||
// WithoutContext 生成没有context调用限制的代码供查询
|
||||
// WithQueryInterface 生成interface形式的查询代码(可导出), 如`Where()`方法返回的就是一个可导出的接口类型
|
||||
Mode: gen.WithDefaultQuery | gen.WithQueryInterface | gen.WithoutContext,
|
||||
|
||||
// 表字段可为 null 值时, 对应结体字段使用指针类型
|
||||
FieldNullable: false, // generate pointer when field is nullable
|
||||
|
||||
// 表字段默认值与模型结构体字段零值不一致的字段, 在插入数据时需要赋值该字段值为零值的, 结构体字段须是指针类型才能成功, 即`FieldCoverable:true`配置下生成的结构体字段.
|
||||
// 因为在插入时遇到字段为零值的会被GORM赋予默认值. 如字段`age`表默认值为10, 即使你显式设置为0最后也会被GORM设为10提交.
|
||||
// 如果该字段没有上面提到的插入时赋零值的特殊需要, 则字段为非指针类型使用起来会比较方便.
|
||||
FieldCoverable: true,
|
||||
|
||||
// 模型结构体字段的数字类型的符号表示是否与表字段的一致, `false`指示都用有符号类型
|
||||
FieldSignable: false,
|
||||
// 生成 gorm 标签的字段索引属性
|
||||
FieldWithIndexTag: true,
|
||||
// 生成 gorm 标签的字段类型属性
|
||||
FieldWithTypeTag: true,
|
||||
})
|
||||
// 设置目标 db
|
||||
g.UseDB(db)
|
||||
|
||||
// 自定义字段的数据类型
|
||||
// 统一数字类型为int64,兼容protobuf
|
||||
dataMap := map[string]func(columnType gorm.ColumnType) (dataType string){
|
||||
"tinyint": func(columnType gorm.ColumnType) (dataType string) { return "int64" },
|
||||
"smallint": func(columnType gorm.ColumnType) (dataType string) { return "int64" },
|
||||
"mediumint": func(columnType gorm.ColumnType) (dataType string) { return "int64" },
|
||||
"bigint": func(columnType gorm.ColumnType) (dataType string) { return "int64" },
|
||||
"int": func(columnType gorm.ColumnType) (dataType string) { return "int64" },
|
||||
}
|
||||
// 要先于`ApplyBasic`执行
|
||||
g.WithDataTypeMap(dataMap)
|
||||
|
||||
// 自定义模型结体字段的标签
|
||||
// 将特定字段名的 json 标签加上`string`属性,即 MarshalJSON 时该字段由数字类型转成字符串类型
|
||||
jsonField := gen.FieldJSONTagWithNS(func(columnName string) (tagContent string) {
|
||||
toStringField := `id, `
|
||||
if strings.Contains(toStringField, columnName) {
|
||||
return columnName + ",string"
|
||||
}
|
||||
return columnName
|
||||
})
|
||||
// 将非默认字段名的字段定义为自动时间戳和软删除字段;
|
||||
// 自动时间戳默认字段名为:`updated_at`、`created_at, 表字段数据类型为: INT 或 DATETIME
|
||||
// 软删除默认字段名为:`deleted_at`, 表字段数据类型为: DATETIME
|
||||
idField := gen.FieldGORMTag("id", func(tag field.GormTag) field.GormTag {
|
||||
return tag.Append("primary_key")
|
||||
})
|
||||
autoUpdateTimeField := gen.FieldGORMTag("updated_at", func(tag field.GormTag) field.GormTag {
|
||||
return tag.Append("autoUpdateTime")
|
||||
})
|
||||
autoCreateTimeField := gen.FieldGORMTag("created_at", func(tag field.GormTag) field.GormTag {
|
||||
return tag.Append("autoCreateTime")
|
||||
})
|
||||
softDeleteField := gen.FieldType("delete_at", "gorm.DeletedAt")
|
||||
versionField := gen.FieldType("version", "optimisticlock.Version")
|
||||
// 模型自定义选项组
|
||||
fieldOpts := []gen.ModelOpt{jsonField, idField, autoUpdateTimeField, autoCreateTimeField, softDeleteField, versionField}
|
||||
|
||||
// 创建全部模型文件, 并覆盖前面创建的同名模型
|
||||
allModel := g.GenerateAllTable(fieldOpts...)
|
||||
|
||||
g.ApplyBasic(allModel...)
|
||||
|
||||
g.Execute()
|
||||
}
|
35
app/auth/api/model/mysql/model/sca_auth_menu.gen.go
Normal file
35
app/auth/api/model/mysql/model/sca_auth_menu.gen.go
Normal file
@@ -0,0 +1,35 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
const TableNameScaAuthMenu = "sca_auth_menu"
|
||||
|
||||
// ScaAuthMenu mapped from table <sca_auth_menu>
|
||||
type ScaAuthMenu struct {
|
||||
ID int64 `gorm:"column:id;type:bigint;primaryKey;autoIncrement:true;comment:主键ID;primary_key" json:"id,string"` // 主键ID
|
||||
MenuName string `gorm:"column:menu_name;type:varchar(64);comment:名称" json:"menu_name"` // 名称
|
||||
ParentID int64 `gorm:"column:parent_id;type:bigint;comment:父ID" json:"parent_id"` // 父ID
|
||||
Type int64 `gorm:"column:type;type:tinyint;comment:类型" json:"type"` // 类型
|
||||
Path string `gorm:"column:path;type:varchar(30);comment:路径" json:"path"` // 路径
|
||||
Status int64 `gorm:"column:status;type:tinyint;comment:状态 0 启用 1 停用" json:"status"` // 状态 0 启用 1 停用
|
||||
Icon string `gorm:"column:icon;type:varchar(128);comment:图标" json:"icon"` // 图标
|
||||
MenuKey string `gorm:"column:menu_key;type:varchar(64);comment:关键字" json:"menu_key"` // 关键字
|
||||
Order_ int64 `gorm:"column:order;type:int;comment:排序" json:"order"` // 排序
|
||||
CreatedAt time.Time `gorm:"column:created_at;type:timestamp;autoCreateTime;comment:创建时间" json:"created_at"` // 创建时间
|
||||
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp;autoUpdateTime;comment:更新时间" json:"updated_at"` // 更新时间
|
||||
Remark string `gorm:"column:remark;type:varchar(255);comment:备注 描述" json:"remark"` // 备注 描述
|
||||
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:timestamp;comment:删除时间" json:"deleted_at"` // 删除时间
|
||||
}
|
||||
|
||||
// TableName ScaAuthMenu's table name
|
||||
func (*ScaAuthMenu) TableName() string {
|
||||
return TableNameScaAuthMenu
|
||||
}
|
@@ -0,0 +1,24 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package model
|
||||
|
||||
const TableNameScaAuthPermissionRule = "sca_auth_permission_rule"
|
||||
|
||||
// ScaAuthPermissionRule mapped from table <sca_auth_permission_rule>
|
||||
type ScaAuthPermissionRule struct {
|
||||
ID int64 `gorm:"column:id;type:int;primaryKey;autoIncrement:true;primary_key" json:"id,string"`
|
||||
Ptype string `gorm:"column:ptype;type:varchar(100);uniqueIndex:idx_sca_auth_permission_rule,priority:1;index:IDX_sca_auth_permission_rule_ptype,priority:1" json:"ptype"`
|
||||
V0 string `gorm:"column:v0;type:varchar(100);uniqueIndex:idx_sca_auth_permission_rule,priority:2;index:IDX_sca_auth_permission_rule_v0,priority:1" json:"v0"`
|
||||
V1 string `gorm:"column:v1;type:varchar(100);uniqueIndex:idx_sca_auth_permission_rule,priority:3;index:IDX_sca_auth_permission_rule_v1,priority:1" json:"v1"`
|
||||
V2 string `gorm:"column:v2;type:varchar(100);uniqueIndex:idx_sca_auth_permission_rule,priority:4;index:IDX_sca_auth_permission_rule_v2,priority:1" json:"v2"`
|
||||
V3 string `gorm:"column:v3;type:varchar(100);uniqueIndex:idx_sca_auth_permission_rule,priority:5;index:IDX_sca_auth_permission_rule_v3,priority:1" json:"v3"`
|
||||
V4 string `gorm:"column:v4;type:varchar(100);uniqueIndex:idx_sca_auth_permission_rule,priority:6;index:IDX_sca_auth_permission_rule_v4,priority:1" json:"v4"`
|
||||
V5 string `gorm:"column:v5;type:varchar(100);uniqueIndex:idx_sca_auth_permission_rule,priority:7;index:IDX_sca_auth_permission_rule_v5,priority:1" json:"v5"`
|
||||
}
|
||||
|
||||
// TableName ScaAuthPermissionRule's table name
|
||||
func (*ScaAuthPermissionRule) TableName() string {
|
||||
return TableNameScaAuthPermissionRule
|
||||
}
|
28
app/auth/api/model/mysql/model/sca_auth_role.gen.go
Normal file
28
app/auth/api/model/mysql/model/sca_auth_role.gen.go
Normal file
@@ -0,0 +1,28 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
const TableNameScaAuthRole = "sca_auth_role"
|
||||
|
||||
// ScaAuthRole mapped from table <sca_auth_role>
|
||||
type ScaAuthRole struct {
|
||||
ID int64 `gorm:"column:id;type:bigint;primaryKey;autoIncrement:true;comment:主键ID;primary_key" json:"id,string"` // 主键ID
|
||||
RoleName string `gorm:"column:role_name;type:varchar(32);not null;comment:角色名称" json:"role_name"` // 角色名称
|
||||
RoleKey string `gorm:"column:role_key;type:varchar(64);not null;comment:角色关键字" json:"role_key"` // 角色关键字
|
||||
CreatedAt time.Time `gorm:"column:created_at;type:timestamp;autoCreateTime;comment:创建时间" json:"created_at"` // 创建时间
|
||||
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp;autoUpdateTime;comment:更新时间" json:"updated_at"` // 更新时间
|
||||
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:timestamp;comment:删除时间" json:"deleted_at"` // 删除时间
|
||||
}
|
||||
|
||||
// TableName ScaAuthRole's table name
|
||||
func (*ScaAuthRole) TableName() string {
|
||||
return TableNameScaAuthRole
|
||||
}
|
39
app/auth/api/model/mysql/model/sca_auth_user.gen.go
Normal file
39
app/auth/api/model/mysql/model/sca_auth_user.gen.go
Normal file
@@ -0,0 +1,39 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
const TableNameScaAuthUser = "sca_auth_user"
|
||||
|
||||
// ScaAuthUser mapped from table <sca_auth_user>
|
||||
type ScaAuthUser struct {
|
||||
ID int64 `gorm:"column:id;type:bigint;primaryKey;autoIncrement:true;uniqueIndex:id,priority:1;comment:自增ID;primary_key" json:"id,string"` // 自增ID
|
||||
UID string `gorm:"column:uid;type:varchar(50);not null;uniqueIndex:uid,priority:1;comment:唯一ID" json:"uid"` // 唯一ID
|
||||
Username string `gorm:"column:username;type:varchar(32);comment:用户名" json:"username"` // 用户名
|
||||
Nickname string `gorm:"column:nickname;type:varchar(32);comment:昵称" json:"nickname"` // 昵称
|
||||
Email string `gorm:"column:email;type:varchar(32);comment:邮箱" json:"email"` // 邮箱
|
||||
Phone string `gorm:"column:phone;type:varchar(32);comment:电话" json:"phone"` // 电话
|
||||
Password string `gorm:"column:password;type:varchar(64);comment:密码" json:"password"` // 密码
|
||||
Gender int64 `gorm:"column:gender;type:tinyint;comment:性别" json:"gender"` // 性别
|
||||
Avatar string `gorm:"column:avatar;type:longtext;comment:头像" json:"avatar"` // 头像
|
||||
Status int64 `gorm:"column:status;type:tinyint;comment:状态 0 正常 1 封禁" json:"status"` // 状态 0 正常 1 封禁
|
||||
Introduce string `gorm:"column:introduce;type:varchar(255);comment:介绍" json:"introduce"` // 介绍
|
||||
CreatedAt time.Time `gorm:"column:created_at;type:timestamp;autoCreateTime;comment:创建时间" json:"created_at"` // 创建时间
|
||||
Blog string `gorm:"column:blog;type:varchar(30);comment:博客" json:"blog"` // 博客
|
||||
Location string `gorm:"column:location;type:varchar(50);comment:地址" json:"location"` // 地址
|
||||
Company string `gorm:"column:company;type:varchar(50);comment:公司" json:"company"` // 公司
|
||||
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp;autoUpdateTime;comment:更新时间" json:"updated_at"` // 更新时间
|
||||
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:timestamp;comment:删除时间" json:"deleted_at"` // 删除时间
|
||||
}
|
||||
|
||||
// TableName ScaAuthUser's table name
|
||||
func (*ScaAuthUser) TableName() string {
|
||||
return TableNameScaAuthUser
|
||||
}
|
39
app/auth/api/model/mysql/model/sca_auth_user_device.gen.go
Normal file
39
app/auth/api/model/mysql/model/sca_auth_user_device.gen.go
Normal file
@@ -0,0 +1,39 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
const TableNameScaAuthUserDevice = "sca_auth_user_device"
|
||||
|
||||
// ScaAuthUserDevice mapped from table <sca_auth_user_device>
|
||||
type ScaAuthUserDevice struct {
|
||||
ID int64 `gorm:"column:id;type:bigint;primaryKey;autoIncrement:true;comment:主键ID;primary_key" json:"id,string"` // 主键ID
|
||||
UserID string `gorm:"column:user_id;type:varchar(20);not null;comment:用户ID" json:"user_id"` // 用户ID
|
||||
IP string `gorm:"column:ip;type:varchar(20);comment:登录IP" json:"ip"` // 登录IP
|
||||
Location string `gorm:"column:location;type:varchar(20);comment:地址" json:"location"` // 地址
|
||||
Agent string `gorm:"column:agent;type:varchar(255);comment:设备信息" json:"agent"` // 设备信息
|
||||
CreatedAt time.Time `gorm:"column:created_at;type:timestamp;autoCreateTime;comment:创建时间" json:"created_at"` // 创建时间
|
||||
Browser string `gorm:"column:browser;type:varchar(20);comment:浏览器" json:"browser"` // 浏览器
|
||||
OperatingSystem string `gorm:"column:operating_system;type:varchar(20);comment:操作系统" json:"operating_system"` // 操作系统
|
||||
BrowserVersion string `gorm:"column:browser_version;type:varchar(20);comment:浏览器版本" json:"browser_version"` // 浏览器版本
|
||||
Mobile int64 `gorm:"column:mobile;type:tinyint(1);comment:是否为手机 0否1是" json:"mobile"` // 是否为手机 0否1是
|
||||
Bot int64 `gorm:"column:bot;type:tinyint(1);comment:是否为bot 0否1是" json:"bot"` // 是否为bot 0否1是
|
||||
Mozilla string `gorm:"column:mozilla;type:varchar(10);comment:火狐版本" json:"mozilla"` // 火狐版本
|
||||
Platform string `gorm:"column:platform;type:varchar(20);comment:平台" json:"platform"` // 平台
|
||||
EngineName string `gorm:"column:engine_name;type:varchar(20);comment:引擎名称" json:"engine_name"` // 引擎名称
|
||||
EngineVersion string `gorm:"column:engine_version;type:varchar(20);comment:引擎版本" json:"engine_version"` // 引擎版本
|
||||
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp;autoUpdateTime;comment:更新时间" json:"updated_at"` // 更新时间
|
||||
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:timestamp;comment:删除时间" json:"deleted_at"` // 删除时间
|
||||
}
|
||||
|
||||
// TableName ScaAuthUserDevice's table name
|
||||
func (*ScaAuthUserDevice) TableName() string {
|
||||
return TableNameScaAuthUserDevice
|
||||
}
|
30
app/auth/api/model/mysql/model/sca_auth_user_social.gen.go
Normal file
30
app/auth/api/model/mysql/model/sca_auth_user_social.gen.go
Normal file
@@ -0,0 +1,30 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
const TableNameScaAuthUserSocial = "sca_auth_user_social"
|
||||
|
||||
// ScaAuthUserSocial mapped from table <sca_auth_user_social>
|
||||
type ScaAuthUserSocial struct {
|
||||
ID int64 `gorm:"column:id;type:bigint;primaryKey;autoIncrement:true;comment:主键ID;primary_key" json:"id,string"` // 主键ID
|
||||
UserID string `gorm:"column:user_id;type:varchar(50);not null;comment:用户ID" json:"user_id"` // 用户ID
|
||||
OpenID string `gorm:"column:open_id;type:varchar(50);not null;comment:第三方用户的 open id" json:"open_id"` // 第三方用户的 open id
|
||||
Source string `gorm:"column:source;type:varchar(10);comment:第三方用户来源" json:"source"` // 第三方用户来源
|
||||
Status int64 `gorm:"column:status;type:bigint;comment:状态 0正常 1 封禁" json:"status"` // 状态 0正常 1 封禁
|
||||
CreatedAt time.Time `gorm:"column:created_at;type:timestamp;autoCreateTime;comment:创建时间" json:"created_at"` // 创建时间
|
||||
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp;autoUpdateTime;comment:更新时间" json:"updated_at"` // 更新时间
|
||||
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:timestamp;comment:删除时间" json:"deleted_at"` // 删除时间
|
||||
}
|
||||
|
||||
// TableName ScaAuthUserSocial's table name
|
||||
func (*ScaAuthUserSocial) TableName() string {
|
||||
return TableNameScaAuthUserSocial
|
||||
}
|
33
app/auth/api/model/mysql/model/sca_user_level.gen.go
Normal file
33
app/auth/api/model/mysql/model/sca_user_level.gen.go
Normal file
@@ -0,0 +1,33 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
const TableNameScaUserLevel = "sca_user_level"
|
||||
|
||||
// ScaUserLevel mapped from table <sca_user_level>
|
||||
type ScaUserLevel struct {
|
||||
ID int64 `gorm:"column:id;type:bigint;primaryKey;comment:主键;primary_key" json:"id,string"` // 主键
|
||||
UserID string `gorm:"column:user_id;type:varchar(50);comment:用户Id" json:"user_id"` // 用户Id
|
||||
LevelType int64 `gorm:"column:level_type;type:tinyint unsigned;comment:等级类型" json:"level_type"` // 等级类型
|
||||
Level int64 `gorm:"column:level;type:int;comment:等级" json:"level"` // 等级
|
||||
LevelName string `gorm:"column:level_name;type:varchar(50);comment:等级名称" json:"level_name"` // 等级名称
|
||||
ExpStart int64 `gorm:"column:exp_start;type:bigint;comment:开始经验值" json:"exp_start"` // 开始经验值
|
||||
ExpEnd int64 `gorm:"column:exp_end;type:bigint;comment:结束经验值" json:"exp_end"` // 结束经验值
|
||||
Description string `gorm:"column:description;type:text;comment:等级描述" json:"description"` // 等级描述
|
||||
CreatedAt *time.Time `gorm:"column:created_at;type:timestamp;default:CURRENT_TIMESTAMP;autoCreateTime;comment:创建时间" json:"created_at"` // 创建时间
|
||||
UpdatedAt *time.Time `gorm:"column:updated_at;type:timestamp;default:CURRENT_TIMESTAMP;autoUpdateTime;comment:更新时间" json:"updated_at"` // 更新时间
|
||||
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:timestamp;comment:删除时间" json:"deleted_at"` // 删除时间
|
||||
}
|
||||
|
||||
// TableName ScaUserLevel's table name
|
||||
func (*ScaUserLevel) TableName() string {
|
||||
return TableNameScaUserLevel
|
||||
}
|
31
app/auth/api/model/mysql/model/sca_user_message.gen.go
Normal file
31
app/auth/api/model/mysql/model/sca_user_message.gen.go
Normal file
@@ -0,0 +1,31 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
const TableNameScaUserMessage = "sca_user_message"
|
||||
|
||||
// ScaUserMessage mapped from table <sca_user_message>
|
||||
type ScaUserMessage struct {
|
||||
ID int64 `gorm:"column:id;type:bigint;primaryKey;autoIncrement:true;comment:主键;primary_key" json:"id,string"` // 主键
|
||||
TopicID string `gorm:"column:topic_id;type:varchar(50);comment:话题Id" json:"topic_id"` // 话题Id
|
||||
FromID string `gorm:"column:from_id;type:varchar(50);comment:来自人" json:"from_id"` // 来自人
|
||||
ToID string `gorm:"column:to_id;type:varchar(50);comment:送达人" json:"to_id"` // 送达人
|
||||
Content string `gorm:"column:content;type:text;comment:消息内容" json:"content"` // 消息内容
|
||||
IsRead int64 `gorm:"column:is_read;type:tinyint;comment:是否已读" json:"is_read"` // 是否已读
|
||||
CreatedAt time.Time `gorm:"column:created_at;type:timestamp;autoCreateTime;comment:创建时间" json:"created_at"` // 创建时间
|
||||
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp;autoUpdateTime;comment:更新时间" json:"updated_at"` // 更新时间
|
||||
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:timestamp;comment:删除时间" json:"deleted_at"` // 删除时间
|
||||
}
|
||||
|
||||
// TableName ScaUserMessage's table name
|
||||
func (*ScaUserMessage) TableName() string {
|
||||
return TableNameScaUserMessage
|
||||
}
|
64
app/auth/api/model/mysql/mysql.go
Normal file
64
app/auth/api/model/mysql/mysql.go
Normal file
@@ -0,0 +1,64 @@
|
||||
package mysql
|
||||
|
||||
import (
|
||||
"github.com/asjdf/gorm-cache/cache"
|
||||
"github.com/asjdf/gorm-cache/config"
|
||||
"github.com/asjdf/gorm-cache/storage"
|
||||
"github.com/redis/go-redis/v9"
|
||||
"gorm.io/driver/mysql"
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/logger"
|
||||
"log"
|
||||
"os"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/model/mysql/query"
|
||||
"time"
|
||||
)
|
||||
|
||||
func NewMySQL(url string, maxOpenConn int, maxIdleConn int, client *redis.Client) (*gorm.DB, *query.Query) {
|
||||
db, err := gorm.Open(mysql.Open(url), &gorm.Config{
|
||||
SkipDefaultTransaction: true,
|
||||
PrepareStmt: true,
|
||||
Logger: logger.New(
|
||||
log.New(os.Stdout, "\r\n", log.LstdFlags),
|
||||
logger.Config{
|
||||
SlowThreshold: time.Second, // 慢sql日志
|
||||
LogLevel: logger.Error, // 级别
|
||||
Colorful: true, // 颜色
|
||||
IgnoreRecordNotFoundError: true, // 忽略RecordNotFoundError
|
||||
ParameterizedQueries: true, // 格式化SQL语句
|
||||
}),
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
sqlDB, err := db.DB()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
sqlDB.SetMaxOpenConns(maxOpenConn)
|
||||
sqlDB.SetMaxIdleConns(maxIdleConn)
|
||||
useDB := query.Use(db)
|
||||
// cache
|
||||
gormCache, err := cache.NewGorm2Cache(&config.CacheConfig{
|
||||
CacheLevel: config.CacheLevelAll,
|
||||
CacheStorage: storage.NewRedis(&storage.RedisStoreConfig{
|
||||
KeyPrefix: "cache",
|
||||
Client: client,
|
||||
}),
|
||||
InvalidateWhenUpdate: true, // when you create/update/delete objects, invalidate cache
|
||||
CacheTTL: 10000, // 5000 ms
|
||||
CacheMaxItemCnt: 0, // if length of objects retrieved one single time
|
||||
AsyncWrite: true, // async write to cache
|
||||
DebugMode: false,
|
||||
DisableCachePenetrationProtect: true, // disable cache penetration protect
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
err = db.Use(gormCache)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return db, useDB
|
||||
}
|
159
app/auth/api/model/mysql/query/gen.go
Normal file
159
app/auth/api/model/mysql/query/gen.go
Normal file
@@ -0,0 +1,159 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package query
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
|
||||
"gorm.io/gorm"
|
||||
|
||||
"gorm.io/gen"
|
||||
|
||||
"gorm.io/plugin/dbresolver"
|
||||
)
|
||||
|
||||
var (
|
||||
Q = new(Query)
|
||||
ScaAuthMenu *scaAuthMenu
|
||||
ScaAuthPermissionRule *scaAuthPermissionRule
|
||||
ScaAuthRole *scaAuthRole
|
||||
ScaAuthUser *scaAuthUser
|
||||
ScaAuthUserDevice *scaAuthUserDevice
|
||||
ScaAuthUserSocial *scaAuthUserSocial
|
||||
ScaUserLevel *scaUserLevel
|
||||
ScaUserMessage *scaUserMessage
|
||||
)
|
||||
|
||||
func SetDefault(db *gorm.DB, opts ...gen.DOOption) {
|
||||
*Q = *Use(db, opts...)
|
||||
ScaAuthMenu = &Q.ScaAuthMenu
|
||||
ScaAuthPermissionRule = &Q.ScaAuthPermissionRule
|
||||
ScaAuthRole = &Q.ScaAuthRole
|
||||
ScaAuthUser = &Q.ScaAuthUser
|
||||
ScaAuthUserDevice = &Q.ScaAuthUserDevice
|
||||
ScaAuthUserSocial = &Q.ScaAuthUserSocial
|
||||
ScaUserLevel = &Q.ScaUserLevel
|
||||
ScaUserMessage = &Q.ScaUserMessage
|
||||
}
|
||||
|
||||
func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
|
||||
return &Query{
|
||||
db: db,
|
||||
ScaAuthMenu: newScaAuthMenu(db, opts...),
|
||||
ScaAuthPermissionRule: newScaAuthPermissionRule(db, opts...),
|
||||
ScaAuthRole: newScaAuthRole(db, opts...),
|
||||
ScaAuthUser: newScaAuthUser(db, opts...),
|
||||
ScaAuthUserDevice: newScaAuthUserDevice(db, opts...),
|
||||
ScaAuthUserSocial: newScaAuthUserSocial(db, opts...),
|
||||
ScaUserLevel: newScaUserLevel(db, opts...),
|
||||
ScaUserMessage: newScaUserMessage(db, opts...),
|
||||
}
|
||||
}
|
||||
|
||||
type Query struct {
|
||||
db *gorm.DB
|
||||
|
||||
ScaAuthMenu scaAuthMenu
|
||||
ScaAuthPermissionRule scaAuthPermissionRule
|
||||
ScaAuthRole scaAuthRole
|
||||
ScaAuthUser scaAuthUser
|
||||
ScaAuthUserDevice scaAuthUserDevice
|
||||
ScaAuthUserSocial scaAuthUserSocial
|
||||
ScaUserLevel scaUserLevel
|
||||
ScaUserMessage scaUserMessage
|
||||
}
|
||||
|
||||
func (q *Query) Available() bool { return q.db != nil }
|
||||
|
||||
func (q *Query) clone(db *gorm.DB) *Query {
|
||||
return &Query{
|
||||
db: db,
|
||||
ScaAuthMenu: q.ScaAuthMenu.clone(db),
|
||||
ScaAuthPermissionRule: q.ScaAuthPermissionRule.clone(db),
|
||||
ScaAuthRole: q.ScaAuthRole.clone(db),
|
||||
ScaAuthUser: q.ScaAuthUser.clone(db),
|
||||
ScaAuthUserDevice: q.ScaAuthUserDevice.clone(db),
|
||||
ScaAuthUserSocial: q.ScaAuthUserSocial.clone(db),
|
||||
ScaUserLevel: q.ScaUserLevel.clone(db),
|
||||
ScaUserMessage: q.ScaUserMessage.clone(db),
|
||||
}
|
||||
}
|
||||
|
||||
func (q *Query) ReadDB() *Query {
|
||||
return q.ReplaceDB(q.db.Clauses(dbresolver.Read))
|
||||
}
|
||||
|
||||
func (q *Query) WriteDB() *Query {
|
||||
return q.ReplaceDB(q.db.Clauses(dbresolver.Write))
|
||||
}
|
||||
|
||||
func (q *Query) ReplaceDB(db *gorm.DB) *Query {
|
||||
return &Query{
|
||||
db: db,
|
||||
ScaAuthMenu: q.ScaAuthMenu.replaceDB(db),
|
||||
ScaAuthPermissionRule: q.ScaAuthPermissionRule.replaceDB(db),
|
||||
ScaAuthRole: q.ScaAuthRole.replaceDB(db),
|
||||
ScaAuthUser: q.ScaAuthUser.replaceDB(db),
|
||||
ScaAuthUserDevice: q.ScaAuthUserDevice.replaceDB(db),
|
||||
ScaAuthUserSocial: q.ScaAuthUserSocial.replaceDB(db),
|
||||
ScaUserLevel: q.ScaUserLevel.replaceDB(db),
|
||||
ScaUserMessage: q.ScaUserMessage.replaceDB(db),
|
||||
}
|
||||
}
|
||||
|
||||
type queryCtx struct {
|
||||
ScaAuthMenu IScaAuthMenuDo
|
||||
ScaAuthPermissionRule IScaAuthPermissionRuleDo
|
||||
ScaAuthRole IScaAuthRoleDo
|
||||
ScaAuthUser IScaAuthUserDo
|
||||
ScaAuthUserDevice IScaAuthUserDeviceDo
|
||||
ScaAuthUserSocial IScaAuthUserSocialDo
|
||||
ScaUserLevel IScaUserLevelDo
|
||||
ScaUserMessage IScaUserMessageDo
|
||||
}
|
||||
|
||||
func (q *Query) WithContext(ctx context.Context) *queryCtx {
|
||||
return &queryCtx{
|
||||
ScaAuthMenu: q.ScaAuthMenu.WithContext(ctx),
|
||||
ScaAuthPermissionRule: q.ScaAuthPermissionRule.WithContext(ctx),
|
||||
ScaAuthRole: q.ScaAuthRole.WithContext(ctx),
|
||||
ScaAuthUser: q.ScaAuthUser.WithContext(ctx),
|
||||
ScaAuthUserDevice: q.ScaAuthUserDevice.WithContext(ctx),
|
||||
ScaAuthUserSocial: q.ScaAuthUserSocial.WithContext(ctx),
|
||||
ScaUserLevel: q.ScaUserLevel.WithContext(ctx),
|
||||
ScaUserMessage: q.ScaUserMessage.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (q *Query) Transaction(fc func(tx *Query) error, opts ...*sql.TxOptions) error {
|
||||
return q.db.Transaction(func(tx *gorm.DB) error { return fc(q.clone(tx)) }, opts...)
|
||||
}
|
||||
|
||||
func (q *Query) Begin(opts ...*sql.TxOptions) *QueryTx {
|
||||
tx := q.db.Begin(opts...)
|
||||
return &QueryTx{Query: q.clone(tx), Error: tx.Error}
|
||||
}
|
||||
|
||||
type QueryTx struct {
|
||||
*Query
|
||||
Error error
|
||||
}
|
||||
|
||||
func (q *QueryTx) Commit() error {
|
||||
return q.db.Commit().Error
|
||||
}
|
||||
|
||||
func (q *QueryTx) Rollback() error {
|
||||
return q.db.Rollback().Error
|
||||
}
|
||||
|
||||
func (q *QueryTx) SavePoint(name string) error {
|
||||
return q.db.SavePoint(name).Error
|
||||
}
|
||||
|
||||
func (q *QueryTx) RollbackTo(name string) error {
|
||||
return q.db.RollbackTo(name).Error
|
||||
}
|
427
app/auth/api/model/mysql/query/sca_auth_menu.gen.go
Normal file
427
app/auth/api/model/mysql/query/sca_auth_menu.gen.go
Normal file
@@ -0,0 +1,427 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package query
|
||||
|
||||
import (
|
||||
"context"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/model/mysql/model"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
||||
|
||||
"gorm.io/plugin/dbresolver"
|
||||
)
|
||||
|
||||
func newScaAuthMenu(db *gorm.DB, opts ...gen.DOOption) scaAuthMenu {
|
||||
_scaAuthMenu := scaAuthMenu{}
|
||||
|
||||
_scaAuthMenu.scaAuthMenuDo.UseDB(db, opts...)
|
||||
_scaAuthMenu.scaAuthMenuDo.UseModel(&model.ScaAuthMenu{})
|
||||
|
||||
tableName := _scaAuthMenu.scaAuthMenuDo.TableName()
|
||||
_scaAuthMenu.ALL = field.NewAsterisk(tableName)
|
||||
_scaAuthMenu.ID = field.NewInt64(tableName, "id")
|
||||
_scaAuthMenu.MenuName = field.NewString(tableName, "menu_name")
|
||||
_scaAuthMenu.ParentID = field.NewInt64(tableName, "parent_id")
|
||||
_scaAuthMenu.Type = field.NewInt64(tableName, "type")
|
||||
_scaAuthMenu.Path = field.NewString(tableName, "path")
|
||||
_scaAuthMenu.Status = field.NewInt64(tableName, "status")
|
||||
_scaAuthMenu.Icon = field.NewString(tableName, "icon")
|
||||
_scaAuthMenu.MenuKey = field.NewString(tableName, "menu_key")
|
||||
_scaAuthMenu.Order_ = field.NewInt64(tableName, "order")
|
||||
_scaAuthMenu.CreatedAt = field.NewTime(tableName, "created_at")
|
||||
_scaAuthMenu.UpdatedAt = field.NewTime(tableName, "updated_at")
|
||||
_scaAuthMenu.Remark = field.NewString(tableName, "remark")
|
||||
_scaAuthMenu.DeletedAt = field.NewField(tableName, "deleted_at")
|
||||
|
||||
_scaAuthMenu.fillFieldMap()
|
||||
|
||||
return _scaAuthMenu
|
||||
}
|
||||
|
||||
type scaAuthMenu struct {
|
||||
scaAuthMenuDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Int64 // 主键ID
|
||||
MenuName field.String // 名称
|
||||
ParentID field.Int64 // 父ID
|
||||
Type field.Int64 // 类型
|
||||
Path field.String // 路径
|
||||
Status field.Int64 // 状态 0 启用 1 停用
|
||||
Icon field.String // 图标
|
||||
MenuKey field.String // 关键字
|
||||
Order_ field.Int64 // 排序
|
||||
CreatedAt field.Time // 创建时间
|
||||
UpdatedAt field.Time // 更新时间
|
||||
Remark field.String // 备注 描述
|
||||
DeletedAt field.Field // 删除时间
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (s scaAuthMenu) Table(newTableName string) *scaAuthMenu {
|
||||
s.scaAuthMenuDo.UseTable(newTableName)
|
||||
return s.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (s scaAuthMenu) As(alias string) *scaAuthMenu {
|
||||
s.scaAuthMenuDo.DO = *(s.scaAuthMenuDo.As(alias).(*gen.DO))
|
||||
return s.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (s *scaAuthMenu) updateTableName(table string) *scaAuthMenu {
|
||||
s.ALL = field.NewAsterisk(table)
|
||||
s.ID = field.NewInt64(table, "id")
|
||||
s.MenuName = field.NewString(table, "menu_name")
|
||||
s.ParentID = field.NewInt64(table, "parent_id")
|
||||
s.Type = field.NewInt64(table, "type")
|
||||
s.Path = field.NewString(table, "path")
|
||||
s.Status = field.NewInt64(table, "status")
|
||||
s.Icon = field.NewString(table, "icon")
|
||||
s.MenuKey = field.NewString(table, "menu_key")
|
||||
s.Order_ = field.NewInt64(table, "order")
|
||||
s.CreatedAt = field.NewTime(table, "created_at")
|
||||
s.UpdatedAt = field.NewTime(table, "updated_at")
|
||||
s.Remark = field.NewString(table, "remark")
|
||||
s.DeletedAt = field.NewField(table, "deleted_at")
|
||||
|
||||
s.fillFieldMap()
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *scaAuthMenu) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
_f, ok := s.fieldMap[fieldName]
|
||||
if !ok || _f == nil {
|
||||
return nil, false
|
||||
}
|
||||
_oe, ok := _f.(field.OrderExpr)
|
||||
return _oe, ok
|
||||
}
|
||||
|
||||
func (s *scaAuthMenu) fillFieldMap() {
|
||||
s.fieldMap = make(map[string]field.Expr, 13)
|
||||
s.fieldMap["id"] = s.ID
|
||||
s.fieldMap["menu_name"] = s.MenuName
|
||||
s.fieldMap["parent_id"] = s.ParentID
|
||||
s.fieldMap["type"] = s.Type
|
||||
s.fieldMap["path"] = s.Path
|
||||
s.fieldMap["status"] = s.Status
|
||||
s.fieldMap["icon"] = s.Icon
|
||||
s.fieldMap["menu_key"] = s.MenuKey
|
||||
s.fieldMap["order"] = s.Order_
|
||||
s.fieldMap["created_at"] = s.CreatedAt
|
||||
s.fieldMap["updated_at"] = s.UpdatedAt
|
||||
s.fieldMap["remark"] = s.Remark
|
||||
s.fieldMap["deleted_at"] = s.DeletedAt
|
||||
}
|
||||
|
||||
func (s scaAuthMenu) clone(db *gorm.DB) scaAuthMenu {
|
||||
s.scaAuthMenuDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return s
|
||||
}
|
||||
|
||||
func (s scaAuthMenu) replaceDB(db *gorm.DB) scaAuthMenu {
|
||||
s.scaAuthMenuDo.ReplaceDB(db)
|
||||
return s
|
||||
}
|
||||
|
||||
type scaAuthMenuDo struct{ gen.DO }
|
||||
|
||||
type IScaAuthMenuDo interface {
|
||||
gen.SubQuery
|
||||
Debug() IScaAuthMenuDo
|
||||
WithContext(ctx context.Context) IScaAuthMenuDo
|
||||
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
|
||||
ReplaceDB(db *gorm.DB)
|
||||
ReadDB() IScaAuthMenuDo
|
||||
WriteDB() IScaAuthMenuDo
|
||||
As(alias string) gen.Dao
|
||||
Session(config *gorm.Session) IScaAuthMenuDo
|
||||
Columns(cols ...field.Expr) gen.Columns
|
||||
Clauses(conds ...clause.Expression) IScaAuthMenuDo
|
||||
Not(conds ...gen.Condition) IScaAuthMenuDo
|
||||
Or(conds ...gen.Condition) IScaAuthMenuDo
|
||||
Select(conds ...field.Expr) IScaAuthMenuDo
|
||||
Where(conds ...gen.Condition) IScaAuthMenuDo
|
||||
Order(conds ...field.Expr) IScaAuthMenuDo
|
||||
Distinct(cols ...field.Expr) IScaAuthMenuDo
|
||||
Omit(cols ...field.Expr) IScaAuthMenuDo
|
||||
Join(table schema.Tabler, on ...field.Expr) IScaAuthMenuDo
|
||||
LeftJoin(table schema.Tabler, on ...field.Expr) IScaAuthMenuDo
|
||||
RightJoin(table schema.Tabler, on ...field.Expr) IScaAuthMenuDo
|
||||
Group(cols ...field.Expr) IScaAuthMenuDo
|
||||
Having(conds ...gen.Condition) IScaAuthMenuDo
|
||||
Limit(limit int) IScaAuthMenuDo
|
||||
Offset(offset int) IScaAuthMenuDo
|
||||
Count() (count int64, err error)
|
||||
Scopes(funcs ...func(gen.Dao) gen.Dao) IScaAuthMenuDo
|
||||
Unscoped() IScaAuthMenuDo
|
||||
Create(values ...*model.ScaAuthMenu) error
|
||||
CreateInBatches(values []*model.ScaAuthMenu, batchSize int) error
|
||||
Save(values ...*model.ScaAuthMenu) error
|
||||
First() (*model.ScaAuthMenu, error)
|
||||
Take() (*model.ScaAuthMenu, error)
|
||||
Last() (*model.ScaAuthMenu, error)
|
||||
Find() ([]*model.ScaAuthMenu, error)
|
||||
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.ScaAuthMenu, err error)
|
||||
FindInBatches(result *[]*model.ScaAuthMenu, batchSize int, fc func(tx gen.Dao, batch int) error) error
|
||||
Pluck(column field.Expr, dest interface{}) error
|
||||
Delete(...*model.ScaAuthMenu) (info gen.ResultInfo, err error)
|
||||
Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
||||
Updates(value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
||||
UpdateColumns(value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateFrom(q gen.SubQuery) gen.Dao
|
||||
Attrs(attrs ...field.AssignExpr) IScaAuthMenuDo
|
||||
Assign(attrs ...field.AssignExpr) IScaAuthMenuDo
|
||||
Joins(fields ...field.RelationField) IScaAuthMenuDo
|
||||
Preload(fields ...field.RelationField) IScaAuthMenuDo
|
||||
FirstOrInit() (*model.ScaAuthMenu, error)
|
||||
FirstOrCreate() (*model.ScaAuthMenu, error)
|
||||
FindByPage(offset int, limit int) (result []*model.ScaAuthMenu, count int64, err error)
|
||||
ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
|
||||
Scan(result interface{}) (err error)
|
||||
Returning(value interface{}, columns ...string) IScaAuthMenuDo
|
||||
UnderlyingDB() *gorm.DB
|
||||
schema.Tabler
|
||||
}
|
||||
|
||||
func (s scaAuthMenuDo) Debug() IScaAuthMenuDo {
|
||||
return s.withDO(s.DO.Debug())
|
||||
}
|
||||
|
||||
func (s scaAuthMenuDo) WithContext(ctx context.Context) IScaAuthMenuDo {
|
||||
return s.withDO(s.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (s scaAuthMenuDo) ReadDB() IScaAuthMenuDo {
|
||||
return s.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (s scaAuthMenuDo) WriteDB() IScaAuthMenuDo {
|
||||
return s.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (s scaAuthMenuDo) Session(config *gorm.Session) IScaAuthMenuDo {
|
||||
return s.withDO(s.DO.Session(config))
|
||||
}
|
||||
|
||||
func (s scaAuthMenuDo) Clauses(conds ...clause.Expression) IScaAuthMenuDo {
|
||||
return s.withDO(s.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (s scaAuthMenuDo) Returning(value interface{}, columns ...string) IScaAuthMenuDo {
|
||||
return s.withDO(s.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (s scaAuthMenuDo) Not(conds ...gen.Condition) IScaAuthMenuDo {
|
||||
return s.withDO(s.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (s scaAuthMenuDo) Or(conds ...gen.Condition) IScaAuthMenuDo {
|
||||
return s.withDO(s.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (s scaAuthMenuDo) Select(conds ...field.Expr) IScaAuthMenuDo {
|
||||
return s.withDO(s.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (s scaAuthMenuDo) Where(conds ...gen.Condition) IScaAuthMenuDo {
|
||||
return s.withDO(s.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (s scaAuthMenuDo) Order(conds ...field.Expr) IScaAuthMenuDo {
|
||||
return s.withDO(s.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (s scaAuthMenuDo) Distinct(cols ...field.Expr) IScaAuthMenuDo {
|
||||
return s.withDO(s.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (s scaAuthMenuDo) Omit(cols ...field.Expr) IScaAuthMenuDo {
|
||||
return s.withDO(s.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (s scaAuthMenuDo) Join(table schema.Tabler, on ...field.Expr) IScaAuthMenuDo {
|
||||
return s.withDO(s.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (s scaAuthMenuDo) LeftJoin(table schema.Tabler, on ...field.Expr) IScaAuthMenuDo {
|
||||
return s.withDO(s.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (s scaAuthMenuDo) RightJoin(table schema.Tabler, on ...field.Expr) IScaAuthMenuDo {
|
||||
return s.withDO(s.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (s scaAuthMenuDo) Group(cols ...field.Expr) IScaAuthMenuDo {
|
||||
return s.withDO(s.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (s scaAuthMenuDo) Having(conds ...gen.Condition) IScaAuthMenuDo {
|
||||
return s.withDO(s.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (s scaAuthMenuDo) Limit(limit int) IScaAuthMenuDo {
|
||||
return s.withDO(s.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (s scaAuthMenuDo) Offset(offset int) IScaAuthMenuDo {
|
||||
return s.withDO(s.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (s scaAuthMenuDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IScaAuthMenuDo {
|
||||
return s.withDO(s.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (s scaAuthMenuDo) Unscoped() IScaAuthMenuDo {
|
||||
return s.withDO(s.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (s scaAuthMenuDo) Create(values ...*model.ScaAuthMenu) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return s.DO.Create(values)
|
||||
}
|
||||
|
||||
func (s scaAuthMenuDo) CreateInBatches(values []*model.ScaAuthMenu, batchSize int) error {
|
||||
return s.DO.CreateInBatches(values, batchSize)
|
||||
}
|
||||
|
||||
// Save : !!! underlying implementation is different with GORM
|
||||
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
|
||||
func (s scaAuthMenuDo) Save(values ...*model.ScaAuthMenu) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return s.DO.Save(values)
|
||||
}
|
||||
|
||||
func (s scaAuthMenuDo) First() (*model.ScaAuthMenu, error) {
|
||||
if result, err := s.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.ScaAuthMenu), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s scaAuthMenuDo) Take() (*model.ScaAuthMenu, error) {
|
||||
if result, err := s.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.ScaAuthMenu), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s scaAuthMenuDo) Last() (*model.ScaAuthMenu, error) {
|
||||
if result, err := s.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.ScaAuthMenu), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s scaAuthMenuDo) Find() ([]*model.ScaAuthMenu, error) {
|
||||
result, err := s.DO.Find()
|
||||
return result.([]*model.ScaAuthMenu), err
|
||||
}
|
||||
|
||||
func (s scaAuthMenuDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.ScaAuthMenu, err error) {
|
||||
buf := make([]*model.ScaAuthMenu, 0, batchSize)
|
||||
err = s.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
|
||||
defer func() { results = append(results, buf...) }()
|
||||
return fc(tx, batch)
|
||||
})
|
||||
return results, err
|
||||
}
|
||||
|
||||
func (s scaAuthMenuDo) FindInBatches(result *[]*model.ScaAuthMenu, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return s.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (s scaAuthMenuDo) Attrs(attrs ...field.AssignExpr) IScaAuthMenuDo {
|
||||
return s.withDO(s.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (s scaAuthMenuDo) Assign(attrs ...field.AssignExpr) IScaAuthMenuDo {
|
||||
return s.withDO(s.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (s scaAuthMenuDo) Joins(fields ...field.RelationField) IScaAuthMenuDo {
|
||||
for _, _f := range fields {
|
||||
s = *s.withDO(s.DO.Joins(_f))
|
||||
}
|
||||
return &s
|
||||
}
|
||||
|
||||
func (s scaAuthMenuDo) Preload(fields ...field.RelationField) IScaAuthMenuDo {
|
||||
for _, _f := range fields {
|
||||
s = *s.withDO(s.DO.Preload(_f))
|
||||
}
|
||||
return &s
|
||||
}
|
||||
|
||||
func (s scaAuthMenuDo) FirstOrInit() (*model.ScaAuthMenu, error) {
|
||||
if result, err := s.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.ScaAuthMenu), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s scaAuthMenuDo) FirstOrCreate() (*model.ScaAuthMenu, error) {
|
||||
if result, err := s.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.ScaAuthMenu), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s scaAuthMenuDo) FindByPage(offset int, limit int) (result []*model.ScaAuthMenu, count int64, err error) {
|
||||
result, err = s.Offset(offset).Limit(limit).Find()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if size := len(result); 0 < limit && 0 < size && size < limit {
|
||||
count = int64(size + offset)
|
||||
return
|
||||
}
|
||||
|
||||
count, err = s.Offset(-1).Limit(-1).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (s scaAuthMenuDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||
count, err = s.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = s.Offset(offset).Limit(limit).Scan(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (s scaAuthMenuDo) Scan(result interface{}) (err error) {
|
||||
return s.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (s scaAuthMenuDo) Delete(models ...*model.ScaAuthMenu) (result gen.ResultInfo, err error) {
|
||||
return s.DO.Delete(models)
|
||||
}
|
||||
|
||||
func (s *scaAuthMenuDo) withDO(do gen.Dao) *scaAuthMenuDo {
|
||||
s.DO = *do.(*gen.DO)
|
||||
return s
|
||||
}
|
407
app/auth/api/model/mysql/query/sca_auth_permission_rule.gen.go
Normal file
407
app/auth/api/model/mysql/query/sca_auth_permission_rule.gen.go
Normal file
@@ -0,0 +1,407 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package query
|
||||
|
||||
import (
|
||||
"context"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/model/mysql/model"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
||||
|
||||
"gorm.io/plugin/dbresolver"
|
||||
)
|
||||
|
||||
func newScaAuthPermissionRule(db *gorm.DB, opts ...gen.DOOption) scaAuthPermissionRule {
|
||||
_scaAuthPermissionRule := scaAuthPermissionRule{}
|
||||
|
||||
_scaAuthPermissionRule.scaAuthPermissionRuleDo.UseDB(db, opts...)
|
||||
_scaAuthPermissionRule.scaAuthPermissionRuleDo.UseModel(&model.ScaAuthPermissionRule{})
|
||||
|
||||
tableName := _scaAuthPermissionRule.scaAuthPermissionRuleDo.TableName()
|
||||
_scaAuthPermissionRule.ALL = field.NewAsterisk(tableName)
|
||||
_scaAuthPermissionRule.ID = field.NewInt64(tableName, "id")
|
||||
_scaAuthPermissionRule.Ptype = field.NewString(tableName, "ptype")
|
||||
_scaAuthPermissionRule.V0 = field.NewString(tableName, "v0")
|
||||
_scaAuthPermissionRule.V1 = field.NewString(tableName, "v1")
|
||||
_scaAuthPermissionRule.V2 = field.NewString(tableName, "v2")
|
||||
_scaAuthPermissionRule.V3 = field.NewString(tableName, "v3")
|
||||
_scaAuthPermissionRule.V4 = field.NewString(tableName, "v4")
|
||||
_scaAuthPermissionRule.V5 = field.NewString(tableName, "v5")
|
||||
|
||||
_scaAuthPermissionRule.fillFieldMap()
|
||||
|
||||
return _scaAuthPermissionRule
|
||||
}
|
||||
|
||||
type scaAuthPermissionRule struct {
|
||||
scaAuthPermissionRuleDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Int64
|
||||
Ptype field.String
|
||||
V0 field.String
|
||||
V1 field.String
|
||||
V2 field.String
|
||||
V3 field.String
|
||||
V4 field.String
|
||||
V5 field.String
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (s scaAuthPermissionRule) Table(newTableName string) *scaAuthPermissionRule {
|
||||
s.scaAuthPermissionRuleDo.UseTable(newTableName)
|
||||
return s.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (s scaAuthPermissionRule) As(alias string) *scaAuthPermissionRule {
|
||||
s.scaAuthPermissionRuleDo.DO = *(s.scaAuthPermissionRuleDo.As(alias).(*gen.DO))
|
||||
return s.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (s *scaAuthPermissionRule) updateTableName(table string) *scaAuthPermissionRule {
|
||||
s.ALL = field.NewAsterisk(table)
|
||||
s.ID = field.NewInt64(table, "id")
|
||||
s.Ptype = field.NewString(table, "ptype")
|
||||
s.V0 = field.NewString(table, "v0")
|
||||
s.V1 = field.NewString(table, "v1")
|
||||
s.V2 = field.NewString(table, "v2")
|
||||
s.V3 = field.NewString(table, "v3")
|
||||
s.V4 = field.NewString(table, "v4")
|
||||
s.V5 = field.NewString(table, "v5")
|
||||
|
||||
s.fillFieldMap()
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *scaAuthPermissionRule) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
_f, ok := s.fieldMap[fieldName]
|
||||
if !ok || _f == nil {
|
||||
return nil, false
|
||||
}
|
||||
_oe, ok := _f.(field.OrderExpr)
|
||||
return _oe, ok
|
||||
}
|
||||
|
||||
func (s *scaAuthPermissionRule) fillFieldMap() {
|
||||
s.fieldMap = make(map[string]field.Expr, 8)
|
||||
s.fieldMap["id"] = s.ID
|
||||
s.fieldMap["ptype"] = s.Ptype
|
||||
s.fieldMap["v0"] = s.V0
|
||||
s.fieldMap["v1"] = s.V1
|
||||
s.fieldMap["v2"] = s.V2
|
||||
s.fieldMap["v3"] = s.V3
|
||||
s.fieldMap["v4"] = s.V4
|
||||
s.fieldMap["v5"] = s.V5
|
||||
}
|
||||
|
||||
func (s scaAuthPermissionRule) clone(db *gorm.DB) scaAuthPermissionRule {
|
||||
s.scaAuthPermissionRuleDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return s
|
||||
}
|
||||
|
||||
func (s scaAuthPermissionRule) replaceDB(db *gorm.DB) scaAuthPermissionRule {
|
||||
s.scaAuthPermissionRuleDo.ReplaceDB(db)
|
||||
return s
|
||||
}
|
||||
|
||||
type scaAuthPermissionRuleDo struct{ gen.DO }
|
||||
|
||||
type IScaAuthPermissionRuleDo interface {
|
||||
gen.SubQuery
|
||||
Debug() IScaAuthPermissionRuleDo
|
||||
WithContext(ctx context.Context) IScaAuthPermissionRuleDo
|
||||
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
|
||||
ReplaceDB(db *gorm.DB)
|
||||
ReadDB() IScaAuthPermissionRuleDo
|
||||
WriteDB() IScaAuthPermissionRuleDo
|
||||
As(alias string) gen.Dao
|
||||
Session(config *gorm.Session) IScaAuthPermissionRuleDo
|
||||
Columns(cols ...field.Expr) gen.Columns
|
||||
Clauses(conds ...clause.Expression) IScaAuthPermissionRuleDo
|
||||
Not(conds ...gen.Condition) IScaAuthPermissionRuleDo
|
||||
Or(conds ...gen.Condition) IScaAuthPermissionRuleDo
|
||||
Select(conds ...field.Expr) IScaAuthPermissionRuleDo
|
||||
Where(conds ...gen.Condition) IScaAuthPermissionRuleDo
|
||||
Order(conds ...field.Expr) IScaAuthPermissionRuleDo
|
||||
Distinct(cols ...field.Expr) IScaAuthPermissionRuleDo
|
||||
Omit(cols ...field.Expr) IScaAuthPermissionRuleDo
|
||||
Join(table schema.Tabler, on ...field.Expr) IScaAuthPermissionRuleDo
|
||||
LeftJoin(table schema.Tabler, on ...field.Expr) IScaAuthPermissionRuleDo
|
||||
RightJoin(table schema.Tabler, on ...field.Expr) IScaAuthPermissionRuleDo
|
||||
Group(cols ...field.Expr) IScaAuthPermissionRuleDo
|
||||
Having(conds ...gen.Condition) IScaAuthPermissionRuleDo
|
||||
Limit(limit int) IScaAuthPermissionRuleDo
|
||||
Offset(offset int) IScaAuthPermissionRuleDo
|
||||
Count() (count int64, err error)
|
||||
Scopes(funcs ...func(gen.Dao) gen.Dao) IScaAuthPermissionRuleDo
|
||||
Unscoped() IScaAuthPermissionRuleDo
|
||||
Create(values ...*model.ScaAuthPermissionRule) error
|
||||
CreateInBatches(values []*model.ScaAuthPermissionRule, batchSize int) error
|
||||
Save(values ...*model.ScaAuthPermissionRule) error
|
||||
First() (*model.ScaAuthPermissionRule, error)
|
||||
Take() (*model.ScaAuthPermissionRule, error)
|
||||
Last() (*model.ScaAuthPermissionRule, error)
|
||||
Find() ([]*model.ScaAuthPermissionRule, error)
|
||||
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.ScaAuthPermissionRule, err error)
|
||||
FindInBatches(result *[]*model.ScaAuthPermissionRule, batchSize int, fc func(tx gen.Dao, batch int) error) error
|
||||
Pluck(column field.Expr, dest interface{}) error
|
||||
Delete(...*model.ScaAuthPermissionRule) (info gen.ResultInfo, err error)
|
||||
Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
||||
Updates(value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
||||
UpdateColumns(value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateFrom(q gen.SubQuery) gen.Dao
|
||||
Attrs(attrs ...field.AssignExpr) IScaAuthPermissionRuleDo
|
||||
Assign(attrs ...field.AssignExpr) IScaAuthPermissionRuleDo
|
||||
Joins(fields ...field.RelationField) IScaAuthPermissionRuleDo
|
||||
Preload(fields ...field.RelationField) IScaAuthPermissionRuleDo
|
||||
FirstOrInit() (*model.ScaAuthPermissionRule, error)
|
||||
FirstOrCreate() (*model.ScaAuthPermissionRule, error)
|
||||
FindByPage(offset int, limit int) (result []*model.ScaAuthPermissionRule, count int64, err error)
|
||||
ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
|
||||
Scan(result interface{}) (err error)
|
||||
Returning(value interface{}, columns ...string) IScaAuthPermissionRuleDo
|
||||
UnderlyingDB() *gorm.DB
|
||||
schema.Tabler
|
||||
}
|
||||
|
||||
func (s scaAuthPermissionRuleDo) Debug() IScaAuthPermissionRuleDo {
|
||||
return s.withDO(s.DO.Debug())
|
||||
}
|
||||
|
||||
func (s scaAuthPermissionRuleDo) WithContext(ctx context.Context) IScaAuthPermissionRuleDo {
|
||||
return s.withDO(s.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (s scaAuthPermissionRuleDo) ReadDB() IScaAuthPermissionRuleDo {
|
||||
return s.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (s scaAuthPermissionRuleDo) WriteDB() IScaAuthPermissionRuleDo {
|
||||
return s.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (s scaAuthPermissionRuleDo) Session(config *gorm.Session) IScaAuthPermissionRuleDo {
|
||||
return s.withDO(s.DO.Session(config))
|
||||
}
|
||||
|
||||
func (s scaAuthPermissionRuleDo) Clauses(conds ...clause.Expression) IScaAuthPermissionRuleDo {
|
||||
return s.withDO(s.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (s scaAuthPermissionRuleDo) Returning(value interface{}, columns ...string) IScaAuthPermissionRuleDo {
|
||||
return s.withDO(s.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (s scaAuthPermissionRuleDo) Not(conds ...gen.Condition) IScaAuthPermissionRuleDo {
|
||||
return s.withDO(s.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (s scaAuthPermissionRuleDo) Or(conds ...gen.Condition) IScaAuthPermissionRuleDo {
|
||||
return s.withDO(s.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (s scaAuthPermissionRuleDo) Select(conds ...field.Expr) IScaAuthPermissionRuleDo {
|
||||
return s.withDO(s.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (s scaAuthPermissionRuleDo) Where(conds ...gen.Condition) IScaAuthPermissionRuleDo {
|
||||
return s.withDO(s.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (s scaAuthPermissionRuleDo) Order(conds ...field.Expr) IScaAuthPermissionRuleDo {
|
||||
return s.withDO(s.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (s scaAuthPermissionRuleDo) Distinct(cols ...field.Expr) IScaAuthPermissionRuleDo {
|
||||
return s.withDO(s.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (s scaAuthPermissionRuleDo) Omit(cols ...field.Expr) IScaAuthPermissionRuleDo {
|
||||
return s.withDO(s.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (s scaAuthPermissionRuleDo) Join(table schema.Tabler, on ...field.Expr) IScaAuthPermissionRuleDo {
|
||||
return s.withDO(s.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (s scaAuthPermissionRuleDo) LeftJoin(table schema.Tabler, on ...field.Expr) IScaAuthPermissionRuleDo {
|
||||
return s.withDO(s.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (s scaAuthPermissionRuleDo) RightJoin(table schema.Tabler, on ...field.Expr) IScaAuthPermissionRuleDo {
|
||||
return s.withDO(s.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (s scaAuthPermissionRuleDo) Group(cols ...field.Expr) IScaAuthPermissionRuleDo {
|
||||
return s.withDO(s.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (s scaAuthPermissionRuleDo) Having(conds ...gen.Condition) IScaAuthPermissionRuleDo {
|
||||
return s.withDO(s.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (s scaAuthPermissionRuleDo) Limit(limit int) IScaAuthPermissionRuleDo {
|
||||
return s.withDO(s.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (s scaAuthPermissionRuleDo) Offset(offset int) IScaAuthPermissionRuleDo {
|
||||
return s.withDO(s.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (s scaAuthPermissionRuleDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IScaAuthPermissionRuleDo {
|
||||
return s.withDO(s.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (s scaAuthPermissionRuleDo) Unscoped() IScaAuthPermissionRuleDo {
|
||||
return s.withDO(s.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (s scaAuthPermissionRuleDo) Create(values ...*model.ScaAuthPermissionRule) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return s.DO.Create(values)
|
||||
}
|
||||
|
||||
func (s scaAuthPermissionRuleDo) CreateInBatches(values []*model.ScaAuthPermissionRule, batchSize int) error {
|
||||
return s.DO.CreateInBatches(values, batchSize)
|
||||
}
|
||||
|
||||
// Save : !!! underlying implementation is different with GORM
|
||||
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
|
||||
func (s scaAuthPermissionRuleDo) Save(values ...*model.ScaAuthPermissionRule) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return s.DO.Save(values)
|
||||
}
|
||||
|
||||
func (s scaAuthPermissionRuleDo) First() (*model.ScaAuthPermissionRule, error) {
|
||||
if result, err := s.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.ScaAuthPermissionRule), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s scaAuthPermissionRuleDo) Take() (*model.ScaAuthPermissionRule, error) {
|
||||
if result, err := s.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.ScaAuthPermissionRule), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s scaAuthPermissionRuleDo) Last() (*model.ScaAuthPermissionRule, error) {
|
||||
if result, err := s.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.ScaAuthPermissionRule), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s scaAuthPermissionRuleDo) Find() ([]*model.ScaAuthPermissionRule, error) {
|
||||
result, err := s.DO.Find()
|
||||
return result.([]*model.ScaAuthPermissionRule), err
|
||||
}
|
||||
|
||||
func (s scaAuthPermissionRuleDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.ScaAuthPermissionRule, err error) {
|
||||
buf := make([]*model.ScaAuthPermissionRule, 0, batchSize)
|
||||
err = s.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
|
||||
defer func() { results = append(results, buf...) }()
|
||||
return fc(tx, batch)
|
||||
})
|
||||
return results, err
|
||||
}
|
||||
|
||||
func (s scaAuthPermissionRuleDo) FindInBatches(result *[]*model.ScaAuthPermissionRule, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return s.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (s scaAuthPermissionRuleDo) Attrs(attrs ...field.AssignExpr) IScaAuthPermissionRuleDo {
|
||||
return s.withDO(s.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (s scaAuthPermissionRuleDo) Assign(attrs ...field.AssignExpr) IScaAuthPermissionRuleDo {
|
||||
return s.withDO(s.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (s scaAuthPermissionRuleDo) Joins(fields ...field.RelationField) IScaAuthPermissionRuleDo {
|
||||
for _, _f := range fields {
|
||||
s = *s.withDO(s.DO.Joins(_f))
|
||||
}
|
||||
return &s
|
||||
}
|
||||
|
||||
func (s scaAuthPermissionRuleDo) Preload(fields ...field.RelationField) IScaAuthPermissionRuleDo {
|
||||
for _, _f := range fields {
|
||||
s = *s.withDO(s.DO.Preload(_f))
|
||||
}
|
||||
return &s
|
||||
}
|
||||
|
||||
func (s scaAuthPermissionRuleDo) FirstOrInit() (*model.ScaAuthPermissionRule, error) {
|
||||
if result, err := s.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.ScaAuthPermissionRule), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s scaAuthPermissionRuleDo) FirstOrCreate() (*model.ScaAuthPermissionRule, error) {
|
||||
if result, err := s.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.ScaAuthPermissionRule), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s scaAuthPermissionRuleDo) FindByPage(offset int, limit int) (result []*model.ScaAuthPermissionRule, count int64, err error) {
|
||||
result, err = s.Offset(offset).Limit(limit).Find()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if size := len(result); 0 < limit && 0 < size && size < limit {
|
||||
count = int64(size + offset)
|
||||
return
|
||||
}
|
||||
|
||||
count, err = s.Offset(-1).Limit(-1).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (s scaAuthPermissionRuleDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||
count, err = s.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = s.Offset(offset).Limit(limit).Scan(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (s scaAuthPermissionRuleDo) Scan(result interface{}) (err error) {
|
||||
return s.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (s scaAuthPermissionRuleDo) Delete(models ...*model.ScaAuthPermissionRule) (result gen.ResultInfo, err error) {
|
||||
return s.DO.Delete(models)
|
||||
}
|
||||
|
||||
func (s *scaAuthPermissionRuleDo) withDO(do gen.Dao) *scaAuthPermissionRuleDo {
|
||||
s.DO = *do.(*gen.DO)
|
||||
return s
|
||||
}
|
399
app/auth/api/model/mysql/query/sca_auth_role.gen.go
Normal file
399
app/auth/api/model/mysql/query/sca_auth_role.gen.go
Normal file
@@ -0,0 +1,399 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package query
|
||||
|
||||
import (
|
||||
"context"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/model/mysql/model"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
||||
|
||||
"gorm.io/plugin/dbresolver"
|
||||
)
|
||||
|
||||
func newScaAuthRole(db *gorm.DB, opts ...gen.DOOption) scaAuthRole {
|
||||
_scaAuthRole := scaAuthRole{}
|
||||
|
||||
_scaAuthRole.scaAuthRoleDo.UseDB(db, opts...)
|
||||
_scaAuthRole.scaAuthRoleDo.UseModel(&model.ScaAuthRole{})
|
||||
|
||||
tableName := _scaAuthRole.scaAuthRoleDo.TableName()
|
||||
_scaAuthRole.ALL = field.NewAsterisk(tableName)
|
||||
_scaAuthRole.ID = field.NewInt64(tableName, "id")
|
||||
_scaAuthRole.RoleName = field.NewString(tableName, "role_name")
|
||||
_scaAuthRole.RoleKey = field.NewString(tableName, "role_key")
|
||||
_scaAuthRole.CreatedAt = field.NewTime(tableName, "created_at")
|
||||
_scaAuthRole.UpdatedAt = field.NewTime(tableName, "updated_at")
|
||||
_scaAuthRole.DeletedAt = field.NewField(tableName, "deleted_at")
|
||||
|
||||
_scaAuthRole.fillFieldMap()
|
||||
|
||||
return _scaAuthRole
|
||||
}
|
||||
|
||||
type scaAuthRole struct {
|
||||
scaAuthRoleDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Int64 // 主键ID
|
||||
RoleName field.String // 角色名称
|
||||
RoleKey field.String // 角色关键字
|
||||
CreatedAt field.Time // 创建时间
|
||||
UpdatedAt field.Time // 更新时间
|
||||
DeletedAt field.Field // 删除时间
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (s scaAuthRole) Table(newTableName string) *scaAuthRole {
|
||||
s.scaAuthRoleDo.UseTable(newTableName)
|
||||
return s.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (s scaAuthRole) As(alias string) *scaAuthRole {
|
||||
s.scaAuthRoleDo.DO = *(s.scaAuthRoleDo.As(alias).(*gen.DO))
|
||||
return s.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (s *scaAuthRole) updateTableName(table string) *scaAuthRole {
|
||||
s.ALL = field.NewAsterisk(table)
|
||||
s.ID = field.NewInt64(table, "id")
|
||||
s.RoleName = field.NewString(table, "role_name")
|
||||
s.RoleKey = field.NewString(table, "role_key")
|
||||
s.CreatedAt = field.NewTime(table, "created_at")
|
||||
s.UpdatedAt = field.NewTime(table, "updated_at")
|
||||
s.DeletedAt = field.NewField(table, "deleted_at")
|
||||
|
||||
s.fillFieldMap()
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *scaAuthRole) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
_f, ok := s.fieldMap[fieldName]
|
||||
if !ok || _f == nil {
|
||||
return nil, false
|
||||
}
|
||||
_oe, ok := _f.(field.OrderExpr)
|
||||
return _oe, ok
|
||||
}
|
||||
|
||||
func (s *scaAuthRole) fillFieldMap() {
|
||||
s.fieldMap = make(map[string]field.Expr, 6)
|
||||
s.fieldMap["id"] = s.ID
|
||||
s.fieldMap["role_name"] = s.RoleName
|
||||
s.fieldMap["role_key"] = s.RoleKey
|
||||
s.fieldMap["created_at"] = s.CreatedAt
|
||||
s.fieldMap["updated_at"] = s.UpdatedAt
|
||||
s.fieldMap["deleted_at"] = s.DeletedAt
|
||||
}
|
||||
|
||||
func (s scaAuthRole) clone(db *gorm.DB) scaAuthRole {
|
||||
s.scaAuthRoleDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return s
|
||||
}
|
||||
|
||||
func (s scaAuthRole) replaceDB(db *gorm.DB) scaAuthRole {
|
||||
s.scaAuthRoleDo.ReplaceDB(db)
|
||||
return s
|
||||
}
|
||||
|
||||
type scaAuthRoleDo struct{ gen.DO }
|
||||
|
||||
type IScaAuthRoleDo interface {
|
||||
gen.SubQuery
|
||||
Debug() IScaAuthRoleDo
|
||||
WithContext(ctx context.Context) IScaAuthRoleDo
|
||||
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
|
||||
ReplaceDB(db *gorm.DB)
|
||||
ReadDB() IScaAuthRoleDo
|
||||
WriteDB() IScaAuthRoleDo
|
||||
As(alias string) gen.Dao
|
||||
Session(config *gorm.Session) IScaAuthRoleDo
|
||||
Columns(cols ...field.Expr) gen.Columns
|
||||
Clauses(conds ...clause.Expression) IScaAuthRoleDo
|
||||
Not(conds ...gen.Condition) IScaAuthRoleDo
|
||||
Or(conds ...gen.Condition) IScaAuthRoleDo
|
||||
Select(conds ...field.Expr) IScaAuthRoleDo
|
||||
Where(conds ...gen.Condition) IScaAuthRoleDo
|
||||
Order(conds ...field.Expr) IScaAuthRoleDo
|
||||
Distinct(cols ...field.Expr) IScaAuthRoleDo
|
||||
Omit(cols ...field.Expr) IScaAuthRoleDo
|
||||
Join(table schema.Tabler, on ...field.Expr) IScaAuthRoleDo
|
||||
LeftJoin(table schema.Tabler, on ...field.Expr) IScaAuthRoleDo
|
||||
RightJoin(table schema.Tabler, on ...field.Expr) IScaAuthRoleDo
|
||||
Group(cols ...field.Expr) IScaAuthRoleDo
|
||||
Having(conds ...gen.Condition) IScaAuthRoleDo
|
||||
Limit(limit int) IScaAuthRoleDo
|
||||
Offset(offset int) IScaAuthRoleDo
|
||||
Count() (count int64, err error)
|
||||
Scopes(funcs ...func(gen.Dao) gen.Dao) IScaAuthRoleDo
|
||||
Unscoped() IScaAuthRoleDo
|
||||
Create(values ...*model.ScaAuthRole) error
|
||||
CreateInBatches(values []*model.ScaAuthRole, batchSize int) error
|
||||
Save(values ...*model.ScaAuthRole) error
|
||||
First() (*model.ScaAuthRole, error)
|
||||
Take() (*model.ScaAuthRole, error)
|
||||
Last() (*model.ScaAuthRole, error)
|
||||
Find() ([]*model.ScaAuthRole, error)
|
||||
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.ScaAuthRole, err error)
|
||||
FindInBatches(result *[]*model.ScaAuthRole, batchSize int, fc func(tx gen.Dao, batch int) error) error
|
||||
Pluck(column field.Expr, dest interface{}) error
|
||||
Delete(...*model.ScaAuthRole) (info gen.ResultInfo, err error)
|
||||
Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
||||
Updates(value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
||||
UpdateColumns(value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateFrom(q gen.SubQuery) gen.Dao
|
||||
Attrs(attrs ...field.AssignExpr) IScaAuthRoleDo
|
||||
Assign(attrs ...field.AssignExpr) IScaAuthRoleDo
|
||||
Joins(fields ...field.RelationField) IScaAuthRoleDo
|
||||
Preload(fields ...field.RelationField) IScaAuthRoleDo
|
||||
FirstOrInit() (*model.ScaAuthRole, error)
|
||||
FirstOrCreate() (*model.ScaAuthRole, error)
|
||||
FindByPage(offset int, limit int) (result []*model.ScaAuthRole, count int64, err error)
|
||||
ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
|
||||
Scan(result interface{}) (err error)
|
||||
Returning(value interface{}, columns ...string) IScaAuthRoleDo
|
||||
UnderlyingDB() *gorm.DB
|
||||
schema.Tabler
|
||||
}
|
||||
|
||||
func (s scaAuthRoleDo) Debug() IScaAuthRoleDo {
|
||||
return s.withDO(s.DO.Debug())
|
||||
}
|
||||
|
||||
func (s scaAuthRoleDo) WithContext(ctx context.Context) IScaAuthRoleDo {
|
||||
return s.withDO(s.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (s scaAuthRoleDo) ReadDB() IScaAuthRoleDo {
|
||||
return s.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (s scaAuthRoleDo) WriteDB() IScaAuthRoleDo {
|
||||
return s.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (s scaAuthRoleDo) Session(config *gorm.Session) IScaAuthRoleDo {
|
||||
return s.withDO(s.DO.Session(config))
|
||||
}
|
||||
|
||||
func (s scaAuthRoleDo) Clauses(conds ...clause.Expression) IScaAuthRoleDo {
|
||||
return s.withDO(s.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (s scaAuthRoleDo) Returning(value interface{}, columns ...string) IScaAuthRoleDo {
|
||||
return s.withDO(s.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (s scaAuthRoleDo) Not(conds ...gen.Condition) IScaAuthRoleDo {
|
||||
return s.withDO(s.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (s scaAuthRoleDo) Or(conds ...gen.Condition) IScaAuthRoleDo {
|
||||
return s.withDO(s.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (s scaAuthRoleDo) Select(conds ...field.Expr) IScaAuthRoleDo {
|
||||
return s.withDO(s.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (s scaAuthRoleDo) Where(conds ...gen.Condition) IScaAuthRoleDo {
|
||||
return s.withDO(s.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (s scaAuthRoleDo) Order(conds ...field.Expr) IScaAuthRoleDo {
|
||||
return s.withDO(s.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (s scaAuthRoleDo) Distinct(cols ...field.Expr) IScaAuthRoleDo {
|
||||
return s.withDO(s.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (s scaAuthRoleDo) Omit(cols ...field.Expr) IScaAuthRoleDo {
|
||||
return s.withDO(s.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (s scaAuthRoleDo) Join(table schema.Tabler, on ...field.Expr) IScaAuthRoleDo {
|
||||
return s.withDO(s.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (s scaAuthRoleDo) LeftJoin(table schema.Tabler, on ...field.Expr) IScaAuthRoleDo {
|
||||
return s.withDO(s.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (s scaAuthRoleDo) RightJoin(table schema.Tabler, on ...field.Expr) IScaAuthRoleDo {
|
||||
return s.withDO(s.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (s scaAuthRoleDo) Group(cols ...field.Expr) IScaAuthRoleDo {
|
||||
return s.withDO(s.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (s scaAuthRoleDo) Having(conds ...gen.Condition) IScaAuthRoleDo {
|
||||
return s.withDO(s.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (s scaAuthRoleDo) Limit(limit int) IScaAuthRoleDo {
|
||||
return s.withDO(s.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (s scaAuthRoleDo) Offset(offset int) IScaAuthRoleDo {
|
||||
return s.withDO(s.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (s scaAuthRoleDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IScaAuthRoleDo {
|
||||
return s.withDO(s.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (s scaAuthRoleDo) Unscoped() IScaAuthRoleDo {
|
||||
return s.withDO(s.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (s scaAuthRoleDo) Create(values ...*model.ScaAuthRole) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return s.DO.Create(values)
|
||||
}
|
||||
|
||||
func (s scaAuthRoleDo) CreateInBatches(values []*model.ScaAuthRole, batchSize int) error {
|
||||
return s.DO.CreateInBatches(values, batchSize)
|
||||
}
|
||||
|
||||
// Save : !!! underlying implementation is different with GORM
|
||||
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
|
||||
func (s scaAuthRoleDo) Save(values ...*model.ScaAuthRole) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return s.DO.Save(values)
|
||||
}
|
||||
|
||||
func (s scaAuthRoleDo) First() (*model.ScaAuthRole, error) {
|
||||
if result, err := s.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.ScaAuthRole), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s scaAuthRoleDo) Take() (*model.ScaAuthRole, error) {
|
||||
if result, err := s.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.ScaAuthRole), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s scaAuthRoleDo) Last() (*model.ScaAuthRole, error) {
|
||||
if result, err := s.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.ScaAuthRole), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s scaAuthRoleDo) Find() ([]*model.ScaAuthRole, error) {
|
||||
result, err := s.DO.Find()
|
||||
return result.([]*model.ScaAuthRole), err
|
||||
}
|
||||
|
||||
func (s scaAuthRoleDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.ScaAuthRole, err error) {
|
||||
buf := make([]*model.ScaAuthRole, 0, batchSize)
|
||||
err = s.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
|
||||
defer func() { results = append(results, buf...) }()
|
||||
return fc(tx, batch)
|
||||
})
|
||||
return results, err
|
||||
}
|
||||
|
||||
func (s scaAuthRoleDo) FindInBatches(result *[]*model.ScaAuthRole, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return s.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (s scaAuthRoleDo) Attrs(attrs ...field.AssignExpr) IScaAuthRoleDo {
|
||||
return s.withDO(s.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (s scaAuthRoleDo) Assign(attrs ...field.AssignExpr) IScaAuthRoleDo {
|
||||
return s.withDO(s.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (s scaAuthRoleDo) Joins(fields ...field.RelationField) IScaAuthRoleDo {
|
||||
for _, _f := range fields {
|
||||
s = *s.withDO(s.DO.Joins(_f))
|
||||
}
|
||||
return &s
|
||||
}
|
||||
|
||||
func (s scaAuthRoleDo) Preload(fields ...field.RelationField) IScaAuthRoleDo {
|
||||
for _, _f := range fields {
|
||||
s = *s.withDO(s.DO.Preload(_f))
|
||||
}
|
||||
return &s
|
||||
}
|
||||
|
||||
func (s scaAuthRoleDo) FirstOrInit() (*model.ScaAuthRole, error) {
|
||||
if result, err := s.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.ScaAuthRole), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s scaAuthRoleDo) FirstOrCreate() (*model.ScaAuthRole, error) {
|
||||
if result, err := s.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.ScaAuthRole), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s scaAuthRoleDo) FindByPage(offset int, limit int) (result []*model.ScaAuthRole, count int64, err error) {
|
||||
result, err = s.Offset(offset).Limit(limit).Find()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if size := len(result); 0 < limit && 0 < size && size < limit {
|
||||
count = int64(size + offset)
|
||||
return
|
||||
}
|
||||
|
||||
count, err = s.Offset(-1).Limit(-1).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (s scaAuthRoleDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||
count, err = s.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = s.Offset(offset).Limit(limit).Scan(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (s scaAuthRoleDo) Scan(result interface{}) (err error) {
|
||||
return s.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (s scaAuthRoleDo) Delete(models ...*model.ScaAuthRole) (result gen.ResultInfo, err error) {
|
||||
return s.DO.Delete(models)
|
||||
}
|
||||
|
||||
func (s *scaAuthRoleDo) withDO(do gen.Dao) *scaAuthRoleDo {
|
||||
s.DO = *do.(*gen.DO)
|
||||
return s
|
||||
}
|
443
app/auth/api/model/mysql/query/sca_auth_user.gen.go
Normal file
443
app/auth/api/model/mysql/query/sca_auth_user.gen.go
Normal file
@@ -0,0 +1,443 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package query
|
||||
|
||||
import (
|
||||
"context"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/model/mysql/model"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
||||
|
||||
"gorm.io/plugin/dbresolver"
|
||||
)
|
||||
|
||||
func newScaAuthUser(db *gorm.DB, opts ...gen.DOOption) scaAuthUser {
|
||||
_scaAuthUser := scaAuthUser{}
|
||||
|
||||
_scaAuthUser.scaAuthUserDo.UseDB(db, opts...)
|
||||
_scaAuthUser.scaAuthUserDo.UseModel(&model.ScaAuthUser{})
|
||||
|
||||
tableName := _scaAuthUser.scaAuthUserDo.TableName()
|
||||
_scaAuthUser.ALL = field.NewAsterisk(tableName)
|
||||
_scaAuthUser.ID = field.NewInt64(tableName, "id")
|
||||
_scaAuthUser.UID = field.NewString(tableName, "uid")
|
||||
_scaAuthUser.Username = field.NewString(tableName, "username")
|
||||
_scaAuthUser.Nickname = field.NewString(tableName, "nickname")
|
||||
_scaAuthUser.Email = field.NewString(tableName, "email")
|
||||
_scaAuthUser.Phone = field.NewString(tableName, "phone")
|
||||
_scaAuthUser.Password = field.NewString(tableName, "password")
|
||||
_scaAuthUser.Gender = field.NewInt64(tableName, "gender")
|
||||
_scaAuthUser.Avatar = field.NewString(tableName, "avatar")
|
||||
_scaAuthUser.Status = field.NewInt64(tableName, "status")
|
||||
_scaAuthUser.Introduce = field.NewString(tableName, "introduce")
|
||||
_scaAuthUser.CreatedAt = field.NewTime(tableName, "created_at")
|
||||
_scaAuthUser.Blog = field.NewString(tableName, "blog")
|
||||
_scaAuthUser.Location = field.NewString(tableName, "location")
|
||||
_scaAuthUser.Company = field.NewString(tableName, "company")
|
||||
_scaAuthUser.UpdatedAt = field.NewTime(tableName, "updated_at")
|
||||
_scaAuthUser.DeletedAt = field.NewField(tableName, "deleted_at")
|
||||
|
||||
_scaAuthUser.fillFieldMap()
|
||||
|
||||
return _scaAuthUser
|
||||
}
|
||||
|
||||
type scaAuthUser struct {
|
||||
scaAuthUserDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Int64 // 自增ID
|
||||
UID field.String // 唯一ID
|
||||
Username field.String // 用户名
|
||||
Nickname field.String // 昵称
|
||||
Email field.String // 邮箱
|
||||
Phone field.String // 电话
|
||||
Password field.String // 密码
|
||||
Gender field.Int64 // 性别
|
||||
Avatar field.String // 头像
|
||||
Status field.Int64 // 状态 0 正常 1 封禁
|
||||
Introduce field.String // 介绍
|
||||
CreatedAt field.Time // 创建时间
|
||||
Blog field.String // 博客
|
||||
Location field.String // 地址
|
||||
Company field.String // 公司
|
||||
UpdatedAt field.Time // 更新时间
|
||||
DeletedAt field.Field // 删除时间
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (s scaAuthUser) Table(newTableName string) *scaAuthUser {
|
||||
s.scaAuthUserDo.UseTable(newTableName)
|
||||
return s.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (s scaAuthUser) As(alias string) *scaAuthUser {
|
||||
s.scaAuthUserDo.DO = *(s.scaAuthUserDo.As(alias).(*gen.DO))
|
||||
return s.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (s *scaAuthUser) updateTableName(table string) *scaAuthUser {
|
||||
s.ALL = field.NewAsterisk(table)
|
||||
s.ID = field.NewInt64(table, "id")
|
||||
s.UID = field.NewString(table, "uid")
|
||||
s.Username = field.NewString(table, "username")
|
||||
s.Nickname = field.NewString(table, "nickname")
|
||||
s.Email = field.NewString(table, "email")
|
||||
s.Phone = field.NewString(table, "phone")
|
||||
s.Password = field.NewString(table, "password")
|
||||
s.Gender = field.NewInt64(table, "gender")
|
||||
s.Avatar = field.NewString(table, "avatar")
|
||||
s.Status = field.NewInt64(table, "status")
|
||||
s.Introduce = field.NewString(table, "introduce")
|
||||
s.CreatedAt = field.NewTime(table, "created_at")
|
||||
s.Blog = field.NewString(table, "blog")
|
||||
s.Location = field.NewString(table, "location")
|
||||
s.Company = field.NewString(table, "company")
|
||||
s.UpdatedAt = field.NewTime(table, "updated_at")
|
||||
s.DeletedAt = field.NewField(table, "deleted_at")
|
||||
|
||||
s.fillFieldMap()
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *scaAuthUser) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
_f, ok := s.fieldMap[fieldName]
|
||||
if !ok || _f == nil {
|
||||
return nil, false
|
||||
}
|
||||
_oe, ok := _f.(field.OrderExpr)
|
||||
return _oe, ok
|
||||
}
|
||||
|
||||
func (s *scaAuthUser) fillFieldMap() {
|
||||
s.fieldMap = make(map[string]field.Expr, 17)
|
||||
s.fieldMap["id"] = s.ID
|
||||
s.fieldMap["uid"] = s.UID
|
||||
s.fieldMap["username"] = s.Username
|
||||
s.fieldMap["nickname"] = s.Nickname
|
||||
s.fieldMap["email"] = s.Email
|
||||
s.fieldMap["phone"] = s.Phone
|
||||
s.fieldMap["password"] = s.Password
|
||||
s.fieldMap["gender"] = s.Gender
|
||||
s.fieldMap["avatar"] = s.Avatar
|
||||
s.fieldMap["status"] = s.Status
|
||||
s.fieldMap["introduce"] = s.Introduce
|
||||
s.fieldMap["created_at"] = s.CreatedAt
|
||||
s.fieldMap["blog"] = s.Blog
|
||||
s.fieldMap["location"] = s.Location
|
||||
s.fieldMap["company"] = s.Company
|
||||
s.fieldMap["updated_at"] = s.UpdatedAt
|
||||
s.fieldMap["deleted_at"] = s.DeletedAt
|
||||
}
|
||||
|
||||
func (s scaAuthUser) clone(db *gorm.DB) scaAuthUser {
|
||||
s.scaAuthUserDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return s
|
||||
}
|
||||
|
||||
func (s scaAuthUser) replaceDB(db *gorm.DB) scaAuthUser {
|
||||
s.scaAuthUserDo.ReplaceDB(db)
|
||||
return s
|
||||
}
|
||||
|
||||
type scaAuthUserDo struct{ gen.DO }
|
||||
|
||||
type IScaAuthUserDo interface {
|
||||
gen.SubQuery
|
||||
Debug() IScaAuthUserDo
|
||||
WithContext(ctx context.Context) IScaAuthUserDo
|
||||
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
|
||||
ReplaceDB(db *gorm.DB)
|
||||
ReadDB() IScaAuthUserDo
|
||||
WriteDB() IScaAuthUserDo
|
||||
As(alias string) gen.Dao
|
||||
Session(config *gorm.Session) IScaAuthUserDo
|
||||
Columns(cols ...field.Expr) gen.Columns
|
||||
Clauses(conds ...clause.Expression) IScaAuthUserDo
|
||||
Not(conds ...gen.Condition) IScaAuthUserDo
|
||||
Or(conds ...gen.Condition) IScaAuthUserDo
|
||||
Select(conds ...field.Expr) IScaAuthUserDo
|
||||
Where(conds ...gen.Condition) IScaAuthUserDo
|
||||
Order(conds ...field.Expr) IScaAuthUserDo
|
||||
Distinct(cols ...field.Expr) IScaAuthUserDo
|
||||
Omit(cols ...field.Expr) IScaAuthUserDo
|
||||
Join(table schema.Tabler, on ...field.Expr) IScaAuthUserDo
|
||||
LeftJoin(table schema.Tabler, on ...field.Expr) IScaAuthUserDo
|
||||
RightJoin(table schema.Tabler, on ...field.Expr) IScaAuthUserDo
|
||||
Group(cols ...field.Expr) IScaAuthUserDo
|
||||
Having(conds ...gen.Condition) IScaAuthUserDo
|
||||
Limit(limit int) IScaAuthUserDo
|
||||
Offset(offset int) IScaAuthUserDo
|
||||
Count() (count int64, err error)
|
||||
Scopes(funcs ...func(gen.Dao) gen.Dao) IScaAuthUserDo
|
||||
Unscoped() IScaAuthUserDo
|
||||
Create(values ...*model.ScaAuthUser) error
|
||||
CreateInBatches(values []*model.ScaAuthUser, batchSize int) error
|
||||
Save(values ...*model.ScaAuthUser) error
|
||||
First() (*model.ScaAuthUser, error)
|
||||
Take() (*model.ScaAuthUser, error)
|
||||
Last() (*model.ScaAuthUser, error)
|
||||
Find() ([]*model.ScaAuthUser, error)
|
||||
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.ScaAuthUser, err error)
|
||||
FindInBatches(result *[]*model.ScaAuthUser, batchSize int, fc func(tx gen.Dao, batch int) error) error
|
||||
Pluck(column field.Expr, dest interface{}) error
|
||||
Delete(...*model.ScaAuthUser) (info gen.ResultInfo, err error)
|
||||
Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
||||
Updates(value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
||||
UpdateColumns(value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateFrom(q gen.SubQuery) gen.Dao
|
||||
Attrs(attrs ...field.AssignExpr) IScaAuthUserDo
|
||||
Assign(attrs ...field.AssignExpr) IScaAuthUserDo
|
||||
Joins(fields ...field.RelationField) IScaAuthUserDo
|
||||
Preload(fields ...field.RelationField) IScaAuthUserDo
|
||||
FirstOrInit() (*model.ScaAuthUser, error)
|
||||
FirstOrCreate() (*model.ScaAuthUser, error)
|
||||
FindByPage(offset int, limit int) (result []*model.ScaAuthUser, count int64, err error)
|
||||
ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
|
||||
Scan(result interface{}) (err error)
|
||||
Returning(value interface{}, columns ...string) IScaAuthUserDo
|
||||
UnderlyingDB() *gorm.DB
|
||||
schema.Tabler
|
||||
}
|
||||
|
||||
func (s scaAuthUserDo) Debug() IScaAuthUserDo {
|
||||
return s.withDO(s.DO.Debug())
|
||||
}
|
||||
|
||||
func (s scaAuthUserDo) WithContext(ctx context.Context) IScaAuthUserDo {
|
||||
return s.withDO(s.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (s scaAuthUserDo) ReadDB() IScaAuthUserDo {
|
||||
return s.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (s scaAuthUserDo) WriteDB() IScaAuthUserDo {
|
||||
return s.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (s scaAuthUserDo) Session(config *gorm.Session) IScaAuthUserDo {
|
||||
return s.withDO(s.DO.Session(config))
|
||||
}
|
||||
|
||||
func (s scaAuthUserDo) Clauses(conds ...clause.Expression) IScaAuthUserDo {
|
||||
return s.withDO(s.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (s scaAuthUserDo) Returning(value interface{}, columns ...string) IScaAuthUserDo {
|
||||
return s.withDO(s.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (s scaAuthUserDo) Not(conds ...gen.Condition) IScaAuthUserDo {
|
||||
return s.withDO(s.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (s scaAuthUserDo) Or(conds ...gen.Condition) IScaAuthUserDo {
|
||||
return s.withDO(s.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (s scaAuthUserDo) Select(conds ...field.Expr) IScaAuthUserDo {
|
||||
return s.withDO(s.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (s scaAuthUserDo) Where(conds ...gen.Condition) IScaAuthUserDo {
|
||||
return s.withDO(s.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (s scaAuthUserDo) Order(conds ...field.Expr) IScaAuthUserDo {
|
||||
return s.withDO(s.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (s scaAuthUserDo) Distinct(cols ...field.Expr) IScaAuthUserDo {
|
||||
return s.withDO(s.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (s scaAuthUserDo) Omit(cols ...field.Expr) IScaAuthUserDo {
|
||||
return s.withDO(s.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (s scaAuthUserDo) Join(table schema.Tabler, on ...field.Expr) IScaAuthUserDo {
|
||||
return s.withDO(s.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (s scaAuthUserDo) LeftJoin(table schema.Tabler, on ...field.Expr) IScaAuthUserDo {
|
||||
return s.withDO(s.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (s scaAuthUserDo) RightJoin(table schema.Tabler, on ...field.Expr) IScaAuthUserDo {
|
||||
return s.withDO(s.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (s scaAuthUserDo) Group(cols ...field.Expr) IScaAuthUserDo {
|
||||
return s.withDO(s.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (s scaAuthUserDo) Having(conds ...gen.Condition) IScaAuthUserDo {
|
||||
return s.withDO(s.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (s scaAuthUserDo) Limit(limit int) IScaAuthUserDo {
|
||||
return s.withDO(s.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (s scaAuthUserDo) Offset(offset int) IScaAuthUserDo {
|
||||
return s.withDO(s.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (s scaAuthUserDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IScaAuthUserDo {
|
||||
return s.withDO(s.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (s scaAuthUserDo) Unscoped() IScaAuthUserDo {
|
||||
return s.withDO(s.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (s scaAuthUserDo) Create(values ...*model.ScaAuthUser) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return s.DO.Create(values)
|
||||
}
|
||||
|
||||
func (s scaAuthUserDo) CreateInBatches(values []*model.ScaAuthUser, batchSize int) error {
|
||||
return s.DO.CreateInBatches(values, batchSize)
|
||||
}
|
||||
|
||||
// Save : !!! underlying implementation is different with GORM
|
||||
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
|
||||
func (s scaAuthUserDo) Save(values ...*model.ScaAuthUser) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return s.DO.Save(values)
|
||||
}
|
||||
|
||||
func (s scaAuthUserDo) First() (*model.ScaAuthUser, error) {
|
||||
if result, err := s.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.ScaAuthUser), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s scaAuthUserDo) Take() (*model.ScaAuthUser, error) {
|
||||
if result, err := s.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.ScaAuthUser), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s scaAuthUserDo) Last() (*model.ScaAuthUser, error) {
|
||||
if result, err := s.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.ScaAuthUser), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s scaAuthUserDo) Find() ([]*model.ScaAuthUser, error) {
|
||||
result, err := s.DO.Find()
|
||||
return result.([]*model.ScaAuthUser), err
|
||||
}
|
||||
|
||||
func (s scaAuthUserDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.ScaAuthUser, err error) {
|
||||
buf := make([]*model.ScaAuthUser, 0, batchSize)
|
||||
err = s.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
|
||||
defer func() { results = append(results, buf...) }()
|
||||
return fc(tx, batch)
|
||||
})
|
||||
return results, err
|
||||
}
|
||||
|
||||
func (s scaAuthUserDo) FindInBatches(result *[]*model.ScaAuthUser, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return s.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (s scaAuthUserDo) Attrs(attrs ...field.AssignExpr) IScaAuthUserDo {
|
||||
return s.withDO(s.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (s scaAuthUserDo) Assign(attrs ...field.AssignExpr) IScaAuthUserDo {
|
||||
return s.withDO(s.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (s scaAuthUserDo) Joins(fields ...field.RelationField) IScaAuthUserDo {
|
||||
for _, _f := range fields {
|
||||
s = *s.withDO(s.DO.Joins(_f))
|
||||
}
|
||||
return &s
|
||||
}
|
||||
|
||||
func (s scaAuthUserDo) Preload(fields ...field.RelationField) IScaAuthUserDo {
|
||||
for _, _f := range fields {
|
||||
s = *s.withDO(s.DO.Preload(_f))
|
||||
}
|
||||
return &s
|
||||
}
|
||||
|
||||
func (s scaAuthUserDo) FirstOrInit() (*model.ScaAuthUser, error) {
|
||||
if result, err := s.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.ScaAuthUser), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s scaAuthUserDo) FirstOrCreate() (*model.ScaAuthUser, error) {
|
||||
if result, err := s.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.ScaAuthUser), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s scaAuthUserDo) FindByPage(offset int, limit int) (result []*model.ScaAuthUser, count int64, err error) {
|
||||
result, err = s.Offset(offset).Limit(limit).Find()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if size := len(result); 0 < limit && 0 < size && size < limit {
|
||||
count = int64(size + offset)
|
||||
return
|
||||
}
|
||||
|
||||
count, err = s.Offset(-1).Limit(-1).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (s scaAuthUserDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||
count, err = s.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = s.Offset(offset).Limit(limit).Scan(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (s scaAuthUserDo) Scan(result interface{}) (err error) {
|
||||
return s.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (s scaAuthUserDo) Delete(models ...*model.ScaAuthUser) (result gen.ResultInfo, err error) {
|
||||
return s.DO.Delete(models)
|
||||
}
|
||||
|
||||
func (s *scaAuthUserDo) withDO(do gen.Dao) *scaAuthUserDo {
|
||||
s.DO = *do.(*gen.DO)
|
||||
return s
|
||||
}
|
443
app/auth/api/model/mysql/query/sca_auth_user_device.gen.go
Normal file
443
app/auth/api/model/mysql/query/sca_auth_user_device.gen.go
Normal file
@@ -0,0 +1,443 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package query
|
||||
|
||||
import (
|
||||
"context"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/model/mysql/model"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
||||
|
||||
"gorm.io/plugin/dbresolver"
|
||||
)
|
||||
|
||||
func newScaAuthUserDevice(db *gorm.DB, opts ...gen.DOOption) scaAuthUserDevice {
|
||||
_scaAuthUserDevice := scaAuthUserDevice{}
|
||||
|
||||
_scaAuthUserDevice.scaAuthUserDeviceDo.UseDB(db, opts...)
|
||||
_scaAuthUserDevice.scaAuthUserDeviceDo.UseModel(&model.ScaAuthUserDevice{})
|
||||
|
||||
tableName := _scaAuthUserDevice.scaAuthUserDeviceDo.TableName()
|
||||
_scaAuthUserDevice.ALL = field.NewAsterisk(tableName)
|
||||
_scaAuthUserDevice.ID = field.NewInt64(tableName, "id")
|
||||
_scaAuthUserDevice.UserID = field.NewString(tableName, "user_id")
|
||||
_scaAuthUserDevice.IP = field.NewString(tableName, "ip")
|
||||
_scaAuthUserDevice.Location = field.NewString(tableName, "location")
|
||||
_scaAuthUserDevice.Agent = field.NewString(tableName, "agent")
|
||||
_scaAuthUserDevice.CreatedAt = field.NewTime(tableName, "created_at")
|
||||
_scaAuthUserDevice.Browser = field.NewString(tableName, "browser")
|
||||
_scaAuthUserDevice.OperatingSystem = field.NewString(tableName, "operating_system")
|
||||
_scaAuthUserDevice.BrowserVersion = field.NewString(tableName, "browser_version")
|
||||
_scaAuthUserDevice.Mobile = field.NewInt64(tableName, "mobile")
|
||||
_scaAuthUserDevice.Bot = field.NewInt64(tableName, "bot")
|
||||
_scaAuthUserDevice.Mozilla = field.NewString(tableName, "mozilla")
|
||||
_scaAuthUserDevice.Platform = field.NewString(tableName, "platform")
|
||||
_scaAuthUserDevice.EngineName = field.NewString(tableName, "engine_name")
|
||||
_scaAuthUserDevice.EngineVersion = field.NewString(tableName, "engine_version")
|
||||
_scaAuthUserDevice.UpdatedAt = field.NewTime(tableName, "updated_at")
|
||||
_scaAuthUserDevice.DeletedAt = field.NewField(tableName, "deleted_at")
|
||||
|
||||
_scaAuthUserDevice.fillFieldMap()
|
||||
|
||||
return _scaAuthUserDevice
|
||||
}
|
||||
|
||||
type scaAuthUserDevice struct {
|
||||
scaAuthUserDeviceDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Int64 // 主键ID
|
||||
UserID field.String // 用户ID
|
||||
IP field.String // 登录IP
|
||||
Location field.String // 地址
|
||||
Agent field.String // 设备信息
|
||||
CreatedAt field.Time // 创建时间
|
||||
Browser field.String // 浏览器
|
||||
OperatingSystem field.String // 操作系统
|
||||
BrowserVersion field.String // 浏览器版本
|
||||
Mobile field.Int64 // 是否为手机 0否1是
|
||||
Bot field.Int64 // 是否为bot 0否1是
|
||||
Mozilla field.String // 火狐版本
|
||||
Platform field.String // 平台
|
||||
EngineName field.String // 引擎名称
|
||||
EngineVersion field.String // 引擎版本
|
||||
UpdatedAt field.Time // 更新时间
|
||||
DeletedAt field.Field // 删除时间
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (s scaAuthUserDevice) Table(newTableName string) *scaAuthUserDevice {
|
||||
s.scaAuthUserDeviceDo.UseTable(newTableName)
|
||||
return s.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (s scaAuthUserDevice) As(alias string) *scaAuthUserDevice {
|
||||
s.scaAuthUserDeviceDo.DO = *(s.scaAuthUserDeviceDo.As(alias).(*gen.DO))
|
||||
return s.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (s *scaAuthUserDevice) updateTableName(table string) *scaAuthUserDevice {
|
||||
s.ALL = field.NewAsterisk(table)
|
||||
s.ID = field.NewInt64(table, "id")
|
||||
s.UserID = field.NewString(table, "user_id")
|
||||
s.IP = field.NewString(table, "ip")
|
||||
s.Location = field.NewString(table, "location")
|
||||
s.Agent = field.NewString(table, "agent")
|
||||
s.CreatedAt = field.NewTime(table, "created_at")
|
||||
s.Browser = field.NewString(table, "browser")
|
||||
s.OperatingSystem = field.NewString(table, "operating_system")
|
||||
s.BrowserVersion = field.NewString(table, "browser_version")
|
||||
s.Mobile = field.NewInt64(table, "mobile")
|
||||
s.Bot = field.NewInt64(table, "bot")
|
||||
s.Mozilla = field.NewString(table, "mozilla")
|
||||
s.Platform = field.NewString(table, "platform")
|
||||
s.EngineName = field.NewString(table, "engine_name")
|
||||
s.EngineVersion = field.NewString(table, "engine_version")
|
||||
s.UpdatedAt = field.NewTime(table, "updated_at")
|
||||
s.DeletedAt = field.NewField(table, "deleted_at")
|
||||
|
||||
s.fillFieldMap()
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *scaAuthUserDevice) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
_f, ok := s.fieldMap[fieldName]
|
||||
if !ok || _f == nil {
|
||||
return nil, false
|
||||
}
|
||||
_oe, ok := _f.(field.OrderExpr)
|
||||
return _oe, ok
|
||||
}
|
||||
|
||||
func (s *scaAuthUserDevice) fillFieldMap() {
|
||||
s.fieldMap = make(map[string]field.Expr, 17)
|
||||
s.fieldMap["id"] = s.ID
|
||||
s.fieldMap["user_id"] = s.UserID
|
||||
s.fieldMap["ip"] = s.IP
|
||||
s.fieldMap["location"] = s.Location
|
||||
s.fieldMap["agent"] = s.Agent
|
||||
s.fieldMap["created_at"] = s.CreatedAt
|
||||
s.fieldMap["browser"] = s.Browser
|
||||
s.fieldMap["operating_system"] = s.OperatingSystem
|
||||
s.fieldMap["browser_version"] = s.BrowserVersion
|
||||
s.fieldMap["mobile"] = s.Mobile
|
||||
s.fieldMap["bot"] = s.Bot
|
||||
s.fieldMap["mozilla"] = s.Mozilla
|
||||
s.fieldMap["platform"] = s.Platform
|
||||
s.fieldMap["engine_name"] = s.EngineName
|
||||
s.fieldMap["engine_version"] = s.EngineVersion
|
||||
s.fieldMap["updated_at"] = s.UpdatedAt
|
||||
s.fieldMap["deleted_at"] = s.DeletedAt
|
||||
}
|
||||
|
||||
func (s scaAuthUserDevice) clone(db *gorm.DB) scaAuthUserDevice {
|
||||
s.scaAuthUserDeviceDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return s
|
||||
}
|
||||
|
||||
func (s scaAuthUserDevice) replaceDB(db *gorm.DB) scaAuthUserDevice {
|
||||
s.scaAuthUserDeviceDo.ReplaceDB(db)
|
||||
return s
|
||||
}
|
||||
|
||||
type scaAuthUserDeviceDo struct{ gen.DO }
|
||||
|
||||
type IScaAuthUserDeviceDo interface {
|
||||
gen.SubQuery
|
||||
Debug() IScaAuthUserDeviceDo
|
||||
WithContext(ctx context.Context) IScaAuthUserDeviceDo
|
||||
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
|
||||
ReplaceDB(db *gorm.DB)
|
||||
ReadDB() IScaAuthUserDeviceDo
|
||||
WriteDB() IScaAuthUserDeviceDo
|
||||
As(alias string) gen.Dao
|
||||
Session(config *gorm.Session) IScaAuthUserDeviceDo
|
||||
Columns(cols ...field.Expr) gen.Columns
|
||||
Clauses(conds ...clause.Expression) IScaAuthUserDeviceDo
|
||||
Not(conds ...gen.Condition) IScaAuthUserDeviceDo
|
||||
Or(conds ...gen.Condition) IScaAuthUserDeviceDo
|
||||
Select(conds ...field.Expr) IScaAuthUserDeviceDo
|
||||
Where(conds ...gen.Condition) IScaAuthUserDeviceDo
|
||||
Order(conds ...field.Expr) IScaAuthUserDeviceDo
|
||||
Distinct(cols ...field.Expr) IScaAuthUserDeviceDo
|
||||
Omit(cols ...field.Expr) IScaAuthUserDeviceDo
|
||||
Join(table schema.Tabler, on ...field.Expr) IScaAuthUserDeviceDo
|
||||
LeftJoin(table schema.Tabler, on ...field.Expr) IScaAuthUserDeviceDo
|
||||
RightJoin(table schema.Tabler, on ...field.Expr) IScaAuthUserDeviceDo
|
||||
Group(cols ...field.Expr) IScaAuthUserDeviceDo
|
||||
Having(conds ...gen.Condition) IScaAuthUserDeviceDo
|
||||
Limit(limit int) IScaAuthUserDeviceDo
|
||||
Offset(offset int) IScaAuthUserDeviceDo
|
||||
Count() (count int64, err error)
|
||||
Scopes(funcs ...func(gen.Dao) gen.Dao) IScaAuthUserDeviceDo
|
||||
Unscoped() IScaAuthUserDeviceDo
|
||||
Create(values ...*model.ScaAuthUserDevice) error
|
||||
CreateInBatches(values []*model.ScaAuthUserDevice, batchSize int) error
|
||||
Save(values ...*model.ScaAuthUserDevice) error
|
||||
First() (*model.ScaAuthUserDevice, error)
|
||||
Take() (*model.ScaAuthUserDevice, error)
|
||||
Last() (*model.ScaAuthUserDevice, error)
|
||||
Find() ([]*model.ScaAuthUserDevice, error)
|
||||
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.ScaAuthUserDevice, err error)
|
||||
FindInBatches(result *[]*model.ScaAuthUserDevice, batchSize int, fc func(tx gen.Dao, batch int) error) error
|
||||
Pluck(column field.Expr, dest interface{}) error
|
||||
Delete(...*model.ScaAuthUserDevice) (info gen.ResultInfo, err error)
|
||||
Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
||||
Updates(value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
||||
UpdateColumns(value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateFrom(q gen.SubQuery) gen.Dao
|
||||
Attrs(attrs ...field.AssignExpr) IScaAuthUserDeviceDo
|
||||
Assign(attrs ...field.AssignExpr) IScaAuthUserDeviceDo
|
||||
Joins(fields ...field.RelationField) IScaAuthUserDeviceDo
|
||||
Preload(fields ...field.RelationField) IScaAuthUserDeviceDo
|
||||
FirstOrInit() (*model.ScaAuthUserDevice, error)
|
||||
FirstOrCreate() (*model.ScaAuthUserDevice, error)
|
||||
FindByPage(offset int, limit int) (result []*model.ScaAuthUserDevice, count int64, err error)
|
||||
ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
|
||||
Scan(result interface{}) (err error)
|
||||
Returning(value interface{}, columns ...string) IScaAuthUserDeviceDo
|
||||
UnderlyingDB() *gorm.DB
|
||||
schema.Tabler
|
||||
}
|
||||
|
||||
func (s scaAuthUserDeviceDo) Debug() IScaAuthUserDeviceDo {
|
||||
return s.withDO(s.DO.Debug())
|
||||
}
|
||||
|
||||
func (s scaAuthUserDeviceDo) WithContext(ctx context.Context) IScaAuthUserDeviceDo {
|
||||
return s.withDO(s.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (s scaAuthUserDeviceDo) ReadDB() IScaAuthUserDeviceDo {
|
||||
return s.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (s scaAuthUserDeviceDo) WriteDB() IScaAuthUserDeviceDo {
|
||||
return s.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (s scaAuthUserDeviceDo) Session(config *gorm.Session) IScaAuthUserDeviceDo {
|
||||
return s.withDO(s.DO.Session(config))
|
||||
}
|
||||
|
||||
func (s scaAuthUserDeviceDo) Clauses(conds ...clause.Expression) IScaAuthUserDeviceDo {
|
||||
return s.withDO(s.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (s scaAuthUserDeviceDo) Returning(value interface{}, columns ...string) IScaAuthUserDeviceDo {
|
||||
return s.withDO(s.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (s scaAuthUserDeviceDo) Not(conds ...gen.Condition) IScaAuthUserDeviceDo {
|
||||
return s.withDO(s.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (s scaAuthUserDeviceDo) Or(conds ...gen.Condition) IScaAuthUserDeviceDo {
|
||||
return s.withDO(s.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (s scaAuthUserDeviceDo) Select(conds ...field.Expr) IScaAuthUserDeviceDo {
|
||||
return s.withDO(s.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (s scaAuthUserDeviceDo) Where(conds ...gen.Condition) IScaAuthUserDeviceDo {
|
||||
return s.withDO(s.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (s scaAuthUserDeviceDo) Order(conds ...field.Expr) IScaAuthUserDeviceDo {
|
||||
return s.withDO(s.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (s scaAuthUserDeviceDo) Distinct(cols ...field.Expr) IScaAuthUserDeviceDo {
|
||||
return s.withDO(s.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (s scaAuthUserDeviceDo) Omit(cols ...field.Expr) IScaAuthUserDeviceDo {
|
||||
return s.withDO(s.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (s scaAuthUserDeviceDo) Join(table schema.Tabler, on ...field.Expr) IScaAuthUserDeviceDo {
|
||||
return s.withDO(s.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (s scaAuthUserDeviceDo) LeftJoin(table schema.Tabler, on ...field.Expr) IScaAuthUserDeviceDo {
|
||||
return s.withDO(s.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (s scaAuthUserDeviceDo) RightJoin(table schema.Tabler, on ...field.Expr) IScaAuthUserDeviceDo {
|
||||
return s.withDO(s.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (s scaAuthUserDeviceDo) Group(cols ...field.Expr) IScaAuthUserDeviceDo {
|
||||
return s.withDO(s.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (s scaAuthUserDeviceDo) Having(conds ...gen.Condition) IScaAuthUserDeviceDo {
|
||||
return s.withDO(s.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (s scaAuthUserDeviceDo) Limit(limit int) IScaAuthUserDeviceDo {
|
||||
return s.withDO(s.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (s scaAuthUserDeviceDo) Offset(offset int) IScaAuthUserDeviceDo {
|
||||
return s.withDO(s.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (s scaAuthUserDeviceDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IScaAuthUserDeviceDo {
|
||||
return s.withDO(s.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (s scaAuthUserDeviceDo) Unscoped() IScaAuthUserDeviceDo {
|
||||
return s.withDO(s.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (s scaAuthUserDeviceDo) Create(values ...*model.ScaAuthUserDevice) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return s.DO.Create(values)
|
||||
}
|
||||
|
||||
func (s scaAuthUserDeviceDo) CreateInBatches(values []*model.ScaAuthUserDevice, batchSize int) error {
|
||||
return s.DO.CreateInBatches(values, batchSize)
|
||||
}
|
||||
|
||||
// Save : !!! underlying implementation is different with GORM
|
||||
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
|
||||
func (s scaAuthUserDeviceDo) Save(values ...*model.ScaAuthUserDevice) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return s.DO.Save(values)
|
||||
}
|
||||
|
||||
func (s scaAuthUserDeviceDo) First() (*model.ScaAuthUserDevice, error) {
|
||||
if result, err := s.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.ScaAuthUserDevice), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s scaAuthUserDeviceDo) Take() (*model.ScaAuthUserDevice, error) {
|
||||
if result, err := s.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.ScaAuthUserDevice), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s scaAuthUserDeviceDo) Last() (*model.ScaAuthUserDevice, error) {
|
||||
if result, err := s.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.ScaAuthUserDevice), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s scaAuthUserDeviceDo) Find() ([]*model.ScaAuthUserDevice, error) {
|
||||
result, err := s.DO.Find()
|
||||
return result.([]*model.ScaAuthUserDevice), err
|
||||
}
|
||||
|
||||
func (s scaAuthUserDeviceDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.ScaAuthUserDevice, err error) {
|
||||
buf := make([]*model.ScaAuthUserDevice, 0, batchSize)
|
||||
err = s.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
|
||||
defer func() { results = append(results, buf...) }()
|
||||
return fc(tx, batch)
|
||||
})
|
||||
return results, err
|
||||
}
|
||||
|
||||
func (s scaAuthUserDeviceDo) FindInBatches(result *[]*model.ScaAuthUserDevice, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return s.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (s scaAuthUserDeviceDo) Attrs(attrs ...field.AssignExpr) IScaAuthUserDeviceDo {
|
||||
return s.withDO(s.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (s scaAuthUserDeviceDo) Assign(attrs ...field.AssignExpr) IScaAuthUserDeviceDo {
|
||||
return s.withDO(s.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (s scaAuthUserDeviceDo) Joins(fields ...field.RelationField) IScaAuthUserDeviceDo {
|
||||
for _, _f := range fields {
|
||||
s = *s.withDO(s.DO.Joins(_f))
|
||||
}
|
||||
return &s
|
||||
}
|
||||
|
||||
func (s scaAuthUserDeviceDo) Preload(fields ...field.RelationField) IScaAuthUserDeviceDo {
|
||||
for _, _f := range fields {
|
||||
s = *s.withDO(s.DO.Preload(_f))
|
||||
}
|
||||
return &s
|
||||
}
|
||||
|
||||
func (s scaAuthUserDeviceDo) FirstOrInit() (*model.ScaAuthUserDevice, error) {
|
||||
if result, err := s.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.ScaAuthUserDevice), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s scaAuthUserDeviceDo) FirstOrCreate() (*model.ScaAuthUserDevice, error) {
|
||||
if result, err := s.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.ScaAuthUserDevice), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s scaAuthUserDeviceDo) FindByPage(offset int, limit int) (result []*model.ScaAuthUserDevice, count int64, err error) {
|
||||
result, err = s.Offset(offset).Limit(limit).Find()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if size := len(result); 0 < limit && 0 < size && size < limit {
|
||||
count = int64(size + offset)
|
||||
return
|
||||
}
|
||||
|
||||
count, err = s.Offset(-1).Limit(-1).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (s scaAuthUserDeviceDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||
count, err = s.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = s.Offset(offset).Limit(limit).Scan(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (s scaAuthUserDeviceDo) Scan(result interface{}) (err error) {
|
||||
return s.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (s scaAuthUserDeviceDo) Delete(models ...*model.ScaAuthUserDevice) (result gen.ResultInfo, err error) {
|
||||
return s.DO.Delete(models)
|
||||
}
|
||||
|
||||
func (s *scaAuthUserDeviceDo) withDO(do gen.Dao) *scaAuthUserDeviceDo {
|
||||
s.DO = *do.(*gen.DO)
|
||||
return s
|
||||
}
|
407
app/auth/api/model/mysql/query/sca_auth_user_social.gen.go
Normal file
407
app/auth/api/model/mysql/query/sca_auth_user_social.gen.go
Normal file
@@ -0,0 +1,407 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package query
|
||||
|
||||
import (
|
||||
"context"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/model/mysql/model"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
||||
|
||||
"gorm.io/plugin/dbresolver"
|
||||
)
|
||||
|
||||
func newScaAuthUserSocial(db *gorm.DB, opts ...gen.DOOption) scaAuthUserSocial {
|
||||
_scaAuthUserSocial := scaAuthUserSocial{}
|
||||
|
||||
_scaAuthUserSocial.scaAuthUserSocialDo.UseDB(db, opts...)
|
||||
_scaAuthUserSocial.scaAuthUserSocialDo.UseModel(&model.ScaAuthUserSocial{})
|
||||
|
||||
tableName := _scaAuthUserSocial.scaAuthUserSocialDo.TableName()
|
||||
_scaAuthUserSocial.ALL = field.NewAsterisk(tableName)
|
||||
_scaAuthUserSocial.ID = field.NewInt64(tableName, "id")
|
||||
_scaAuthUserSocial.UserID = field.NewString(tableName, "user_id")
|
||||
_scaAuthUserSocial.OpenID = field.NewString(tableName, "open_id")
|
||||
_scaAuthUserSocial.Source = field.NewString(tableName, "source")
|
||||
_scaAuthUserSocial.Status = field.NewInt64(tableName, "status")
|
||||
_scaAuthUserSocial.CreatedAt = field.NewTime(tableName, "created_at")
|
||||
_scaAuthUserSocial.UpdatedAt = field.NewTime(tableName, "updated_at")
|
||||
_scaAuthUserSocial.DeletedAt = field.NewField(tableName, "deleted_at")
|
||||
|
||||
_scaAuthUserSocial.fillFieldMap()
|
||||
|
||||
return _scaAuthUserSocial
|
||||
}
|
||||
|
||||
type scaAuthUserSocial struct {
|
||||
scaAuthUserSocialDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Int64 // 主键ID
|
||||
UserID field.String // 用户ID
|
||||
OpenID field.String // 第三方用户的 open id
|
||||
Source field.String // 第三方用户来源
|
||||
Status field.Int64 // 状态 0正常 1 封禁
|
||||
CreatedAt field.Time // 创建时间
|
||||
UpdatedAt field.Time // 更新时间
|
||||
DeletedAt field.Field // 删除时间
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (s scaAuthUserSocial) Table(newTableName string) *scaAuthUserSocial {
|
||||
s.scaAuthUserSocialDo.UseTable(newTableName)
|
||||
return s.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (s scaAuthUserSocial) As(alias string) *scaAuthUserSocial {
|
||||
s.scaAuthUserSocialDo.DO = *(s.scaAuthUserSocialDo.As(alias).(*gen.DO))
|
||||
return s.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (s *scaAuthUserSocial) updateTableName(table string) *scaAuthUserSocial {
|
||||
s.ALL = field.NewAsterisk(table)
|
||||
s.ID = field.NewInt64(table, "id")
|
||||
s.UserID = field.NewString(table, "user_id")
|
||||
s.OpenID = field.NewString(table, "open_id")
|
||||
s.Source = field.NewString(table, "source")
|
||||
s.Status = field.NewInt64(table, "status")
|
||||
s.CreatedAt = field.NewTime(table, "created_at")
|
||||
s.UpdatedAt = field.NewTime(table, "updated_at")
|
||||
s.DeletedAt = field.NewField(table, "deleted_at")
|
||||
|
||||
s.fillFieldMap()
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *scaAuthUserSocial) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
_f, ok := s.fieldMap[fieldName]
|
||||
if !ok || _f == nil {
|
||||
return nil, false
|
||||
}
|
||||
_oe, ok := _f.(field.OrderExpr)
|
||||
return _oe, ok
|
||||
}
|
||||
|
||||
func (s *scaAuthUserSocial) fillFieldMap() {
|
||||
s.fieldMap = make(map[string]field.Expr, 8)
|
||||
s.fieldMap["id"] = s.ID
|
||||
s.fieldMap["user_id"] = s.UserID
|
||||
s.fieldMap["open_id"] = s.OpenID
|
||||
s.fieldMap["source"] = s.Source
|
||||
s.fieldMap["status"] = s.Status
|
||||
s.fieldMap["created_at"] = s.CreatedAt
|
||||
s.fieldMap["updated_at"] = s.UpdatedAt
|
||||
s.fieldMap["deleted_at"] = s.DeletedAt
|
||||
}
|
||||
|
||||
func (s scaAuthUserSocial) clone(db *gorm.DB) scaAuthUserSocial {
|
||||
s.scaAuthUserSocialDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return s
|
||||
}
|
||||
|
||||
func (s scaAuthUserSocial) replaceDB(db *gorm.DB) scaAuthUserSocial {
|
||||
s.scaAuthUserSocialDo.ReplaceDB(db)
|
||||
return s
|
||||
}
|
||||
|
||||
type scaAuthUserSocialDo struct{ gen.DO }
|
||||
|
||||
type IScaAuthUserSocialDo interface {
|
||||
gen.SubQuery
|
||||
Debug() IScaAuthUserSocialDo
|
||||
WithContext(ctx context.Context) IScaAuthUserSocialDo
|
||||
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
|
||||
ReplaceDB(db *gorm.DB)
|
||||
ReadDB() IScaAuthUserSocialDo
|
||||
WriteDB() IScaAuthUserSocialDo
|
||||
As(alias string) gen.Dao
|
||||
Session(config *gorm.Session) IScaAuthUserSocialDo
|
||||
Columns(cols ...field.Expr) gen.Columns
|
||||
Clauses(conds ...clause.Expression) IScaAuthUserSocialDo
|
||||
Not(conds ...gen.Condition) IScaAuthUserSocialDo
|
||||
Or(conds ...gen.Condition) IScaAuthUserSocialDo
|
||||
Select(conds ...field.Expr) IScaAuthUserSocialDo
|
||||
Where(conds ...gen.Condition) IScaAuthUserSocialDo
|
||||
Order(conds ...field.Expr) IScaAuthUserSocialDo
|
||||
Distinct(cols ...field.Expr) IScaAuthUserSocialDo
|
||||
Omit(cols ...field.Expr) IScaAuthUserSocialDo
|
||||
Join(table schema.Tabler, on ...field.Expr) IScaAuthUserSocialDo
|
||||
LeftJoin(table schema.Tabler, on ...field.Expr) IScaAuthUserSocialDo
|
||||
RightJoin(table schema.Tabler, on ...field.Expr) IScaAuthUserSocialDo
|
||||
Group(cols ...field.Expr) IScaAuthUserSocialDo
|
||||
Having(conds ...gen.Condition) IScaAuthUserSocialDo
|
||||
Limit(limit int) IScaAuthUserSocialDo
|
||||
Offset(offset int) IScaAuthUserSocialDo
|
||||
Count() (count int64, err error)
|
||||
Scopes(funcs ...func(gen.Dao) gen.Dao) IScaAuthUserSocialDo
|
||||
Unscoped() IScaAuthUserSocialDo
|
||||
Create(values ...*model.ScaAuthUserSocial) error
|
||||
CreateInBatches(values []*model.ScaAuthUserSocial, batchSize int) error
|
||||
Save(values ...*model.ScaAuthUserSocial) error
|
||||
First() (*model.ScaAuthUserSocial, error)
|
||||
Take() (*model.ScaAuthUserSocial, error)
|
||||
Last() (*model.ScaAuthUserSocial, error)
|
||||
Find() ([]*model.ScaAuthUserSocial, error)
|
||||
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.ScaAuthUserSocial, err error)
|
||||
FindInBatches(result *[]*model.ScaAuthUserSocial, batchSize int, fc func(tx gen.Dao, batch int) error) error
|
||||
Pluck(column field.Expr, dest interface{}) error
|
||||
Delete(...*model.ScaAuthUserSocial) (info gen.ResultInfo, err error)
|
||||
Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
||||
Updates(value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
||||
UpdateColumns(value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateFrom(q gen.SubQuery) gen.Dao
|
||||
Attrs(attrs ...field.AssignExpr) IScaAuthUserSocialDo
|
||||
Assign(attrs ...field.AssignExpr) IScaAuthUserSocialDo
|
||||
Joins(fields ...field.RelationField) IScaAuthUserSocialDo
|
||||
Preload(fields ...field.RelationField) IScaAuthUserSocialDo
|
||||
FirstOrInit() (*model.ScaAuthUserSocial, error)
|
||||
FirstOrCreate() (*model.ScaAuthUserSocial, error)
|
||||
FindByPage(offset int, limit int) (result []*model.ScaAuthUserSocial, count int64, err error)
|
||||
ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
|
||||
Scan(result interface{}) (err error)
|
||||
Returning(value interface{}, columns ...string) IScaAuthUserSocialDo
|
||||
UnderlyingDB() *gorm.DB
|
||||
schema.Tabler
|
||||
}
|
||||
|
||||
func (s scaAuthUserSocialDo) Debug() IScaAuthUserSocialDo {
|
||||
return s.withDO(s.DO.Debug())
|
||||
}
|
||||
|
||||
func (s scaAuthUserSocialDo) WithContext(ctx context.Context) IScaAuthUserSocialDo {
|
||||
return s.withDO(s.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (s scaAuthUserSocialDo) ReadDB() IScaAuthUserSocialDo {
|
||||
return s.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (s scaAuthUserSocialDo) WriteDB() IScaAuthUserSocialDo {
|
||||
return s.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (s scaAuthUserSocialDo) Session(config *gorm.Session) IScaAuthUserSocialDo {
|
||||
return s.withDO(s.DO.Session(config))
|
||||
}
|
||||
|
||||
func (s scaAuthUserSocialDo) Clauses(conds ...clause.Expression) IScaAuthUserSocialDo {
|
||||
return s.withDO(s.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (s scaAuthUserSocialDo) Returning(value interface{}, columns ...string) IScaAuthUserSocialDo {
|
||||
return s.withDO(s.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (s scaAuthUserSocialDo) Not(conds ...gen.Condition) IScaAuthUserSocialDo {
|
||||
return s.withDO(s.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (s scaAuthUserSocialDo) Or(conds ...gen.Condition) IScaAuthUserSocialDo {
|
||||
return s.withDO(s.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (s scaAuthUserSocialDo) Select(conds ...field.Expr) IScaAuthUserSocialDo {
|
||||
return s.withDO(s.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (s scaAuthUserSocialDo) Where(conds ...gen.Condition) IScaAuthUserSocialDo {
|
||||
return s.withDO(s.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (s scaAuthUserSocialDo) Order(conds ...field.Expr) IScaAuthUserSocialDo {
|
||||
return s.withDO(s.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (s scaAuthUserSocialDo) Distinct(cols ...field.Expr) IScaAuthUserSocialDo {
|
||||
return s.withDO(s.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (s scaAuthUserSocialDo) Omit(cols ...field.Expr) IScaAuthUserSocialDo {
|
||||
return s.withDO(s.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (s scaAuthUserSocialDo) Join(table schema.Tabler, on ...field.Expr) IScaAuthUserSocialDo {
|
||||
return s.withDO(s.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (s scaAuthUserSocialDo) LeftJoin(table schema.Tabler, on ...field.Expr) IScaAuthUserSocialDo {
|
||||
return s.withDO(s.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (s scaAuthUserSocialDo) RightJoin(table schema.Tabler, on ...field.Expr) IScaAuthUserSocialDo {
|
||||
return s.withDO(s.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (s scaAuthUserSocialDo) Group(cols ...field.Expr) IScaAuthUserSocialDo {
|
||||
return s.withDO(s.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (s scaAuthUserSocialDo) Having(conds ...gen.Condition) IScaAuthUserSocialDo {
|
||||
return s.withDO(s.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (s scaAuthUserSocialDo) Limit(limit int) IScaAuthUserSocialDo {
|
||||
return s.withDO(s.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (s scaAuthUserSocialDo) Offset(offset int) IScaAuthUserSocialDo {
|
||||
return s.withDO(s.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (s scaAuthUserSocialDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IScaAuthUserSocialDo {
|
||||
return s.withDO(s.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (s scaAuthUserSocialDo) Unscoped() IScaAuthUserSocialDo {
|
||||
return s.withDO(s.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (s scaAuthUserSocialDo) Create(values ...*model.ScaAuthUserSocial) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return s.DO.Create(values)
|
||||
}
|
||||
|
||||
func (s scaAuthUserSocialDo) CreateInBatches(values []*model.ScaAuthUserSocial, batchSize int) error {
|
||||
return s.DO.CreateInBatches(values, batchSize)
|
||||
}
|
||||
|
||||
// Save : !!! underlying implementation is different with GORM
|
||||
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
|
||||
func (s scaAuthUserSocialDo) Save(values ...*model.ScaAuthUserSocial) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return s.DO.Save(values)
|
||||
}
|
||||
|
||||
func (s scaAuthUserSocialDo) First() (*model.ScaAuthUserSocial, error) {
|
||||
if result, err := s.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.ScaAuthUserSocial), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s scaAuthUserSocialDo) Take() (*model.ScaAuthUserSocial, error) {
|
||||
if result, err := s.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.ScaAuthUserSocial), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s scaAuthUserSocialDo) Last() (*model.ScaAuthUserSocial, error) {
|
||||
if result, err := s.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.ScaAuthUserSocial), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s scaAuthUserSocialDo) Find() ([]*model.ScaAuthUserSocial, error) {
|
||||
result, err := s.DO.Find()
|
||||
return result.([]*model.ScaAuthUserSocial), err
|
||||
}
|
||||
|
||||
func (s scaAuthUserSocialDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.ScaAuthUserSocial, err error) {
|
||||
buf := make([]*model.ScaAuthUserSocial, 0, batchSize)
|
||||
err = s.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
|
||||
defer func() { results = append(results, buf...) }()
|
||||
return fc(tx, batch)
|
||||
})
|
||||
return results, err
|
||||
}
|
||||
|
||||
func (s scaAuthUserSocialDo) FindInBatches(result *[]*model.ScaAuthUserSocial, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return s.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (s scaAuthUserSocialDo) Attrs(attrs ...field.AssignExpr) IScaAuthUserSocialDo {
|
||||
return s.withDO(s.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (s scaAuthUserSocialDo) Assign(attrs ...field.AssignExpr) IScaAuthUserSocialDo {
|
||||
return s.withDO(s.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (s scaAuthUserSocialDo) Joins(fields ...field.RelationField) IScaAuthUserSocialDo {
|
||||
for _, _f := range fields {
|
||||
s = *s.withDO(s.DO.Joins(_f))
|
||||
}
|
||||
return &s
|
||||
}
|
||||
|
||||
func (s scaAuthUserSocialDo) Preload(fields ...field.RelationField) IScaAuthUserSocialDo {
|
||||
for _, _f := range fields {
|
||||
s = *s.withDO(s.DO.Preload(_f))
|
||||
}
|
||||
return &s
|
||||
}
|
||||
|
||||
func (s scaAuthUserSocialDo) FirstOrInit() (*model.ScaAuthUserSocial, error) {
|
||||
if result, err := s.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.ScaAuthUserSocial), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s scaAuthUserSocialDo) FirstOrCreate() (*model.ScaAuthUserSocial, error) {
|
||||
if result, err := s.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.ScaAuthUserSocial), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s scaAuthUserSocialDo) FindByPage(offset int, limit int) (result []*model.ScaAuthUserSocial, count int64, err error) {
|
||||
result, err = s.Offset(offset).Limit(limit).Find()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if size := len(result); 0 < limit && 0 < size && size < limit {
|
||||
count = int64(size + offset)
|
||||
return
|
||||
}
|
||||
|
||||
count, err = s.Offset(-1).Limit(-1).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (s scaAuthUserSocialDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||
count, err = s.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = s.Offset(offset).Limit(limit).Scan(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (s scaAuthUserSocialDo) Scan(result interface{}) (err error) {
|
||||
return s.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (s scaAuthUserSocialDo) Delete(models ...*model.ScaAuthUserSocial) (result gen.ResultInfo, err error) {
|
||||
return s.DO.Delete(models)
|
||||
}
|
||||
|
||||
func (s *scaAuthUserSocialDo) withDO(do gen.Dao) *scaAuthUserSocialDo {
|
||||
s.DO = *do.(*gen.DO)
|
||||
return s
|
||||
}
|
419
app/auth/api/model/mysql/query/sca_user_level.gen.go
Normal file
419
app/auth/api/model/mysql/query/sca_user_level.gen.go
Normal file
@@ -0,0 +1,419 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package query
|
||||
|
||||
import (
|
||||
"context"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/model/mysql/model"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
||||
|
||||
"gorm.io/plugin/dbresolver"
|
||||
)
|
||||
|
||||
func newScaUserLevel(db *gorm.DB, opts ...gen.DOOption) scaUserLevel {
|
||||
_scaUserLevel := scaUserLevel{}
|
||||
|
||||
_scaUserLevel.scaUserLevelDo.UseDB(db, opts...)
|
||||
_scaUserLevel.scaUserLevelDo.UseModel(&model.ScaUserLevel{})
|
||||
|
||||
tableName := _scaUserLevel.scaUserLevelDo.TableName()
|
||||
_scaUserLevel.ALL = field.NewAsterisk(tableName)
|
||||
_scaUserLevel.ID = field.NewInt64(tableName, "id")
|
||||
_scaUserLevel.UserID = field.NewString(tableName, "user_id")
|
||||
_scaUserLevel.LevelType = field.NewInt64(tableName, "level_type")
|
||||
_scaUserLevel.Level = field.NewInt64(tableName, "level")
|
||||
_scaUserLevel.LevelName = field.NewString(tableName, "level_name")
|
||||
_scaUserLevel.ExpStart = field.NewInt64(tableName, "exp_start")
|
||||
_scaUserLevel.ExpEnd = field.NewInt64(tableName, "exp_end")
|
||||
_scaUserLevel.Description = field.NewString(tableName, "description")
|
||||
_scaUserLevel.CreatedAt = field.NewTime(tableName, "created_at")
|
||||
_scaUserLevel.UpdatedAt = field.NewTime(tableName, "updated_at")
|
||||
_scaUserLevel.DeletedAt = field.NewField(tableName, "deleted_at")
|
||||
|
||||
_scaUserLevel.fillFieldMap()
|
||||
|
||||
return _scaUserLevel
|
||||
}
|
||||
|
||||
type scaUserLevel struct {
|
||||
scaUserLevelDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Int64 // 主键
|
||||
UserID field.String // 用户Id
|
||||
LevelType field.Int64 // 等级类型
|
||||
Level field.Int64 // 等级
|
||||
LevelName field.String // 等级名称
|
||||
ExpStart field.Int64 // 开始经验值
|
||||
ExpEnd field.Int64 // 结束经验值
|
||||
Description field.String // 等级描述
|
||||
CreatedAt field.Time // 创建时间
|
||||
UpdatedAt field.Time // 更新时间
|
||||
DeletedAt field.Field // 删除时间
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (s scaUserLevel) Table(newTableName string) *scaUserLevel {
|
||||
s.scaUserLevelDo.UseTable(newTableName)
|
||||
return s.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (s scaUserLevel) As(alias string) *scaUserLevel {
|
||||
s.scaUserLevelDo.DO = *(s.scaUserLevelDo.As(alias).(*gen.DO))
|
||||
return s.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (s *scaUserLevel) updateTableName(table string) *scaUserLevel {
|
||||
s.ALL = field.NewAsterisk(table)
|
||||
s.ID = field.NewInt64(table, "id")
|
||||
s.UserID = field.NewString(table, "user_id")
|
||||
s.LevelType = field.NewInt64(table, "level_type")
|
||||
s.Level = field.NewInt64(table, "level")
|
||||
s.LevelName = field.NewString(table, "level_name")
|
||||
s.ExpStart = field.NewInt64(table, "exp_start")
|
||||
s.ExpEnd = field.NewInt64(table, "exp_end")
|
||||
s.Description = field.NewString(table, "description")
|
||||
s.CreatedAt = field.NewTime(table, "created_at")
|
||||
s.UpdatedAt = field.NewTime(table, "updated_at")
|
||||
s.DeletedAt = field.NewField(table, "deleted_at")
|
||||
|
||||
s.fillFieldMap()
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *scaUserLevel) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
_f, ok := s.fieldMap[fieldName]
|
||||
if !ok || _f == nil {
|
||||
return nil, false
|
||||
}
|
||||
_oe, ok := _f.(field.OrderExpr)
|
||||
return _oe, ok
|
||||
}
|
||||
|
||||
func (s *scaUserLevel) fillFieldMap() {
|
||||
s.fieldMap = make(map[string]field.Expr, 11)
|
||||
s.fieldMap["id"] = s.ID
|
||||
s.fieldMap["user_id"] = s.UserID
|
||||
s.fieldMap["level_type"] = s.LevelType
|
||||
s.fieldMap["level"] = s.Level
|
||||
s.fieldMap["level_name"] = s.LevelName
|
||||
s.fieldMap["exp_start"] = s.ExpStart
|
||||
s.fieldMap["exp_end"] = s.ExpEnd
|
||||
s.fieldMap["description"] = s.Description
|
||||
s.fieldMap["created_at"] = s.CreatedAt
|
||||
s.fieldMap["updated_at"] = s.UpdatedAt
|
||||
s.fieldMap["deleted_at"] = s.DeletedAt
|
||||
}
|
||||
|
||||
func (s scaUserLevel) clone(db *gorm.DB) scaUserLevel {
|
||||
s.scaUserLevelDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return s
|
||||
}
|
||||
|
||||
func (s scaUserLevel) replaceDB(db *gorm.DB) scaUserLevel {
|
||||
s.scaUserLevelDo.ReplaceDB(db)
|
||||
return s
|
||||
}
|
||||
|
||||
type scaUserLevelDo struct{ gen.DO }
|
||||
|
||||
type IScaUserLevelDo interface {
|
||||
gen.SubQuery
|
||||
Debug() IScaUserLevelDo
|
||||
WithContext(ctx context.Context) IScaUserLevelDo
|
||||
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
|
||||
ReplaceDB(db *gorm.DB)
|
||||
ReadDB() IScaUserLevelDo
|
||||
WriteDB() IScaUserLevelDo
|
||||
As(alias string) gen.Dao
|
||||
Session(config *gorm.Session) IScaUserLevelDo
|
||||
Columns(cols ...field.Expr) gen.Columns
|
||||
Clauses(conds ...clause.Expression) IScaUserLevelDo
|
||||
Not(conds ...gen.Condition) IScaUserLevelDo
|
||||
Or(conds ...gen.Condition) IScaUserLevelDo
|
||||
Select(conds ...field.Expr) IScaUserLevelDo
|
||||
Where(conds ...gen.Condition) IScaUserLevelDo
|
||||
Order(conds ...field.Expr) IScaUserLevelDo
|
||||
Distinct(cols ...field.Expr) IScaUserLevelDo
|
||||
Omit(cols ...field.Expr) IScaUserLevelDo
|
||||
Join(table schema.Tabler, on ...field.Expr) IScaUserLevelDo
|
||||
LeftJoin(table schema.Tabler, on ...field.Expr) IScaUserLevelDo
|
||||
RightJoin(table schema.Tabler, on ...field.Expr) IScaUserLevelDo
|
||||
Group(cols ...field.Expr) IScaUserLevelDo
|
||||
Having(conds ...gen.Condition) IScaUserLevelDo
|
||||
Limit(limit int) IScaUserLevelDo
|
||||
Offset(offset int) IScaUserLevelDo
|
||||
Count() (count int64, err error)
|
||||
Scopes(funcs ...func(gen.Dao) gen.Dao) IScaUserLevelDo
|
||||
Unscoped() IScaUserLevelDo
|
||||
Create(values ...*model.ScaUserLevel) error
|
||||
CreateInBatches(values []*model.ScaUserLevel, batchSize int) error
|
||||
Save(values ...*model.ScaUserLevel) error
|
||||
First() (*model.ScaUserLevel, error)
|
||||
Take() (*model.ScaUserLevel, error)
|
||||
Last() (*model.ScaUserLevel, error)
|
||||
Find() ([]*model.ScaUserLevel, error)
|
||||
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.ScaUserLevel, err error)
|
||||
FindInBatches(result *[]*model.ScaUserLevel, batchSize int, fc func(tx gen.Dao, batch int) error) error
|
||||
Pluck(column field.Expr, dest interface{}) error
|
||||
Delete(...*model.ScaUserLevel) (info gen.ResultInfo, err error)
|
||||
Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
||||
Updates(value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
||||
UpdateColumns(value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateFrom(q gen.SubQuery) gen.Dao
|
||||
Attrs(attrs ...field.AssignExpr) IScaUserLevelDo
|
||||
Assign(attrs ...field.AssignExpr) IScaUserLevelDo
|
||||
Joins(fields ...field.RelationField) IScaUserLevelDo
|
||||
Preload(fields ...field.RelationField) IScaUserLevelDo
|
||||
FirstOrInit() (*model.ScaUserLevel, error)
|
||||
FirstOrCreate() (*model.ScaUserLevel, error)
|
||||
FindByPage(offset int, limit int) (result []*model.ScaUserLevel, count int64, err error)
|
||||
ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
|
||||
Scan(result interface{}) (err error)
|
||||
Returning(value interface{}, columns ...string) IScaUserLevelDo
|
||||
UnderlyingDB() *gorm.DB
|
||||
schema.Tabler
|
||||
}
|
||||
|
||||
func (s scaUserLevelDo) Debug() IScaUserLevelDo {
|
||||
return s.withDO(s.DO.Debug())
|
||||
}
|
||||
|
||||
func (s scaUserLevelDo) WithContext(ctx context.Context) IScaUserLevelDo {
|
||||
return s.withDO(s.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (s scaUserLevelDo) ReadDB() IScaUserLevelDo {
|
||||
return s.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (s scaUserLevelDo) WriteDB() IScaUserLevelDo {
|
||||
return s.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (s scaUserLevelDo) Session(config *gorm.Session) IScaUserLevelDo {
|
||||
return s.withDO(s.DO.Session(config))
|
||||
}
|
||||
|
||||
func (s scaUserLevelDo) Clauses(conds ...clause.Expression) IScaUserLevelDo {
|
||||
return s.withDO(s.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (s scaUserLevelDo) Returning(value interface{}, columns ...string) IScaUserLevelDo {
|
||||
return s.withDO(s.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (s scaUserLevelDo) Not(conds ...gen.Condition) IScaUserLevelDo {
|
||||
return s.withDO(s.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (s scaUserLevelDo) Or(conds ...gen.Condition) IScaUserLevelDo {
|
||||
return s.withDO(s.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (s scaUserLevelDo) Select(conds ...field.Expr) IScaUserLevelDo {
|
||||
return s.withDO(s.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (s scaUserLevelDo) Where(conds ...gen.Condition) IScaUserLevelDo {
|
||||
return s.withDO(s.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (s scaUserLevelDo) Order(conds ...field.Expr) IScaUserLevelDo {
|
||||
return s.withDO(s.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (s scaUserLevelDo) Distinct(cols ...field.Expr) IScaUserLevelDo {
|
||||
return s.withDO(s.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (s scaUserLevelDo) Omit(cols ...field.Expr) IScaUserLevelDo {
|
||||
return s.withDO(s.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (s scaUserLevelDo) Join(table schema.Tabler, on ...field.Expr) IScaUserLevelDo {
|
||||
return s.withDO(s.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (s scaUserLevelDo) LeftJoin(table schema.Tabler, on ...field.Expr) IScaUserLevelDo {
|
||||
return s.withDO(s.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (s scaUserLevelDo) RightJoin(table schema.Tabler, on ...field.Expr) IScaUserLevelDo {
|
||||
return s.withDO(s.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (s scaUserLevelDo) Group(cols ...field.Expr) IScaUserLevelDo {
|
||||
return s.withDO(s.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (s scaUserLevelDo) Having(conds ...gen.Condition) IScaUserLevelDo {
|
||||
return s.withDO(s.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (s scaUserLevelDo) Limit(limit int) IScaUserLevelDo {
|
||||
return s.withDO(s.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (s scaUserLevelDo) Offset(offset int) IScaUserLevelDo {
|
||||
return s.withDO(s.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (s scaUserLevelDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IScaUserLevelDo {
|
||||
return s.withDO(s.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (s scaUserLevelDo) Unscoped() IScaUserLevelDo {
|
||||
return s.withDO(s.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (s scaUserLevelDo) Create(values ...*model.ScaUserLevel) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return s.DO.Create(values)
|
||||
}
|
||||
|
||||
func (s scaUserLevelDo) CreateInBatches(values []*model.ScaUserLevel, batchSize int) error {
|
||||
return s.DO.CreateInBatches(values, batchSize)
|
||||
}
|
||||
|
||||
// Save : !!! underlying implementation is different with GORM
|
||||
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
|
||||
func (s scaUserLevelDo) Save(values ...*model.ScaUserLevel) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return s.DO.Save(values)
|
||||
}
|
||||
|
||||
func (s scaUserLevelDo) First() (*model.ScaUserLevel, error) {
|
||||
if result, err := s.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.ScaUserLevel), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s scaUserLevelDo) Take() (*model.ScaUserLevel, error) {
|
||||
if result, err := s.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.ScaUserLevel), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s scaUserLevelDo) Last() (*model.ScaUserLevel, error) {
|
||||
if result, err := s.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.ScaUserLevel), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s scaUserLevelDo) Find() ([]*model.ScaUserLevel, error) {
|
||||
result, err := s.DO.Find()
|
||||
return result.([]*model.ScaUserLevel), err
|
||||
}
|
||||
|
||||
func (s scaUserLevelDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.ScaUserLevel, err error) {
|
||||
buf := make([]*model.ScaUserLevel, 0, batchSize)
|
||||
err = s.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
|
||||
defer func() { results = append(results, buf...) }()
|
||||
return fc(tx, batch)
|
||||
})
|
||||
return results, err
|
||||
}
|
||||
|
||||
func (s scaUserLevelDo) FindInBatches(result *[]*model.ScaUserLevel, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return s.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (s scaUserLevelDo) Attrs(attrs ...field.AssignExpr) IScaUserLevelDo {
|
||||
return s.withDO(s.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (s scaUserLevelDo) Assign(attrs ...field.AssignExpr) IScaUserLevelDo {
|
||||
return s.withDO(s.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (s scaUserLevelDo) Joins(fields ...field.RelationField) IScaUserLevelDo {
|
||||
for _, _f := range fields {
|
||||
s = *s.withDO(s.DO.Joins(_f))
|
||||
}
|
||||
return &s
|
||||
}
|
||||
|
||||
func (s scaUserLevelDo) Preload(fields ...field.RelationField) IScaUserLevelDo {
|
||||
for _, _f := range fields {
|
||||
s = *s.withDO(s.DO.Preload(_f))
|
||||
}
|
||||
return &s
|
||||
}
|
||||
|
||||
func (s scaUserLevelDo) FirstOrInit() (*model.ScaUserLevel, error) {
|
||||
if result, err := s.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.ScaUserLevel), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s scaUserLevelDo) FirstOrCreate() (*model.ScaUserLevel, error) {
|
||||
if result, err := s.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.ScaUserLevel), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s scaUserLevelDo) FindByPage(offset int, limit int) (result []*model.ScaUserLevel, count int64, err error) {
|
||||
result, err = s.Offset(offset).Limit(limit).Find()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if size := len(result); 0 < limit && 0 < size && size < limit {
|
||||
count = int64(size + offset)
|
||||
return
|
||||
}
|
||||
|
||||
count, err = s.Offset(-1).Limit(-1).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (s scaUserLevelDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||
count, err = s.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = s.Offset(offset).Limit(limit).Scan(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (s scaUserLevelDo) Scan(result interface{}) (err error) {
|
||||
return s.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (s scaUserLevelDo) Delete(models ...*model.ScaUserLevel) (result gen.ResultInfo, err error) {
|
||||
return s.DO.Delete(models)
|
||||
}
|
||||
|
||||
func (s *scaUserLevelDo) withDO(do gen.Dao) *scaUserLevelDo {
|
||||
s.DO = *do.(*gen.DO)
|
||||
return s
|
||||
}
|
411
app/auth/api/model/mysql/query/sca_user_message.gen.go
Normal file
411
app/auth/api/model/mysql/query/sca_user_message.gen.go
Normal file
@@ -0,0 +1,411 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package query
|
||||
|
||||
import (
|
||||
"context"
|
||||
"schisandra-album-cloud-microservices/app/auth/api/model/mysql/model"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
||||
|
||||
"gorm.io/plugin/dbresolver"
|
||||
)
|
||||
|
||||
func newScaUserMessage(db *gorm.DB, opts ...gen.DOOption) scaUserMessage {
|
||||
_scaUserMessage := scaUserMessage{}
|
||||
|
||||
_scaUserMessage.scaUserMessageDo.UseDB(db, opts...)
|
||||
_scaUserMessage.scaUserMessageDo.UseModel(&model.ScaUserMessage{})
|
||||
|
||||
tableName := _scaUserMessage.scaUserMessageDo.TableName()
|
||||
_scaUserMessage.ALL = field.NewAsterisk(tableName)
|
||||
_scaUserMessage.ID = field.NewInt64(tableName, "id")
|
||||
_scaUserMessage.TopicID = field.NewString(tableName, "topic_id")
|
||||
_scaUserMessage.FromID = field.NewString(tableName, "from_id")
|
||||
_scaUserMessage.ToID = field.NewString(tableName, "to_id")
|
||||
_scaUserMessage.Content = field.NewString(tableName, "content")
|
||||
_scaUserMessage.IsRead = field.NewInt64(tableName, "is_read")
|
||||
_scaUserMessage.CreatedAt = field.NewTime(tableName, "created_at")
|
||||
_scaUserMessage.UpdatedAt = field.NewTime(tableName, "updated_at")
|
||||
_scaUserMessage.DeletedAt = field.NewField(tableName, "deleted_at")
|
||||
|
||||
_scaUserMessage.fillFieldMap()
|
||||
|
||||
return _scaUserMessage
|
||||
}
|
||||
|
||||
type scaUserMessage struct {
|
||||
scaUserMessageDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Int64 // 主键
|
||||
TopicID field.String // 话题Id
|
||||
FromID field.String // 来自人
|
||||
ToID field.String // 送达人
|
||||
Content field.String // 消息内容
|
||||
IsRead field.Int64 // 是否已读
|
||||
CreatedAt field.Time // 创建时间
|
||||
UpdatedAt field.Time // 更新时间
|
||||
DeletedAt field.Field // 删除时间
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (s scaUserMessage) Table(newTableName string) *scaUserMessage {
|
||||
s.scaUserMessageDo.UseTable(newTableName)
|
||||
return s.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (s scaUserMessage) As(alias string) *scaUserMessage {
|
||||
s.scaUserMessageDo.DO = *(s.scaUserMessageDo.As(alias).(*gen.DO))
|
||||
return s.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (s *scaUserMessage) updateTableName(table string) *scaUserMessage {
|
||||
s.ALL = field.NewAsterisk(table)
|
||||
s.ID = field.NewInt64(table, "id")
|
||||
s.TopicID = field.NewString(table, "topic_id")
|
||||
s.FromID = field.NewString(table, "from_id")
|
||||
s.ToID = field.NewString(table, "to_id")
|
||||
s.Content = field.NewString(table, "content")
|
||||
s.IsRead = field.NewInt64(table, "is_read")
|
||||
s.CreatedAt = field.NewTime(table, "created_at")
|
||||
s.UpdatedAt = field.NewTime(table, "updated_at")
|
||||
s.DeletedAt = field.NewField(table, "deleted_at")
|
||||
|
||||
s.fillFieldMap()
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *scaUserMessage) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
_f, ok := s.fieldMap[fieldName]
|
||||
if !ok || _f == nil {
|
||||
return nil, false
|
||||
}
|
||||
_oe, ok := _f.(field.OrderExpr)
|
||||
return _oe, ok
|
||||
}
|
||||
|
||||
func (s *scaUserMessage) fillFieldMap() {
|
||||
s.fieldMap = make(map[string]field.Expr, 9)
|
||||
s.fieldMap["id"] = s.ID
|
||||
s.fieldMap["topic_id"] = s.TopicID
|
||||
s.fieldMap["from_id"] = s.FromID
|
||||
s.fieldMap["to_id"] = s.ToID
|
||||
s.fieldMap["content"] = s.Content
|
||||
s.fieldMap["is_read"] = s.IsRead
|
||||
s.fieldMap["created_at"] = s.CreatedAt
|
||||
s.fieldMap["updated_at"] = s.UpdatedAt
|
||||
s.fieldMap["deleted_at"] = s.DeletedAt
|
||||
}
|
||||
|
||||
func (s scaUserMessage) clone(db *gorm.DB) scaUserMessage {
|
||||
s.scaUserMessageDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return s
|
||||
}
|
||||
|
||||
func (s scaUserMessage) replaceDB(db *gorm.DB) scaUserMessage {
|
||||
s.scaUserMessageDo.ReplaceDB(db)
|
||||
return s
|
||||
}
|
||||
|
||||
type scaUserMessageDo struct{ gen.DO }
|
||||
|
||||
type IScaUserMessageDo interface {
|
||||
gen.SubQuery
|
||||
Debug() IScaUserMessageDo
|
||||
WithContext(ctx context.Context) IScaUserMessageDo
|
||||
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
|
||||
ReplaceDB(db *gorm.DB)
|
||||
ReadDB() IScaUserMessageDo
|
||||
WriteDB() IScaUserMessageDo
|
||||
As(alias string) gen.Dao
|
||||
Session(config *gorm.Session) IScaUserMessageDo
|
||||
Columns(cols ...field.Expr) gen.Columns
|
||||
Clauses(conds ...clause.Expression) IScaUserMessageDo
|
||||
Not(conds ...gen.Condition) IScaUserMessageDo
|
||||
Or(conds ...gen.Condition) IScaUserMessageDo
|
||||
Select(conds ...field.Expr) IScaUserMessageDo
|
||||
Where(conds ...gen.Condition) IScaUserMessageDo
|
||||
Order(conds ...field.Expr) IScaUserMessageDo
|
||||
Distinct(cols ...field.Expr) IScaUserMessageDo
|
||||
Omit(cols ...field.Expr) IScaUserMessageDo
|
||||
Join(table schema.Tabler, on ...field.Expr) IScaUserMessageDo
|
||||
LeftJoin(table schema.Tabler, on ...field.Expr) IScaUserMessageDo
|
||||
RightJoin(table schema.Tabler, on ...field.Expr) IScaUserMessageDo
|
||||
Group(cols ...field.Expr) IScaUserMessageDo
|
||||
Having(conds ...gen.Condition) IScaUserMessageDo
|
||||
Limit(limit int) IScaUserMessageDo
|
||||
Offset(offset int) IScaUserMessageDo
|
||||
Count() (count int64, err error)
|
||||
Scopes(funcs ...func(gen.Dao) gen.Dao) IScaUserMessageDo
|
||||
Unscoped() IScaUserMessageDo
|
||||
Create(values ...*model.ScaUserMessage) error
|
||||
CreateInBatches(values []*model.ScaUserMessage, batchSize int) error
|
||||
Save(values ...*model.ScaUserMessage) error
|
||||
First() (*model.ScaUserMessage, error)
|
||||
Take() (*model.ScaUserMessage, error)
|
||||
Last() (*model.ScaUserMessage, error)
|
||||
Find() ([]*model.ScaUserMessage, error)
|
||||
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.ScaUserMessage, err error)
|
||||
FindInBatches(result *[]*model.ScaUserMessage, batchSize int, fc func(tx gen.Dao, batch int) error) error
|
||||
Pluck(column field.Expr, dest interface{}) error
|
||||
Delete(...*model.ScaUserMessage) (info gen.ResultInfo, err error)
|
||||
Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
||||
Updates(value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
||||
UpdateColumns(value interface{}) (info gen.ResultInfo, err error)
|
||||
UpdateFrom(q gen.SubQuery) gen.Dao
|
||||
Attrs(attrs ...field.AssignExpr) IScaUserMessageDo
|
||||
Assign(attrs ...field.AssignExpr) IScaUserMessageDo
|
||||
Joins(fields ...field.RelationField) IScaUserMessageDo
|
||||
Preload(fields ...field.RelationField) IScaUserMessageDo
|
||||
FirstOrInit() (*model.ScaUserMessage, error)
|
||||
FirstOrCreate() (*model.ScaUserMessage, error)
|
||||
FindByPage(offset int, limit int) (result []*model.ScaUserMessage, count int64, err error)
|
||||
ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
|
||||
Scan(result interface{}) (err error)
|
||||
Returning(value interface{}, columns ...string) IScaUserMessageDo
|
||||
UnderlyingDB() *gorm.DB
|
||||
schema.Tabler
|
||||
}
|
||||
|
||||
func (s scaUserMessageDo) Debug() IScaUserMessageDo {
|
||||
return s.withDO(s.DO.Debug())
|
||||
}
|
||||
|
||||
func (s scaUserMessageDo) WithContext(ctx context.Context) IScaUserMessageDo {
|
||||
return s.withDO(s.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (s scaUserMessageDo) ReadDB() IScaUserMessageDo {
|
||||
return s.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (s scaUserMessageDo) WriteDB() IScaUserMessageDo {
|
||||
return s.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (s scaUserMessageDo) Session(config *gorm.Session) IScaUserMessageDo {
|
||||
return s.withDO(s.DO.Session(config))
|
||||
}
|
||||
|
||||
func (s scaUserMessageDo) Clauses(conds ...clause.Expression) IScaUserMessageDo {
|
||||
return s.withDO(s.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (s scaUserMessageDo) Returning(value interface{}, columns ...string) IScaUserMessageDo {
|
||||
return s.withDO(s.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (s scaUserMessageDo) Not(conds ...gen.Condition) IScaUserMessageDo {
|
||||
return s.withDO(s.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (s scaUserMessageDo) Or(conds ...gen.Condition) IScaUserMessageDo {
|
||||
return s.withDO(s.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (s scaUserMessageDo) Select(conds ...field.Expr) IScaUserMessageDo {
|
||||
return s.withDO(s.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (s scaUserMessageDo) Where(conds ...gen.Condition) IScaUserMessageDo {
|
||||
return s.withDO(s.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (s scaUserMessageDo) Order(conds ...field.Expr) IScaUserMessageDo {
|
||||
return s.withDO(s.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (s scaUserMessageDo) Distinct(cols ...field.Expr) IScaUserMessageDo {
|
||||
return s.withDO(s.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (s scaUserMessageDo) Omit(cols ...field.Expr) IScaUserMessageDo {
|
||||
return s.withDO(s.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (s scaUserMessageDo) Join(table schema.Tabler, on ...field.Expr) IScaUserMessageDo {
|
||||
return s.withDO(s.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (s scaUserMessageDo) LeftJoin(table schema.Tabler, on ...field.Expr) IScaUserMessageDo {
|
||||
return s.withDO(s.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (s scaUserMessageDo) RightJoin(table schema.Tabler, on ...field.Expr) IScaUserMessageDo {
|
||||
return s.withDO(s.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (s scaUserMessageDo) Group(cols ...field.Expr) IScaUserMessageDo {
|
||||
return s.withDO(s.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (s scaUserMessageDo) Having(conds ...gen.Condition) IScaUserMessageDo {
|
||||
return s.withDO(s.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (s scaUserMessageDo) Limit(limit int) IScaUserMessageDo {
|
||||
return s.withDO(s.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (s scaUserMessageDo) Offset(offset int) IScaUserMessageDo {
|
||||
return s.withDO(s.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (s scaUserMessageDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IScaUserMessageDo {
|
||||
return s.withDO(s.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (s scaUserMessageDo) Unscoped() IScaUserMessageDo {
|
||||
return s.withDO(s.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (s scaUserMessageDo) Create(values ...*model.ScaUserMessage) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return s.DO.Create(values)
|
||||
}
|
||||
|
||||
func (s scaUserMessageDo) CreateInBatches(values []*model.ScaUserMessage, batchSize int) error {
|
||||
return s.DO.CreateInBatches(values, batchSize)
|
||||
}
|
||||
|
||||
// Save : !!! underlying implementation is different with GORM
|
||||
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
|
||||
func (s scaUserMessageDo) Save(values ...*model.ScaUserMessage) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return s.DO.Save(values)
|
||||
}
|
||||
|
||||
func (s scaUserMessageDo) First() (*model.ScaUserMessage, error) {
|
||||
if result, err := s.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.ScaUserMessage), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s scaUserMessageDo) Take() (*model.ScaUserMessage, error) {
|
||||
if result, err := s.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.ScaUserMessage), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s scaUserMessageDo) Last() (*model.ScaUserMessage, error) {
|
||||
if result, err := s.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.ScaUserMessage), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s scaUserMessageDo) Find() ([]*model.ScaUserMessage, error) {
|
||||
result, err := s.DO.Find()
|
||||
return result.([]*model.ScaUserMessage), err
|
||||
}
|
||||
|
||||
func (s scaUserMessageDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.ScaUserMessage, err error) {
|
||||
buf := make([]*model.ScaUserMessage, 0, batchSize)
|
||||
err = s.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
|
||||
defer func() { results = append(results, buf...) }()
|
||||
return fc(tx, batch)
|
||||
})
|
||||
return results, err
|
||||
}
|
||||
|
||||
func (s scaUserMessageDo) FindInBatches(result *[]*model.ScaUserMessage, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return s.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (s scaUserMessageDo) Attrs(attrs ...field.AssignExpr) IScaUserMessageDo {
|
||||
return s.withDO(s.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (s scaUserMessageDo) Assign(attrs ...field.AssignExpr) IScaUserMessageDo {
|
||||
return s.withDO(s.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (s scaUserMessageDo) Joins(fields ...field.RelationField) IScaUserMessageDo {
|
||||
for _, _f := range fields {
|
||||
s = *s.withDO(s.DO.Joins(_f))
|
||||
}
|
||||
return &s
|
||||
}
|
||||
|
||||
func (s scaUserMessageDo) Preload(fields ...field.RelationField) IScaUserMessageDo {
|
||||
for _, _f := range fields {
|
||||
s = *s.withDO(s.DO.Preload(_f))
|
||||
}
|
||||
return &s
|
||||
}
|
||||
|
||||
func (s scaUserMessageDo) FirstOrInit() (*model.ScaUserMessage, error) {
|
||||
if result, err := s.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.ScaUserMessage), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s scaUserMessageDo) FirstOrCreate() (*model.ScaUserMessage, error) {
|
||||
if result, err := s.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.ScaUserMessage), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s scaUserMessageDo) FindByPage(offset int, limit int) (result []*model.ScaUserMessage, count int64, err error) {
|
||||
result, err = s.Offset(offset).Limit(limit).Find()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if size := len(result); 0 < limit && 0 < size && size < limit {
|
||||
count = int64(size + offset)
|
||||
return
|
||||
}
|
||||
|
||||
count, err = s.Offset(-1).Limit(-1).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (s scaUserMessageDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||
count, err = s.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = s.Offset(offset).Limit(limit).Scan(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (s scaUserMessageDo) Scan(result interface{}) (err error) {
|
||||
return s.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (s scaUserMessageDo) Delete(models ...*model.ScaUserMessage) (result gen.ResultInfo, err error) {
|
||||
return s.DO.Delete(models)
|
||||
}
|
||||
|
||||
func (s *scaUserMessageDo) withDO(do gen.Dao) *scaUserMessageDo {
|
||||
s.DO = *do.(*gen.DO)
|
||||
return s
|
||||
}
|
BIN
app/auth/api/resources/ip2region/ip2region.xdb
Normal file
BIN
app/auth/api/resources/ip2region/ip2region.xdb
Normal file
Binary file not shown.
21
app/auth/api/resources/language/active.en.toml
Normal file
21
app/auth/api/resources/language/active.en.toml
Normal file
@@ -0,0 +1,21 @@
|
||||
[captcha]
|
||||
verificationFailure = "verification failure!"
|
||||
[login]
|
||||
invalidAccount = "invalid account!"
|
||||
notFoundAccount = "account not found!"
|
||||
invalidPassword = "invalid password!"
|
||||
loginFailed = "login failed!"
|
||||
phoneFormatError = "phone number format error!"
|
||||
captchaExpired = "captcha expired!"
|
||||
captchaError = "captcha error!"
|
||||
userNotRegistered = "user not registered!"
|
||||
registerError = "register error!"
|
||||
passwordNotMatch = "password not match!"
|
||||
passwordFormatError = "password format error!"
|
||||
resetPasswordError = "reset password error!"
|
||||
loginSuccess = "login success!"
|
||||
|
||||
[sms]
|
||||
smsSendTooFrequently = "sms send too frequently!"
|
||||
smsSendFailed = "sms send failed!"
|
||||
smsSendSuccess = "sms send success!"
|
21
app/auth/api/resources/language/active.zh.toml
Normal file
21
app/auth/api/resources/language/active.zh.toml
Normal file
@@ -0,0 +1,21 @@
|
||||
[captcha]
|
||||
verificationFailure = "验证失败!"
|
||||
[login]
|
||||
invalidAccount = "无效的账号!"
|
||||
notFoundAccount = "未找到账号!"
|
||||
invalidPassword = "密码错误!"
|
||||
loginFailed = "登录失败!"
|
||||
phoneFormatError = "手机号码格式错误!"
|
||||
captchaExpired = "验证码已过期!"
|
||||
captchaError = "验证码错误!"
|
||||
userNotRegistered = "用户未注册!"
|
||||
registerError = "注册失败!"
|
||||
passwordNotMatch = "两次输入的密码不一致!"
|
||||
passwordFormatError = "密码格式错误!"
|
||||
resetPasswordError = "重置密码失败!"
|
||||
loginSuccess = "登录成功!"
|
||||
|
||||
[sms]
|
||||
smsSendTooFrequently = "验证码发送过于频繁,请稍后再试!"
|
||||
smsSendFailed = "短信发送失败!"
|
||||
smsSendSuccess = "短信发送成功!"
|
Reference in New Issue
Block a user