zhipeng.hu
3 years ago
125 changed files with 4367 additions and 0 deletions
-
6api/v1/autocode/enter.go
-
20api/v1/enter.go
-
205config.yaml
-
17config/auto_code.go
-
7config/captcha.go
-
5config/casbin.go
-
30config/config.go
-
14config/cors.go
-
21config/db_list.go
-
11config/email.go
-
5config/excel.go
-
18config/gorm_mysql.go
-
26config/gorm_pgsql.go
-
8config/jwt.go
-
10config/oss_aliyun.go
-
10config/oss_aws.go
-
9config/oss_huawei.go
-
5config/oss_local.go
-
11config/oss_qiniu.go
-
10config/oss_tencent.go
-
7config/redis.go
-
11config/system.go
-
13config/timer.go
-
12config/zap.go
-
34core/server.go
-
19core/server_other.go
-
21core/server_win.go
-
66core/viper.go
-
97core/zap.go
-
23global/global.go
-
13global/model.go
-
103go.mod
-
31initialize/db_list.go
-
40initialize/gorm.go
-
52initialize/gorm_mysql.go
-
50initialize/gorm_pgsql.go
-
39initialize/internal/gorm.go
-
35initialize/internal/logger.go
-
23initialize/redis.go
-
60initialize/router.go
-
2log/2022-01-15.log
-
3log/server_error.log
-
36log/server_info.log
-
22main.go
-
12model/autocode/autocodeExample.go
-
13model/autocode/request/autocodeExample.go
-
27model/common/request/common.go
-
8model/common/response/common.go
-
55model/common/response/response.go
-
24model/example/exa_breakpoint_continue.go
-
15model/example/exa_customer.go
-
8model/example/exa_excel.go
-
13model/example/exa_file_upload_download.go
-
11model/example/response/exa_breakpoint_continue.go
-
7model/example/response/exa_customer.go
-
7model/example/response/exa_file_upload_download.go
-
21model/system/request/jwt.go
-
14model/system/request/sys_api.go
-
7model/system/request/sys_auto_history.go
-
26model/system/request/sys_casbin.go
-
11model/system/request/sys_dictionary.go
-
11model/system/request/sys_dictionary_detail.go
-
66model/system/request/sys_init.go
-
27model/system/request/sys_menu.go
-
11model/system/request/sys_operation_record.go
-
37model/system/request/sys_user.go
-
11model/system/response/sys_api.go
-
12model/system/response/sys_authority.go
-
16model/system/response/sys_auto_code.go
-
13model/system/response/sys_auto_code_history.go
-
9model/system/response/sys_casbin.go
-
15model/system/response/sys_menu.go
-
7model/system/response/sys_system.go
-
15model/system/response/sys_user.go
-
13model/system/sys_api.go
-
18model/system/sys_authority.go
-
13model/system/sys_authority_menu.go
-
31model/system/sys_auto_code.go
-
38model/system/sys_autocode_history.go
-
36model/system/sys_base_menu.go
-
8model/system/sys_casbin.go
-
16model/system/sys_dictionary.go
-
16model/system/sys_dictionary_detail.go
-
79model/system/sys_initdb.go
-
10model/system/sys_jwt_blacklist.go
-
24model/system/sys_operation_record.go
-
10model/system/sys_system.go
-
21model/system/sys_user.go
-
10model/system/sys_user_authority.go
-
4packfile/notUsePackFile.go
-
46packfile/usePackFile.go
-
20router/autocode/auto_code_example.go
-
7router/autocode/enter.go
-
11router/enter.go
-
77service/autocode/auto_code_example.go
-
7service/autocode/enter.go
-
11service/enter.go
-
108utils/breakpoint_continue.go
-
57utils/captcha/redis.go
-
74utils/clamis.go
@ -0,0 +1,6 @@ |
|||
package autocode |
|||
|
|||
type ApiGroup struct { |
|||
// Code generated by github.com/flipped-aurora/yibu/server Begin; DO NOT EDIT.
|
|||
// Code generated by github.com/flipped-aurora/yibu/server End; DO NOT EDIT.
|
|||
} |
@ -0,0 +1,20 @@ |
|||
package v1 |
|||
|
|||
import ( |
|||
"autocode/api/v1/autocode" |
|||
"github.com/gin-gonic/gin" |
|||
) |
|||
|
|||
type ApiGroup struct { |
|||
AutoCodeApiGroup autocode.ApiGroup |
|||
} |
|||
|
|||
func (g ApiGroup) CreateAutoCodeExample(context *gin.Context) { |
|||
context.String(200, "creat") |
|||
} |
|||
|
|||
func (g ApiGroup) FindAutoCodeExample(context *gin.Context) { |
|||
context.String(200, "find") |
|||
} |
|||
|
|||
var ApiGroupApp = new(ApiGroup) |
@ -0,0 +1,205 @@ |
|||
# github.com/flipped-aurora/yibu/server Global Configuration |
|||
|
|||
# jwt configuration |
|||
jwt: |
|||
signing-key: 'qmPlus' |
|||
expires-time: 604800 |
|||
buffer-time: 86400 |
|||
issuer: 'qmPlus' |
|||
# zap logger configuration |
|||
zap: |
|||
level: 'info' |
|||
format: 'console' |
|||
prefix: '[github.com/flipped-aurora/yibu/server]' |
|||
director: 'log' |
|||
show-line: true |
|||
encode-level: 'LowercaseColorLevelEncoder' |
|||
stacktrace-key: 'stacktrace' |
|||
log-in-console: true |
|||
|
|||
# redis configuration |
|||
redis: |
|||
db: 0 |
|||
addr: '127.0.0.1:6379' |
|||
password: '' |
|||
|
|||
# email configuration |
|||
email: |
|||
to: 'xxx@qq.com' |
|||
port: 465 |
|||
from: 'xxx@163.com' |
|||
host: 'smtp.163.com' |
|||
is-ssl: true |
|||
secret: 'xxx' |
|||
nickname: 'test' |
|||
|
|||
# casbin configuration |
|||
casbin: |
|||
model-path: './resource/rbac_model.conf' |
|||
|
|||
# system configuration |
|||
system: |
|||
env: 'public' # Change to "develop" to skip authentication for development mode |
|||
addr: 8888 |
|||
db-type: 'mysql' |
|||
oss-type: 'local' # 控制oss选择走本地还是 七牛等其他仓 自行增加其他oss仓可以在 server/utils/upload/upload.go 中 NewOss函数配置 |
|||
use-multipoint: false |
|||
# IP限制次数 一个小时15000次 |
|||
iplimit-count: 15000 |
|||
# IP限制一个小时 |
|||
iplimit-time: 3600 |
|||
|
|||
# captcha configuration |
|||
captcha: |
|||
key-long: 6 |
|||
img-width: 240 |
|||
img-height: 80 |
|||
|
|||
# mysql connect configuration |
|||
# 未初始化之前请勿手动修改数据库信息!!!如果一定要手动初始化请看(https://www.github.com/flipped-aurora/gin-vue-admin/server.com/docs/first) |
|||
mysql: |
|||
path: '' |
|||
port: '' |
|||
config: '' |
|||
db-name: '' |
|||
username: '' |
|||
password: '' |
|||
max-idle-conns: 10 |
|||
max-open-conns: 100 |
|||
log-mode: "" |
|||
log-zap: false |
|||
|
|||
# pgsql connect configuration |
|||
# 未初始化之前请勿手动修改数据库信息!!!如果一定要手动初始化请看(https://www.github.com/flipped-aurora/gin-vue-admin/server.com/docs/first) |
|||
pgsql: |
|||
path: '' |
|||
port: '' |
|||
config: '' |
|||
db-name: '' |
|||
username: '' |
|||
password: '' |
|||
max-idle-conns: 10 |
|||
max-open-conns: 100 |
|||
log-mode: "" |
|||
log-zap: false |
|||
|
|||
db-list: [ |
|||
{ |
|||
disabled: true, # 是否启用 |
|||
type: "", # 数据库的类型,目前支持mysql、pgsql |
|||
alias-name: "", # 数据库的名称,注意: alias-name 需要在db-list中唯一 |
|||
path: '', |
|||
port: '', |
|||
config: '', |
|||
db-name: '', |
|||
username: '', |
|||
password: '', |
|||
max-idle-conns: 10, |
|||
max-open-conns: 100, |
|||
log-mode: "", |
|||
log-zap: false, |
|||
} |
|||
] |
|||
|
|||
|
|||
|
|||
# local configuration |
|||
local: |
|||
path: 'uploads/file' |
|||
|
|||
# autocode configuration |
|||
autocode: |
|||
transfer-restart: true |
|||
# root 自动适配项目根目录 |
|||
# 请不要手动配置,他会在项目加载的时候识别出根路径 |
|||
root: "" |
|||
server: /server |
|||
server-api: /api/v1/autocode |
|||
server-initialize: /initialize |
|||
server-model: /model/autocode |
|||
server-request: /model/autocode/request/ |
|||
server-router: /router/autocode |
|||
server-service: /service/autocode |
|||
web: /web/src |
|||
web-api: /api |
|||
web-form: /view |
|||
web-table: /view |
|||
|
|||
# qiniu configuration (请自行七牛申请对应的 公钥 私钥 bucket 和 域名地址) |
|||
qiniu: |
|||
zone: 'ZoneHuaDong' |
|||
bucket: '' |
|||
img-path: '' |
|||
use-https: false |
|||
access-key: '' |
|||
secret-key: '' |
|||
use-cdn-domains: false |
|||
|
|||
# aliyun oss configuration |
|||
aliyun-oss: |
|||
endpoint: 'yourEndpoint' |
|||
access-key-id: 'yourAccessKeyId' |
|||
access-key-secret: 'yourAccessKeySecret' |
|||
bucket-name: 'yourBucketName' |
|||
bucket-url: 'yourBucketUrl' |
|||
base-path: 'yourBasePath' |
|||
|
|||
# tencent cos configuration |
|||
tencent-cos: |
|||
bucket: 'xxxxx-10005608' |
|||
region: 'ap-shanghai' |
|||
secret-id: 'xxxxxxxx' |
|||
secret-key: 'xxxxxxxx' |
|||
base-url: 'https://gin.vue.admin' |
|||
path-prefix: 'github.com/flipped-aurora/yibu/server' |
|||
|
|||
# aws s3 configuration |
|||
aws-s3: |
|||
bucket: xxxxx-10005608 |
|||
region: ap-shanghai |
|||
secret-id: xxxxxxxx |
|||
secret-key: xxxxxxxx |
|||
base-url: https://gin.vue.admin |
|||
path-prefix: github.com/flipped-aurora/yibu/server |
|||
|
|||
# huawei obs configuration |
|||
hua-wei-obs: |
|||
path: 'you-path' |
|||
bucket: 'you-bucket' |
|||
endpoint: 'you-endpoint' |
|||
access-key: 'you-access-key' |
|||
secret-key: 'you-secret-key' |
|||
|
|||
# excel configuration |
|||
excel: |
|||
dir: './resource/excel/' |
|||
|
|||
# timer task db clear table |
|||
Timer: |
|||
start: true |
|||
spec: "@daily" # 定时任务详细配置参考 https://pkg.go.dev/github.com/robfig/cron/v3 |
|||
detail: [ |
|||
# tableName: 需要清理的表名 |
|||
# compareField: 需要比较时间的字段 |
|||
# interval: 时间间隔, 具体配置详看 time.ParseDuration() 中字符串表示 且不能为负数 |
|||
# 2160h = 24 * 30 * 3 -> 三个月 |
|||
{ tableName: "sys_operation_records" , compareField: "created_at", interval: "2160h" }, |
|||
{ tableName: "jwt_blacklists" , compareField: "created_at", interval: "168h" } |
|||
#{ tableName: "log2" , compareField: "created_at", interval: "2160h" } |
|||
] |
|||
|
|||
# 跨域配置 |
|||
# 需要配合 server/initialize/router.go#L32 使用 |
|||
cors: |
|||
mode: whitelist # 放行模式: allow-all, 放行全部; whitelist, 白名单模式, 来自白名单内域名的请求添加 cors 头; strict-whitelist 严格白名单模式, 白名单外的请求一律拒绝 |
|||
whitelist: |
|||
- allow-origin: example1.com |
|||
allow-headers: content-type |
|||
allow-methods: GET, POST |
|||
expose-headers: Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers, Content-Type |
|||
allow-credentials: true # 布尔值 |
|||
- allow-origin: example2.com |
|||
allow-headers: content-type |
|||
allow-methods: GET, POST |
|||
expose-headers: Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers, Content-Type |
|||
allow-credentials: true # 布尔值 |
@ -0,0 +1,17 @@ |
|||
package config |
|||
|
|||
type Autocode struct { |
|||
TransferRestart bool `mapstructure:"transfer-restart" json:"transferRestart" yaml:"transfer-restart"` |
|||
Root string `mapstructure:"root" json:"root" yaml:"root"` |
|||
Server string `mapstructure:"server" json:"server" yaml:"server"` |
|||
SApi string `mapstructure:"server-api" json:"serverApi" yaml:"server-api"` |
|||
SInitialize string `mapstructure:"server-initialize" json:"serverInitialize" yaml:"server-initialize"` |
|||
SModel string `mapstructure:"server-model" json:"serverModel" yaml:"server-model"` |
|||
SRequest string `mapstructure:"server-request" json:"serverRequest" yaml:"server-request"` |
|||
SRouter string `mapstructure:"server-router" json:"serverRouter" yaml:"server-router"` |
|||
SService string `mapstructure:"server-service" json:"serverService" yaml:"server-service"` |
|||
Web string `mapstructure:"web" json:"web" yaml:"web"` |
|||
WApi string `mapstructure:"web-api" json:"webApi" yaml:"web-api"` |
|||
WForm string `mapstructure:"web-form" json:"webForm" yaml:"web-form"` |
|||
WTable string `mapstructure:"web-table" json:"webTable" yaml:"web-table"` |
|||
} |
@ -0,0 +1,7 @@ |
|||
package config |
|||
|
|||
type Captcha struct { |
|||
KeyLong int `mapstructure:"key-long" json:"keyLong" yaml:"key-long"` // 验证码长度
|
|||
ImgWidth int `mapstructure:"img-width" json:"imgWidth" yaml:"img-width"` // 验证码宽度
|
|||
ImgHeight int `mapstructure:"img-height" json:"imgHeight" yaml:"img-height"` // 验证码高度
|
|||
} |
@ -0,0 +1,5 @@ |
|||
package config |
|||
|
|||
type Casbin struct { |
|||
ModelPath string `mapstructure:"model-path" json:"modelPath" yaml:"model-path"` // 存放casbin模型的相对路径
|
|||
} |
@ -0,0 +1,30 @@ |
|||
package config |
|||
|
|||
type Server struct { |
|||
JWT JWT `mapstructure:"jwt" json:"jwt" yaml:"jwt"` |
|||
Zap Zap `mapstructure:"zap" json:"zap" yaml:"zap"` |
|||
Redis Redis `mapstructure:"redis" json:"redis" yaml:"redis"` |
|||
Email Email `mapstructure:"email" json:"email" yaml:"email"` |
|||
Casbin Casbin `mapstructure:"casbin" json:"casbin" yaml:"casbin"` |
|||
System System `mapstructure:"system" json:"system" yaml:"system"` |
|||
Captcha Captcha `mapstructure:"captcha" json:"captcha" yaml:"captcha"` |
|||
// auto
|
|||
AutoCode Autocode `mapstructure:"autoCode" json:"autoCode" yaml:"autoCode"` |
|||
// gorm
|
|||
Mysql Mysql `mapstructure:"mysql" json:"mysql" yaml:"mysql"` |
|||
Pgsql Pgsql `mapstructure:"pgsql" json:"pgsql" yaml:"pgsql"` |
|||
DBList []DB `mapstructure:"db-list" json:"db-list" yaml:"db-list"` |
|||
// oss
|
|||
Local Local `mapstructure:"local" json:"local" yaml:"local"` |
|||
Qiniu Qiniu `mapstructure:"qiniu" json:"qiniu" yaml:"qiniu"` |
|||
AliyunOSS AliyunOSS `mapstructure:"aliyun-oss" json:"aliyunOSS" yaml:"aliyun-oss"` |
|||
HuaWeiObs HuaWeiObs `mapstructure:"hua-wei-obs" json:"huaWeiObs" yaml:"hua-wei-obs"` |
|||
TencentCOS TencentCOS `mapstructure:"tencent-cos" json:"tencentCOS" yaml:"tencent-cos"` |
|||
AwsS3 AwsS3 `mapstructure:"aws-s3" json:"awsS3" yaml:"aws-s3"` |
|||
|
|||
Excel Excel `mapstructure:"excel" json:"excel" yaml:"excel"` |
|||
Timer Timer `mapstructure:"timer" json:"timer" yaml:"timer"` |
|||
|
|||
// 跨域配置
|
|||
Cors CORS `mapstructure:"cors" json:"cors" yaml:"cors"` |
|||
} |
@ -0,0 +1,14 @@ |
|||
package config |
|||
|
|||
type CORS struct { |
|||
Mode string `mapstructure:"mode" json:"mode" yaml:"mode"` |
|||
Whitelist []CORSWhitelist `mapstructure:"whitelist" json:"whitelist" yaml:"whitelist"` |
|||
} |
|||
|
|||
type CORSWhitelist struct { |
|||
AllowOrigin string `mapstructure:"allow-origin" json:"allow-origin" yaml:"allow-origin"` |
|||
AllowMethods string `mapstructure:"allow-methods" json:"allow-methods" yaml:"allow-methods"` |
|||
AllowHeaders string `mapstructure:"allow-headers" json:"allow-headers" yaml:"allow-headers"` |
|||
ExposeHeaders string `mapstructure:"expose-headers" json:"expose-headers" yaml:"expose-headers"` |
|||
AllowCredentials bool `mapstructure:"allow-credentials" json:"allow-credentials" yaml:"allow-credentials"` |
|||
} |
@ -0,0 +1,21 @@ |
|||
package config |
|||
|
|||
type DB struct { |
|||
Disable bool `mapstructure:"disable" json:"disable" yaml:"disable"` |
|||
Type string `mapstructure:"type" json:"type" yaml:"type"` |
|||
AliasName string `mapstructure:"alias-name" json:"alias-name" yaml:"alias-name"` |
|||
Path string `mapstructure:"path" json:"path" yaml:"path"` // 服务器地址:端口
|
|||
Port string `mapstructure:"port" json:"port" yaml:"port"` //:端口
|
|||
Config string `mapstructure:"config" json:"config" yaml:"config"` // 高级配置
|
|||
Dbname string `mapstructure:"db-name" json:"dbname" yaml:"db-name"` // 数据库名
|
|||
Username string `mapstructure:"username" json:"username" yaml:"username"` // 数据库用户名
|
|||
Password string `mapstructure:"password" json:"password" yaml:"password"` // 数据库密码
|
|||
MaxIdleConns int `mapstructure:"max-idle-conns" json:"maxIdleConns" yaml:"max-idle-conns"` // 空闲中的最大连接数
|
|||
MaxOpenConns int `mapstructure:"max-open-conns" json:"maxOpenConns" yaml:"max-open-conns"` // 打开到数据库的最大连接数
|
|||
LogMode string `mapstructure:"log-mode" json:"logMode" yaml:"log-mode"` // 是否开启Gorm全局日志
|
|||
LogZap bool `mapstructure:"log-zap" json:"logZap" yaml:"log-zap"` |
|||
} |
|||
|
|||
func (m *DB) Dsn() string { |
|||
return m.Username + ":" + m.Password + "@tcp(" + m.Path + ":" + m.Port + ")/" + m.Dbname + "?" + m.Config |
|||
} |
@ -0,0 +1,11 @@ |
|||
package config |
|||
|
|||
type Email struct { |
|||
To string `mapstructure:"to" json:"to" yaml:"to"` // 收件人:多个以英文逗号分隔
|
|||
Port int `mapstructure:"port" json:"port" yaml:"port"` // 端口
|
|||
From string `mapstructure:"from" json:"from" yaml:"from"` // 收件人
|
|||
Host string `mapstructure:"host" json:"host" yaml:"host"` // 服务器地址
|
|||
IsSSL bool `mapstructure:"is-ssl" json:"isSSL" yaml:"is-ssl"` // 是否SSL
|
|||
Secret string `mapstructure:"secret" json:"secret" yaml:"secret"` // 密钥
|
|||
Nickname string `mapstructure:"nickname" json:"nickname" yaml:"nickname"` // 昵称
|
|||
} |
@ -0,0 +1,5 @@ |
|||
package config |
|||
|
|||
type Excel struct { |
|||
Dir string `mapstructure:"dir" json:"dir" yaml:"dir"` |
|||
} |
@ -0,0 +1,18 @@ |
|||
package config |
|||
|
|||
type Mysql struct { |
|||
Path string `mapstructure:"path" json:"path" yaml:"path"` // 服务器地址
|
|||
Port string `mapstructure:"port" json:"port" yaml:"port"` // 端口
|
|||
Config string `mapstructure:"config" json:"config" yaml:"config"` // 高级配置
|
|||
Dbname string `mapstructure:"db-name" json:"dbname" yaml:"db-name"` // 数据库名
|
|||
Username string `mapstructure:"username" json:"username" yaml:"username"` // 数据库用户名
|
|||
Password string `mapstructure:"password" json:"password" yaml:"password"` // 数据库密码
|
|||
MaxIdleConns int `mapstructure:"max-idle-conns" json:"maxIdleConns" yaml:"max-idle-conns"` // 空闲中的最大连接数
|
|||
MaxOpenConns int `mapstructure:"max-open-conns" json:"maxOpenConns" yaml:"max-open-conns"` // 打开到数据库的最大连接数
|
|||
LogMode string `mapstructure:"log-mode" json:"logMode" yaml:"log-mode"` // 是否开启Gorm全局日志
|
|||
LogZap bool `mapstructure:"log-zap" json:"logZap" yaml:"log-zap"` // 是否通过zap写入日志文件
|
|||
} |
|||
|
|||
func (m *Mysql) Dsn() string { |
|||
return m.Username + ":" + m.Password + "@tcp(" + m.Path + ":" + m.Port + ")/" + m.Dbname + "?" + m.Config |
|||
} |
@ -0,0 +1,26 @@ |
|||
package config |
|||
|
|||
type Pgsql struct { |
|||
Path string `mapstructure:"path" json:"path" yaml:"path"` // 服务器地址:端口
|
|||
Port string `mapstructure:"port" json:"port" yaml:"port"` //:端口
|
|||
Config string `mapstructure:"config" json:"config" yaml:"config"` // 高级配置
|
|||
Dbname string `mapstructure:"db-name" json:"dbname" yaml:"db-name"` // 数据库名
|
|||
Username string `mapstructure:"username" json:"username" yaml:"username"` // 数据库用户名
|
|||
Password string `mapstructure:"password" json:"password" yaml:"password"` // 数据库密码
|
|||
MaxIdleConns int `mapstructure:"max-idle-conns" json:"maxIdleConns" yaml:"max-idle-conns"` // 空闲中的最大连接数
|
|||
MaxOpenConns int `mapstructure:"max-open-conns" json:"maxOpenConns" yaml:"max-open-conns"` // 打开到数据库的最大连接数
|
|||
LogMode string `mapstructure:"log-mode" json:"logMode" yaml:"log-mode"` // 是否开启Gorm全局日志
|
|||
LogZap bool `mapstructure:"log-zap" json:"logZap" yaml:"log-zap"` // 是否通过zap写入日志文件
|
|||
} |
|||
|
|||
// Dsn 基于配置文件获取 dsn
|
|||
// Author [SliverHorn](https://github.com/SliverHorn)
|
|||
func (p *Pgsql) Dsn() string { |
|||
return "host=" + p.Path + " user=" + p.Username + " password=" + p.Password + " dbname=" + p.Dbname + " port=" + p.Port + " " + p.Config |
|||
} |
|||
|
|||
// LinkDsn 根据 dbname 生成 dsn
|
|||
// Author [SliverHorn](https://github.com/SliverHorn)
|
|||
func (p *Pgsql) LinkDsn(dbname string) string { |
|||
return "host=" + p.Path + " user=" + p.Username + " password=" + p.Password + " dbname=" + dbname + " port=" + p.Port + " " + p.Config |
|||
} |
@ -0,0 +1,8 @@ |
|||
package config |
|||
|
|||
type JWT struct { |
|||
SigningKey string `mapstructure:"signing-key" json:"signingKey" yaml:"signing-key"` // jwt签名
|
|||
ExpiresTime int64 `mapstructure:"expires-time" json:"expiresTime" yaml:"expires-time"` // 过期时间
|
|||
BufferTime int64 `mapstructure:"buffer-time" json:"bufferTime" yaml:"buffer-time"` // 缓冲时间
|
|||
Issuer string `mapstructure:"issuer" json:"issuer" yaml:"issuer"` // 签发者
|
|||
} |
@ -0,0 +1,10 @@ |
|||
package config |
|||
|
|||
type AliyunOSS struct { |
|||
Endpoint string `mapstructure:"endpoint" json:"endpoint" yaml:"endpoint"` |
|||
AccessKeyId string `mapstructure:"access-key-id" json:"accessKeyId" yaml:"access-key-id"` |
|||
AccessKeySecret string `mapstructure:"access-key-secret" json:"accessKeySecret" yaml:"access-key-secret"` |
|||
BucketName string `mapstructure:"bucket-name" json:"bucketName" yaml:"bucket-name"` |
|||
BucketUrl string `mapstructure:"bucket-url" json:"bucketUrl" yaml:"bucket-url"` |
|||
BasePath string `mapstructure:"base-path" json:"basePath" yaml:"base-path"` |
|||
} |
@ -0,0 +1,10 @@ |
|||
package config |
|||
|
|||
type AwsS3 struct { |
|||
Bucket string `mapstructure:"bucket" json:"bucket" yaml:"bucket"` |
|||
Region string `mapstructure:"region" json:"region" yaml:"region"` |
|||
SecretID string `mapstructure:"secret-id" json:"secretID" yaml:"secret-id"` |
|||
SecretKey string `mapstructure:"secret-key" json:"secretKey" yaml:"secret-key"` |
|||
BaseURL string `mapstructure:"base-url" json:"baseURL" yaml:"base-url"` |
|||
PathPrefix string `mapstructure:"path-prefix" json:"pathPrefix" yaml:"path-prefix"` |
|||
} |
@ -0,0 +1,9 @@ |
|||
package config |
|||
|
|||
type HuaWeiObs struct { |
|||
Path string `mapstructure:"path" json:"path" yaml:"path"` |
|||
Bucket string `mapstructure:"bucket" json:"bucket" yaml:"bucket"` |
|||
Endpoint string `mapstructure:"endpoint" json:"endpoint" yaml:"endpoint"` |
|||
AccessKey string `mapstructure:"access-key" json:"accessKey" yaml:"access-key"` |
|||
SecretKey string `mapstructure:"secret-key" json:"secretKey" yaml:"secret-key"` |
|||
} |
@ -0,0 +1,5 @@ |
|||
package config |
|||
|
|||
type Local struct { |
|||
Path string `mapstructure:"path" json:"path" yaml:"path"` // 本地文件路径
|
|||
} |
@ -0,0 +1,11 @@ |
|||
package config |
|||
|
|||
type Qiniu struct { |
|||
Zone string `mapstructure:"zone" json:"zone" yaml:"zone"` // 存储区域
|
|||
Bucket string `mapstructure:"bucket" json:"bucket" yaml:"bucket"` // 空间名称
|
|||
ImgPath string `mapstructure:"img-path" json:"imgPath" yaml:"img-path"` // CDN加速域名
|
|||
UseHTTPS bool `mapstructure:"use-https" json:"useHttps" yaml:"use-https"` // 是否使用https
|
|||
AccessKey string `mapstructure:"access-key" json:"accessKey" yaml:"access-key"` // 秘钥AK
|
|||
SecretKey string `mapstructure:"secret-key" json:"secretKey" yaml:"secret-key"` // 秘钥SK
|
|||
UseCdnDomains bool `mapstructure:"use-cdn-domains" json:"useCdnDomains" yaml:"use-cdn-domains"` // 上传是否使用CDN上传加速
|
|||
} |
@ -0,0 +1,10 @@ |
|||
package config |
|||
|
|||
type TencentCOS struct { |
|||
Bucket string `mapstructure:"bucket" json:"bucket" yaml:"bucket"` |
|||
Region string `mapstructure:"region" json:"region" yaml:"region"` |
|||
SecretID string `mapstructure:"secret-id" json:"secretID" yaml:"secret-id"` |
|||
SecretKey string `mapstructure:"secret-key" json:"secretKey" yaml:"secret-key"` |
|||
BaseURL string `mapstructure:"base-url" json:"baseURL" yaml:"base-url"` |
|||
PathPrefix string `mapstructure:"path-prefix" json:"pathPrefix" yaml:"path-prefix"` |
|||
} |
@ -0,0 +1,7 @@ |
|||
package config |
|||
|
|||
type Redis struct { |
|||
DB int `mapstructure:"db" json:"db" yaml:"db"` // redis的哪个数据库
|
|||
Addr string `mapstructure:"addr" json:"addr" yaml:"addr"` // 服务器地址:端口
|
|||
Password string `mapstructure:"password" json:"password" yaml:"password"` // 密码
|
|||
} |
@ -0,0 +1,11 @@ |
|||
package config |
|||
|
|||
type System struct { |
|||
Env string `mapstructure:"env" json:"env" yaml:"env"` // 环境值
|
|||
Addr int `mapstructure:"addr" json:"addr" yaml:"addr"` // 端口值
|
|||
DbType string `mapstructure:"db-type" json:"dbType" yaml:"db-type"` // 数据库类型:mysql(默认)|sqlite|sqlserver|postgresql
|
|||
OssType string `mapstructure:"oss-type" json:"ossType" yaml:"oss-type"` // Oss类型
|
|||
UseMultipoint bool `mapstructure:"use-multipoint" json:"useMultipoint" yaml:"use-multipoint"` // 多点登录拦截
|
|||
LimitCountIP int `mapstructure:"iplimit-count" json:"iplimitCount" yaml:"iplimit-count"` |
|||
LimitTimeIP int `mapstructure:"iplimit-time" json:"iplimitTime" yaml:"iplimit-time"` |
|||
} |
@ -0,0 +1,13 @@ |
|||
package config |
|||
|
|||
type Timer struct { |
|||
Start bool `mapstructure:"start" json:"start" yaml:"start"` // 是否启用
|
|||
Spec string `mapstructure:"spec" json:"spec" yaml:"spec"` // CRON表达式
|
|||
Detail []Detail `mapstructure:"detail" json:"detail" yaml:"detail"` |
|||
} |
|||
|
|||
type Detail struct { |
|||
TableName string `mapstructure:"tableName" json:"tableName" yaml:"tableName"` // 需要清理的表名
|
|||
CompareField string `mapstructure:"compareField" json:"compareField" yaml:"compareField"` // 需要比较时间的字段
|
|||
Interval string `mapstructure:"interval" json:"interval" yaml:"interval"` // 时间间隔
|
|||
} |
@ -0,0 +1,12 @@ |
|||
package config |
|||
|
|||
type Zap struct { |
|||
Level string `mapstructure:"level" json:"level" yaml:"level"` // 级别
|
|||
Format string `mapstructure:"format" json:"format" yaml:"format"` // 输出
|
|||
Prefix string `mapstructure:"prefix" json:"prefix" yaml:"prefix"` // 日志前缀
|
|||
Director string `mapstructure:"director" json:"director" yaml:"director"` // 日志文件夹
|
|||
ShowLine bool `mapstructure:"show-line" json:"showLine" yaml:"showLine"` // 显示行
|
|||
EncodeLevel string `mapstructure:"encode-level" json:"encodeLevel" yaml:"encode-level"` // 编码级
|
|||
StacktraceKey string `mapstructure:"stacktrace-key" json:"stacktraceKey" yaml:"stacktrace-key"` // 栈名
|
|||
LogInConsole bool `mapstructure:"log-in-console" json:"logInConsole" yaml:"log-in-console"` // 输出控制台
|
|||
} |
@ -0,0 +1,34 @@ |
|||
package core |
|||
|
|||
import ( |
|||
"fmt" |
|||
"time" |
|||
|
|||
"autocode/global" |
|||
"autocode/initialize" |
|||
"go.uber.org/zap" |
|||
) |
|||
|
|||
type server interface { |
|||
ListenAndServe() error |
|||
} |
|||
|
|||
func RunWindowsServer() { |
|||
if global.GVA_CONFIG.System.UseMultipoint { |
|||
// 初始化redis服务
|
|||
initialize.Redis() |
|||
} |
|||
|
|||
Router := initialize.Routers() |
|||
|
|||
Router.Static("/form-generator", "./resource/page") |
|||
|
|||
address := fmt.Sprintf(":%d", global.GVA_CONFIG.System.Addr) |
|||
s := initServer(address, Router) |
|||
// 保证文本顺序输出
|
|||
// In order to ensure that the text order output can be deleted
|
|||
time.Sleep(10 * time.Microsecond) |
|||
global.GVA_LOG.Info("server run success on ", zap.String("address", address)) |
|||
|
|||
global.GVA_LOG.Error(s.ListenAndServe().Error()) |
|||
} |
@ -0,0 +1,19 @@ |
|||
//go:build !windows
|
|||
// +build !windows
|
|||
|
|||
package core |
|||
|
|||
import ( |
|||
"time" |
|||
|
|||
"github.com/fvbock/endless" |
|||
"github.com/gin-gonic/gin" |
|||
) |
|||
|
|||
func initServer(address string, router *gin.Engine) server { |
|||
s := endless.NewServer(address, router) |
|||
s.ReadHeaderTimeout = 20 * time.Second |
|||
s.WriteTimeout = 20 * time.Second |
|||
s.MaxHeaderBytes = 1 << 20 |
|||
return s |
|||
} |
@ -0,0 +1,21 @@ |
|||
//go:build windows
|
|||
// +build windows
|
|||
|
|||
package core |
|||
|
|||
import ( |
|||
"net/http" |
|||
"time" |
|||
|
|||
"github.com/gin-gonic/gin" |
|||
) |
|||
|
|||
func initServer(address string, router *gin.Engine) server { |
|||
return &http.Server{ |
|||
Addr: address, |
|||
Handler: router, |
|||
ReadTimeout: 20 * time.Second, |
|||
WriteTimeout: 20 * time.Second, |
|||
MaxHeaderBytes: 1 << 20, |
|||
} |
|||
} |
@ -0,0 +1,66 @@ |
|||
package core |
|||
|
|||
import ( |
|||
"flag" |
|||
"fmt" |
|||
"os" |
|||
"path/filepath" |
|||
"time" |
|||
|
|||
"github.com/songzhibin97/gkit/cache/local_cache" |
|||
|
|||
"autocode/global" |
|||
_ "autocode/packfile" |
|||
"autocode/utils" |
|||
|
|||
"github.com/fsnotify/fsnotify" |
|||
"github.com/spf13/viper" |
|||
) |
|||
|
|||
func Viper(path ...string) *viper.Viper { |
|||
var config string |
|||
if len(path) == 0 { |
|||
flag.StringVar(&config, "c", "", "choose config file.") |
|||
flag.Parse() |
|||
if config == "" { // 优先级: 命令行 > 环境变量 > 默认值
|
|||
if configEnv := os.Getenv(utils.ConfigEnv); configEnv == "" { |
|||
config = utils.ConfigFile |
|||
fmt.Printf("您正在使用config的默认值,config的路径为%v\n", utils.ConfigFile) |
|||
} else { |
|||
config = configEnv |
|||
fmt.Printf("您正在使用GVA_CONFIG环境变量,config的路径为%v\n", config) |
|||
} |
|||
} else { |
|||
fmt.Printf("您正在使用命令行的-c参数传递的值,config的路径为%v\n", config) |
|||
} |
|||
} else { |
|||
config = path[0] |
|||
fmt.Printf("您正在使用func Viper()传递的值,config的路径为%v\n", config) |
|||
} |
|||
|
|||
v := viper.New() |
|||
v.SetConfigFile(config) |
|||
v.SetConfigType("yaml") |
|||
err := v.ReadInConfig() |
|||
if err != nil { |
|||
panic(fmt.Errorf("Fatal error config file: %s \n", err)) |
|||
} |
|||
v.WatchConfig() |
|||
|
|||
v.OnConfigChange(func(e fsnotify.Event) { |
|||
fmt.Println("config file changed:", e.Name) |
|||
if err := v.Unmarshal(&global.GVA_CONFIG); err != nil { |
|||
fmt.Println(err) |
|||
} |
|||
}) |
|||
if err := v.Unmarshal(&global.GVA_CONFIG); err != nil { |
|||
fmt.Println(err) |
|||
} |
|||
// root 适配性
|
|||
// 根据root位置去找到对应迁移位置,保证root路径有效
|
|||
global.GVA_CONFIG.AutoCode.Root, _ = filepath.Abs("..") |
|||
global.BlackCache = local_cache.NewCache( |
|||
local_cache.SetDefaultExpire(time.Second * time.Duration(global.GVA_CONFIG.JWT.ExpiresTime)), |
|||
) |
|||
return v |
|||
} |
@ -0,0 +1,97 @@ |
|||
package core |
|||
|
|||
import ( |
|||
"fmt" |
|||
"os" |
|||
"time" |
|||
|
|||
"autocode/global" |
|||
"autocode/utils" |
|||
"go.uber.org/zap" |
|||
"go.uber.org/zap/zapcore" |
|||
) |
|||
|
|||
func Zap() (logger *zap.Logger) { |
|||
if ok, _ := utils.PathExists(global.GVA_CONFIG.Zap.Director); !ok { // 判断是否有Director文件夹
|
|||
fmt.Printf("create %v directory\n", global.GVA_CONFIG.Zap.Director) |
|||
_ = os.Mkdir(global.GVA_CONFIG.Zap.Director, os.ModePerm) |
|||
} |
|||
// 调试级别
|
|||
debugPriority := zap.LevelEnablerFunc(func(lev zapcore.Level) bool { |
|||
return lev == zap.DebugLevel |
|||
}) |
|||
// 日志级别
|
|||
infoPriority := zap.LevelEnablerFunc(func(lev zapcore.Level) bool { |
|||
return lev == zap.InfoLevel |
|||
}) |
|||
// 警告级别
|
|||
warnPriority := zap.LevelEnablerFunc(func(lev zapcore.Level) bool { |
|||
return lev == zap.WarnLevel |
|||
}) |
|||
// 错误级别
|
|||
errorPriority := zap.LevelEnablerFunc(func(lev zapcore.Level) bool { |
|||
return lev >= zap.ErrorLevel |
|||
}) |
|||
|
|||
cores := [...]zapcore.Core{ |
|||
getEncoderCore(fmt.Sprintf("./%s/server_debug.log", global.GVA_CONFIG.Zap.Director), debugPriority), |
|||
getEncoderCore(fmt.Sprintf("./%s/server_info.log", global.GVA_CONFIG.Zap.Director), infoPriority), |
|||
getEncoderCore(fmt.Sprintf("./%s/server_warn.log", global.GVA_CONFIG.Zap.Director), warnPriority), |
|||
getEncoderCore(fmt.Sprintf("./%s/server_error.log", global.GVA_CONFIG.Zap.Director), errorPriority), |
|||
} |
|||
logger = zap.New(zapcore.NewTee(cores[:]...), zap.AddCaller()) |
|||
|
|||
if global.GVA_CONFIG.Zap.ShowLine { |
|||
logger = logger.WithOptions(zap.AddCaller()) |
|||
} |
|||
return logger |
|||
} |
|||
|
|||
// getEncoderConfig 获取zapcore.EncoderConfig
|
|||
func getEncoderConfig() (config zapcore.EncoderConfig) { |
|||
config = zapcore.EncoderConfig{ |
|||
MessageKey: "message", |
|||
LevelKey: "level", |
|||
TimeKey: "time", |
|||
NameKey: "logger", |
|||
CallerKey: "caller", |
|||
StacktraceKey: global.GVA_CONFIG.Zap.StacktraceKey, |
|||
LineEnding: zapcore.DefaultLineEnding, |
|||
EncodeLevel: zapcore.LowercaseLevelEncoder, |
|||
EncodeTime: CustomTimeEncoder, |
|||
EncodeDuration: zapcore.SecondsDurationEncoder, |
|||
EncodeCaller: zapcore.FullCallerEncoder, |
|||
} |
|||
switch { |
|||
case global.GVA_CONFIG.Zap.EncodeLevel == "LowercaseLevelEncoder": // 小写编码器(默认)
|
|||
config.EncodeLevel = zapcore.LowercaseLevelEncoder |
|||
case global.GVA_CONFIG.Zap.EncodeLevel == "LowercaseColorLevelEncoder": // 小写编码器带颜色
|
|||
config.EncodeLevel = zapcore.LowercaseColorLevelEncoder |
|||
case global.GVA_CONFIG.Zap.EncodeLevel == "CapitalLevelEncoder": // 大写编码器
|
|||
config.EncodeLevel = zapcore.CapitalLevelEncoder |
|||
case global.GVA_CONFIG.Zap.EncodeLevel == "CapitalColorLevelEncoder": // 大写编码器带颜色
|
|||
config.EncodeLevel = zapcore.CapitalColorLevelEncoder |
|||
default: |
|||
config.EncodeLevel = zapcore.LowercaseLevelEncoder |
|||
} |
|||
return config |
|||
} |
|||
|
|||
// getEncoder 获取zapcore.Encoder
|
|||
func getEncoder() zapcore.Encoder { |
|||
if global.GVA_CONFIG.Zap.Format == "json" { |
|||
return zapcore.NewJSONEncoder(getEncoderConfig()) |
|||
} |
|||
return zapcore.NewConsoleEncoder(getEncoderConfig()) |
|||
} |
|||
|
|||
// getEncoderCore 获取Encoder的zapcore.Core
|
|||
func getEncoderCore(fileName string, level zapcore.LevelEnabler) (core zapcore.Core) { |
|||
writer := utils.GetWriteSyncer(fileName) // 使用file-rotatelogs进行日志分割
|
|||
return zapcore.NewCore(getEncoder(), writer, level) |
|||
} |
|||
|
|||
// 自定义日志输出时间格式
|
|||
func CustomTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder) { |
|||
enc.AppendString(t.Format(global.GVA_CONFIG.Zap.Prefix + "2006/01/02 - 15:04:05.000")) |
|||
} |
@ -0,0 +1,23 @@ |
|||
package global |
|||
|
|||
import ( |
|||
"autocode/config" |
|||
"github.com/go-redis/redis" |
|||
"github.com/songzhibin97/gkit/cache/local_cache" |
|||
"github.com/songzhibin97/gkit/cache/singleflight" |
|||
"github.com/spf13/viper" |
|||
"go.uber.org/zap" |
|||
"gorm.io/gorm" |
|||
) |
|||
|
|||
var ( |
|||
GVA_DB *gorm.DB |
|||
GVA_DBList map[string]*gorm.DB |
|||
GVA_REDIS *redis.Client |
|||
GVA_CONFIG config.Server |
|||
GVA_VP *viper.Viper |
|||
//GVA_LOG *oplogging.Logger
|
|||
GVA_LOG *zap.Logger |
|||
GVA_Concurrency_Control = &singleflight.Group{} |
|||
BlackCache local_cache.Cache |
|||
) |
@ -0,0 +1,13 @@ |
|||
package global |
|||
|
|||
import ( |
|||
"gorm.io/gorm" |
|||
"time" |
|||
) |
|||
|
|||
type GVA_MODEL struct { |
|||
ID uint `gorm:"primarykey"` |
|||
CreatedAt time.Time |
|||
UpdatedAt time.Time |
|||
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"` |
|||
} |
@ -0,0 +1,103 @@ |
|||
module autocode |
|||
|
|||
go 1.17 |
|||
|
|||
require ( |
|||
github.com/aliyun/aliyun-oss-go-sdk v2.2.0+incompatible |
|||
github.com/aws/aws-sdk-go v1.42.35 |
|||
github.com/dgrijalva/jwt-go v3.2.0+incompatible |
|||
github.com/fsnotify/fsnotify v1.5.1 |
|||
github.com/fvbock/endless v0.0.0-20170109170031-447134032cb6 |
|||
github.com/gin-gonic/gin v1.7.7 |
|||
github.com/go-redis/redis v6.15.9+incompatible |
|||
github.com/gookit/color v1.3.6 |
|||
github.com/huaweicloud/huaweicloud-sdk-go-obs v3.21.12+incompatible |
|||
github.com/mojocn/base64Captcha v1.3.5 |
|||
github.com/natefinch/lumberjack v2.0.0+incompatible |
|||
github.com/pkg/errors v0.9.1 |
|||
github.com/qiniu/api.v7/v7 v7.8.2 |
|||
github.com/robfig/cron/v3 v3.0.1 |
|||
github.com/satori/go.uuid v1.2.0 |
|||
github.com/shirou/gopsutil v3.21.11+incompatible |
|||
github.com/songzhibin97/gkit v1.1.4 |
|||
github.com/spf13/viper v1.10.1 |
|||
github.com/stretchr/testify v1.7.0 |
|||
github.com/swaggo/gin-swagger v1.3.3 |
|||
github.com/tencentyun/cos-go-sdk-v5 v0.7.33 |
|||
go.uber.org/zap v1.20.0 |
|||
gorm.io/driver/mysql v1.2.3 |
|||
gorm.io/driver/postgres v1.2.3 |
|||
gorm.io/gorm v1.22.5 |
|||
) |
|||
|
|||
require ( |
|||
github.com/KyleBanks/depth v1.2.1 // indirect |
|||
github.com/PuerkitoBio/purell v1.1.1 // indirect |
|||
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect |
|||
github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f // indirect |
|||
github.com/davecgh/go-spew v1.1.1 // indirect |
|||
github.com/gin-contrib/sse v0.1.0 // indirect |
|||
github.com/go-ole/go-ole v1.2.6 // indirect |
|||
github.com/go-openapi/jsonpointer v0.19.5 // indirect |
|||
github.com/go-openapi/jsonreference v0.19.6 // indirect |
|||
github.com/go-openapi/spec v0.20.3 // indirect |
|||
github.com/go-openapi/swag v0.19.15 // indirect |
|||
github.com/go-playground/locales v0.14.0 // indirect |
|||
github.com/go-playground/universal-translator v0.18.0 // indirect |
|||
github.com/go-playground/validator/v10 v10.9.0 // indirect |
|||
github.com/go-sql-driver/mysql v1.6.0 // indirect |
|||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect |
|||
github.com/golang/protobuf v1.5.2 // indirect |
|||
github.com/google/go-querystring v1.0.0 // indirect |
|||
github.com/hashicorp/hcl v1.0.0 // indirect |
|||
github.com/jackc/chunkreader/v2 v2.0.1 // indirect |
|||
github.com/jackc/pgconn v1.10.1 // indirect |
|||
github.com/jackc/pgio v1.0.0 // indirect |
|||
github.com/jackc/pgpassfile v1.0.0 // indirect |
|||
github.com/jackc/pgproto3/v2 v2.2.0 // indirect |
|||
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b // indirect |
|||
github.com/jackc/pgtype v1.9.0 // indirect |
|||
github.com/jackc/pgx/v4 v4.14.0 // indirect |
|||
github.com/jinzhu/inflection v1.0.0 // indirect |
|||
github.com/jinzhu/now v1.1.4 // indirect |
|||
github.com/jmespath/go-jmespath v0.4.0 // indirect |
|||
github.com/josharian/intern v1.0.0 // indirect |
|||
github.com/json-iterator/go v1.1.12 // indirect |
|||
github.com/leodido/go-urn v1.2.1 // indirect |
|||
github.com/magiconair/properties v1.8.5 // indirect |
|||
github.com/mailru/easyjson v0.7.7 // indirect |
|||
github.com/mattn/go-isatty v0.0.14 // indirect |
|||
github.com/mitchellh/mapstructure v1.4.3 // indirect |
|||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect |
|||
github.com/modern-go/reflect2 v1.0.2 // indirect |
|||
github.com/mozillazg/go-httpheader v0.2.1 // indirect |
|||
github.com/onsi/ginkgo v1.16.5 // indirect |
|||
github.com/onsi/gomega v1.17.0 // indirect |
|||
github.com/pelletier/go-toml v1.9.4 // indirect |
|||
github.com/pmezard/go-difflib v1.0.0 // indirect |
|||
github.com/spf13/afero v1.6.0 // indirect |
|||
github.com/spf13/cast v1.4.1 // indirect |
|||
github.com/spf13/jwalterweatherman v1.1.0 // indirect |
|||
github.com/spf13/pflag v1.0.5 // indirect |
|||
github.com/subosito/gotenv v1.2.0 // indirect |
|||
github.com/swaggo/swag v1.7.4 // indirect |
|||
github.com/tklauser/go-sysconf v0.3.9 // indirect |
|||
github.com/tklauser/numcpus v0.3.0 // indirect |
|||
github.com/ugorji/go/codec v1.2.6 // indirect |
|||
github.com/yusufpapurcu/wmi v1.2.2 // indirect |
|||
go.uber.org/atomic v1.7.0 // indirect |
|||
go.uber.org/multierr v1.6.0 // indirect |
|||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 // indirect |
|||
golang.org/x/image v0.0.0-20210220032944-ac19c3e999fb // indirect |
|||
golang.org/x/net v0.0.0-20211216030914-fe4d6282115f // indirect |
|||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect |
|||
golang.org/x/sys v0.0.0-20211210111614-af8b64212486 // indirect |
|||
golang.org/x/text v0.3.7 // indirect |
|||
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324 // indirect |
|||
golang.org/x/tools v0.1.5 // indirect |
|||
google.golang.org/protobuf v1.27.1 // indirect |
|||
gopkg.in/ini.v1 v1.66.2 // indirect |
|||
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect |
|||
gopkg.in/yaml.v2 v2.4.0 // indirect |
|||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect |
|||
) |
@ -0,0 +1,31 @@ |
|||
package initialize |
|||
|
|||
import ( |
|||
"autocode/global" |
|||
"gorm.io/gorm" |
|||
) |
|||
|
|||
const sys = "system" |
|||
|
|||
func DBList() { |
|||
dbMap := make(map[string]*gorm.DB) |
|||
for _, info := range global.GVA_CONFIG.DBList { |
|||
if info.Disable { |
|||
continue |
|||
} |
|||
switch info.Type { |
|||
case "mysql": |
|||
dbMap[info.Dbname] = GormMysqlByConfig(info) |
|||
case "pgsql": |
|||
dbMap[info.Dbname] = GormPgSqlByConfig(info) |
|||
default: |
|||
continue |
|||
} |
|||
} |
|||
// 做特殊判断,是否有迁移
|
|||
// 适配低版本迁移多数据库版本
|
|||
if sysDB, ok := dbMap[sys]; ok { |
|||
global.GVA_DB = sysDB |
|||
} |
|||
global.GVA_DBList = dbMap |
|||
} |
@ -0,0 +1,40 @@ |
|||
package initialize |
|||
|
|||
import ( |
|||
"os" |
|||
|
|||
"autocode/global" |
|||
"autocode/model/autocode" |
|||
"go.uber.org/zap" |
|||
"gorm.io/gorm" |
|||
) |
|||
|
|||
// Gorm 初始化数据库并产生数据库全局变量
|
|||
// Author SliverHorn
|
|||
func Gorm() *gorm.DB { |
|||
switch global.GVA_CONFIG.System.DbType { |
|||
case "mysql": |
|||
return GormMysql() |
|||
case "pgsql": |
|||
return GormPgSql() |
|||
default: |
|||
return GormMysql() |
|||
} |
|||
} |
|||
|
|||
// RegisterTables 注册数据库表专用
|
|||
// Author SliverHorn
|
|||
func RegisterTables(db *gorm.DB) { |
|||
err := db.AutoMigrate( |
|||
|
|||
// 自动化模块表
|
|||
// Code generated by github.com/flipped-aurora/yibu/server Begin; DO NOT EDIT.
|
|||
autocode.AutoCodeExample{}, |
|||
// Code generated by github.com/flipped-aurora/yibu/server End; DO NOT EDIT.
|
|||
) |
|||
if err != nil { |
|||
global.GVA_LOG.Error("register table failed", zap.Error(err)) |
|||
os.Exit(0) |
|||
} |
|||
global.GVA_LOG.Info("register table success") |
|||
} |
@ -0,0 +1,52 @@ |
|||
package initialize |
|||
|
|||
import ( |
|||
"autocode/config" |
|||
"autocode/global" |
|||
"autocode/initialize/internal" |
|||
"gorm.io/driver/mysql" |
|||
"gorm.io/gorm" |
|||
) |
|||
|
|||
// GormMysql 初始化Mysql数据库
|
|||
// Author [piexlmax](https://github.com/piexlmax)
|
|||
// Author [SliverHorn](https://github.com/SliverHorn)
|
|||
func GormMysql() *gorm.DB { |
|||
m := global.GVA_CONFIG.Mysql |
|||
if m.Dbname == "" { |
|||
return nil |
|||
} |
|||
mysqlConfig := mysql.Config{ |
|||
DSN: m.Dsn(), // DSN data source name
|
|||
DefaultStringSize: 191, // string 类型字段的默认长度
|
|||
SkipInitializeWithVersion: false, // 根据版本自动配置
|
|||
} |
|||
if db, err := gorm.Open(mysql.New(mysqlConfig), internal.Gorm.Config()); err != nil { |
|||
return nil |
|||
} else { |
|||
sqlDB, _ := db.DB() |
|||
sqlDB.SetMaxIdleConns(m.MaxIdleConns) |
|||
sqlDB.SetMaxOpenConns(m.MaxOpenConns) |
|||
return db |
|||
} |
|||
} |
|||
|
|||
// GormMysqlByConfig 初始化Mysql数据库用过传入配置
|
|||
func GormMysqlByConfig(m config.DB) *gorm.DB { |
|||
if m.Dbname == "" { |
|||
return nil |
|||
} |
|||
mysqlConfig := mysql.Config{ |
|||
DSN: m.Dsn(), // DSN data source name
|
|||
DefaultStringSize: 191, // string 类型字段的默认长度
|
|||
SkipInitializeWithVersion: false, // 根据版本自动配置
|
|||
} |
|||
if db, err := gorm.Open(mysql.New(mysqlConfig), internal.Gorm.Config()); err != nil { |
|||
panic(err) |
|||
} else { |
|||
sqlDB, _ := db.DB() |
|||
sqlDB.SetMaxIdleConns(m.MaxIdleConns) |
|||
sqlDB.SetMaxOpenConns(m.MaxOpenConns) |
|||
return db |
|||
} |
|||
} |
@ -0,0 +1,50 @@ |
|||
package initialize |
|||
|
|||
import ( |
|||
"autocode/config" |
|||
"autocode/global" |
|||
"autocode/initialize/internal" |
|||
"gorm.io/driver/postgres" |
|||
"gorm.io/gorm" |
|||
) |
|||
|
|||
// GormPgSql 初始化 Postgresql 数据库
|
|||
// Author [piexlmax](https://github.com/piexlmax)
|
|||
// Author [SliverHorn](https://github.com/SliverHorn)
|
|||
func GormPgSql() *gorm.DB { |
|||
p := global.GVA_CONFIG.Pgsql |
|||
if p.Dbname == "" { |
|||
return nil |
|||
} |
|||
pgsqlConfig := postgres.Config{ |
|||
DSN: p.Dsn(), // DSN data source name
|
|||
PreferSimpleProtocol: false, |
|||
} |
|||
if db, err := gorm.Open(postgres.New(pgsqlConfig), internal.Gorm.Config()); err != nil { |
|||
return nil |
|||
} else { |
|||
sqlDB, _ := db.DB() |
|||
sqlDB.SetMaxIdleConns(p.MaxIdleConns) |
|||
sqlDB.SetMaxOpenConns(p.MaxOpenConns) |
|||
return db |
|||
} |
|||
} |
|||
|
|||
// GormPgSqlByConfig 初始化 Postgresql 数据库 通过参数
|
|||
func GormPgSqlByConfig(p config.DB) *gorm.DB { |
|||
if p.Dbname == "" { |
|||
return nil |
|||
} |
|||
pgsqlConfig := postgres.Config{ |
|||
DSN: p.Dsn(), // DSN data source name
|
|||
PreferSimpleProtocol: false, |
|||
} |
|||
if db, err := gorm.Open(postgres.New(pgsqlConfig), internal.Gorm.Config()); err != nil { |
|||
panic(err) |
|||
} else { |
|||
sqlDB, _ := db.DB() |
|||
sqlDB.SetMaxIdleConns(p.MaxIdleConns) |
|||
sqlDB.SetMaxOpenConns(p.MaxOpenConns) |
|||
return db |
|||
} |
|||
} |
@ -0,0 +1,39 @@ |
|||
package internal |
|||
|
|||
import ( |
|||
"log" |
|||
"os" |
|||
"time" |
|||
|
|||
"autocode/global" |
|||
"gorm.io/gorm" |
|||
"gorm.io/gorm/logger" |
|||
) |
|||
|
|||
var Gorm = new(_gorm) |
|||
|
|||
type _gorm struct{} |
|||
|
|||
// Config gorm 自定义配置
|
|||
// Author [SliverHorn](https://github.com/SliverHorn)
|
|||
func (g *_gorm) Config() *gorm.Config { |
|||
config := &gorm.Config{DisableForeignKeyConstraintWhenMigrating: true} |
|||
_default := logger.New(NewWriter(log.New(os.Stdout, "\r\n", log.LstdFlags)), logger.Config{ |
|||
SlowThreshold: 200 * time.Millisecond, |
|||
LogLevel: logger.Warn, |
|||
Colorful: true, |
|||
}) |
|||
switch global.GVA_CONFIG.Mysql.LogMode { |
|||
case "silent", "Silent": |
|||
config.Logger = _default.LogMode(logger.Silent) |
|||
case "error", "Error": |
|||
config.Logger = _default.LogMode(logger.Error) |
|||
case "warn", "Warn": |
|||
config.Logger = _default.LogMode(logger.Warn) |
|||
case "info", "Info": |
|||
config.Logger = _default.LogMode(logger.Info) |
|||
default: |
|||
config.Logger = _default.LogMode(logger.Info) |
|||
} |
|||
return config |
|||
} |
@ -0,0 +1,35 @@ |
|||
package internal |
|||
|
|||
import ( |
|||
"fmt" |
|||
|
|||
"autocode/global" |
|||
"gorm.io/gorm/logger" |
|||
) |
|||
|
|||
type writer struct { |
|||
logger.Writer |
|||
} |
|||
|
|||
// NewWriter writer 构造函数
|
|||
// Author [SliverHorn](https://github.com/SliverHorn)
|
|||
func NewWriter(w logger.Writer) *writer { |
|||
return &writer{Writer: w} |
|||
} |
|||
|
|||
// Printf 格式化打印日志
|
|||
// Author [SliverHorn](https://github.com/SliverHorn)
|
|||
func (w *writer) Printf(message string, data ...interface{}) { |
|||
var logZap bool |
|||
switch global.GVA_CONFIG.System.DbType { |
|||
case "mysql": |
|||
logZap = global.GVA_CONFIG.Mysql.LogZap |
|||
case "pgsql": |
|||
logZap = global.GVA_CONFIG.Pgsql.LogZap |
|||
} |
|||
if logZap { |
|||
global.GVA_LOG.Info(fmt.Sprintf(message+"\n", data...)) |
|||
} else { |
|||
w.Writer.Printf(message, data...) |
|||
} |
|||
} |
@ -0,0 +1,23 @@ |
|||
package initialize |
|||
|
|||
import ( |
|||
"autocode/global" |
|||
"github.com/go-redis/redis" |
|||
"go.uber.org/zap" |
|||
) |
|||
|
|||
func Redis() { |
|||
redisCfg := global.GVA_CONFIG.Redis |
|||
client := redis.NewClient(&redis.Options{ |
|||
Addr: redisCfg.Addr, |
|||
Password: redisCfg.Password, // no password set
|
|||
DB: redisCfg.DB, // use default DB
|
|||
}) |
|||
pong, err := client.Ping().Result() |
|||
if err != nil { |
|||
global.GVA_LOG.Error("redis connect ping failed, err:", zap.Any("err", err)) |
|||
} else { |
|||
global.GVA_LOG.Info("redis connect ping response:", zap.String("pong", pong)) |
|||
global.GVA_REDIS = client |
|||
} |
|||
} |
@ -0,0 +1,60 @@ |
|||
package initialize |
|||
|
|||
import ( |
|||
"net/http" |
|||
|
|||
"autocode/global" |
|||
"autocode/router" |
|||
"github.com/gin-gonic/gin" |
|||
"github.com/swaggo/gin-swagger" |
|||
"github.com/swaggo/gin-swagger/swaggerFiles" |
|||
) |
|||
|
|||
// 初始化总路由
|
|||
|
|||
func Routers() *gin.Engine { |
|||
Router := gin.Default() |
|||
|
|||
// 如果想要不使用nginx代理前端网页,可以修改 web/.env.production 下的
|
|||
// VUE_APP_BASE_API = /
|
|||
// VUE_APP_BASE_PATH = http://localhost
|
|||
// 然后执行打包命令 npm run build。在打开下面4行注释
|
|||
// Router.LoadHTMLGlob("./dist/*.html") // npm打包成dist的路径
|
|||
// Router.Static("/favicon.ico", "./dist/favicon.ico")
|
|||
// Router.Static("/static", "./dist/assets") // dist里面的静态资源
|
|||
// Router.StaticFile("/", "./dist/index.html") // 前端网页入口页面
|
|||
|
|||
Router.StaticFS(global.GVA_CONFIG.Local.Path, http.Dir(global.GVA_CONFIG.Local.Path)) // 为用户头像和文件提供静态地址
|
|||
// Router.Use(middleware.LoadTls()) // 打开就能玩https了
|
|||
global.GVA_LOG.Info("use middleware logger") |
|||
// 跨域,如需跨域可以打开下面的注释
|
|||
// Router.Use(middleware.Cors()) // 直接放行全部跨域请求
|
|||
//Router.Use(middleware.CorsByRules()) // 按照配置的规则放行跨域请求
|
|||
global.GVA_LOG.Info("use middleware cors") |
|||
Router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler)) |
|||
global.GVA_LOG.Info("register swagger handler") |
|||
// 方便统一添加路由组前缀 多服务器上线使用
|
|||
|
|||
// 获取路由组实例
|
|||
autocodeRouter := router.RouterGroupApp.Autocode |
|||
PublicGroup := Router.Group("") |
|||
{ |
|||
// 健康监测
|
|||
PublicGroup.GET("/health", func(c *gin.Context) { |
|||
c.JSON(200, "ok") |
|||
}) |
|||
} |
|||
{ |
|||
} |
|||
PrivateGroup := Router.Group("") |
|||
PrivateGroup.Use() |
|||
{ |
|||
|
|||
// Code generated by github.com/flipped-aurora/yibu/server Begin; DO NOT EDIT.
|
|||
autocodeRouter.InitSysAutoCodeExampleRouter(PrivateGroup) |
|||
// Code generated by github.com/flipped-aurora/yibu/server End; DO NOT EDIT.
|
|||
} |
|||
|
|||
global.GVA_LOG.Info("router register success") |
|||
return Router |
|||
} |
@ -0,0 +1,2 @@ |
|||
[tcp_server/zinx/examples/zinx_server]2022/01/15 - 19:33:52.717 [34minfo[0m C:/Users/Administrator/go/src/autocode/initialize/redis.go:20 redis connect ping response: {"pong": "PONG"} |
|||
[tcp_server/zinx/examples/zinx_server]2022/01/15 - 20:11:04.657 [34minfo[0m C:/Users/Administrator/go/src/autocode/initialize/redis.go:20 redis connect ping response: {"pong": "PONG"} |
@ -0,0 +1,3 @@ |
|||
[github.com/flipped-aurora/yibu/server]2022/01/15 - 20:31:51.422 [31merror[0m C:/Users/Administrator/go/src/autocode/core/server.go:44 listen tcp :8888: bind: Only one usage of each socket address (protocol/network address/port) is normally permitted. |
|||
[github.com/flipped-aurora/yibu/server]2022/01/15 - 21:12:24.656 [31merror[0m C:/Users/Administrator/go/src/mygencode/autocode/core/server.go:33 listen tcp :8888: bind: Only one usage of each socket address (protocol/network address/port) is normally permitted. |
|||
[github.com/flipped-aurora/yibu/server]2022/01/15 - 21:16:58.013 [31merror[0m C:/Users/Administrator/go/src/awesomeProject5/autocode/core/server.go:33 listen tcp :8888: bind: Only one usage of each socket address (protocol/network address/port) is normally permitted. |
@ -0,0 +1,36 @@ |
|||
[github.com/flipped-aurora/yibu/server]2022/01/15 - 20:29:20.059 [34minfo[0m C:/Users/Administrator/go/src/autocode/initialize/redis.go:20 redis connect ping response: {"pong": "PONG"} |
|||
[github.com/flipped-aurora/yibu/server]2022/01/15 - 20:31:51.405 [34minfo[0m C:/Users/Administrator/go/src/autocode/initialize/router.go:29 use middleware logger |
|||
[github.com/flipped-aurora/yibu/server]2022/01/15 - 20:31:51.407 [34minfo[0m C:/Users/Administrator/go/src/autocode/initialize/router.go:33 use middleware cors |
|||
[github.com/flipped-aurora/yibu/server]2022/01/15 - 20:31:51.407 [34minfo[0m C:/Users/Administrator/go/src/autocode/initialize/router.go:35 register swagger handler |
|||
[github.com/flipped-aurora/yibu/server]2022/01/15 - 20:31:51.407 [34minfo[0m C:/Users/Administrator/go/src/autocode/initialize/router.go:59 router register success |
|||
[github.com/flipped-aurora/yibu/server]2022/01/15 - 20:31:51.418 [34minfo[0m C:/Users/Administrator/go/src/autocode/core/server.go:33 server run success on {"address": ":8888"} |
|||
[github.com/flipped-aurora/yibu/server]2022/01/15 - 20:32:40.806 [34minfo[0m C:/Users/Administrator/go/src/autocode/initialize/router.go:29 use middleware logger |
|||
[github.com/flipped-aurora/yibu/server]2022/01/15 - 20:32:40.806 [34minfo[0m C:/Users/Administrator/go/src/autocode/initialize/router.go:33 use middleware cors |
|||
[github.com/flipped-aurora/yibu/server]2022/01/15 - 20:32:40.807 [34minfo[0m C:/Users/Administrator/go/src/autocode/initialize/router.go:35 register swagger handler |
|||
[github.com/flipped-aurora/yibu/server]2022/01/15 - 20:32:40.807 [34minfo[0m C:/Users/Administrator/go/src/autocode/initialize/router.go:59 router register success |
|||
[github.com/flipped-aurora/yibu/server]2022/01/15 - 20:32:40.815 [34minfo[0m C:/Users/Administrator/go/src/autocode/core/server.go:33 server run success on {"address": ":8888"} |
|||
[github.com/flipped-aurora/yibu/server]2022/01/15 - 20:34:37.870 [34minfo[0m C:/Users/Administrator/go/src/autocode/initialize/router.go:29 use middleware logger |
|||
[github.com/flipped-aurora/yibu/server]2022/01/15 - 20:34:37.871 [34minfo[0m C:/Users/Administrator/go/src/autocode/initialize/router.go:33 use middleware cors |
|||
[github.com/flipped-aurora/yibu/server]2022/01/15 - 20:34:37.871 [34minfo[0m C:/Users/Administrator/go/src/autocode/initialize/router.go:35 register swagger handler |
|||
[github.com/flipped-aurora/yibu/server]2022/01/15 - 20:34:37.871 [34minfo[0m C:/Users/Administrator/go/src/autocode/initialize/router.go:59 router register success |
|||
[github.com/flipped-aurora/yibu/server]2022/01/15 - 20:34:37.876 [34minfo[0m C:/Users/Administrator/go/src/autocode/core/server.go:33 server run success on {"address": ":8888"} |
|||
[github.com/flipped-aurora/yibu/server]2022/01/15 - 20:42:26.949 [34minfo[0m C:/Users/Administrator/go/src/autocode/initialize/router.go:29 use middleware logger |
|||
[github.com/flipped-aurora/yibu/server]2022/01/15 - 20:42:26.950 [34minfo[0m C:/Users/Administrator/go/src/autocode/initialize/router.go:33 use middleware cors |
|||
[github.com/flipped-aurora/yibu/server]2022/01/15 - 20:42:26.950 [34minfo[0m C:/Users/Administrator/go/src/autocode/initialize/router.go:35 register swagger handler |
|||
[github.com/flipped-aurora/yibu/server]2022/01/15 - 20:42:26.951 [34minfo[0m C:/Users/Administrator/go/src/autocode/initialize/router.go:59 router register success |
|||
[github.com/flipped-aurora/yibu/server]2022/01/15 - 20:42:26.953 [34minfo[0m C:/Users/Administrator/go/src/autocode/core/server.go:33 server run success on {"address": ":8888"} |
|||
[github.com/flipped-aurora/yibu/server]2022/01/15 - 21:03:14.700 [34minfo[0m C:/Users/Administrator/go/src/gin-vue/autocode/initialize/router.go:29 use middleware logger |
|||
[github.com/flipped-aurora/yibu/server]2022/01/15 - 21:03:14.701 [34minfo[0m C:/Users/Administrator/go/src/gin-vue/autocode/initialize/router.go:33 use middleware cors |
|||
[github.com/flipped-aurora/yibu/server]2022/01/15 - 21:03:14.702 [34minfo[0m C:/Users/Administrator/go/src/gin-vue/autocode/initialize/router.go:35 register swagger handler |
|||
[github.com/flipped-aurora/yibu/server]2022/01/15 - 21:03:14.702 [34minfo[0m C:/Users/Administrator/go/src/gin-vue/autocode/initialize/router.go:58 router register success |
|||
[github.com/flipped-aurora/yibu/server]2022/01/15 - 21:03:14.703 [34minfo[0m C:/Users/Administrator/go/src/gin-vue/autocode/core/server.go:31 server run success on {"address": ":8888"} |
|||
[github.com/flipped-aurora/yibu/server]2022/01/15 - 21:12:24.648 [34minfo[0m C:/Users/Administrator/go/src/mygencode/autocode/initialize/router.go:29 use middleware logger |
|||
[github.com/flipped-aurora/yibu/server]2022/01/15 - 21:12:24.648 [34minfo[0m C:/Users/Administrator/go/src/mygencode/autocode/initialize/router.go:33 use middleware cors |
|||
[github.com/flipped-aurora/yibu/server]2022/01/15 - 21:12:24.648 [34minfo[0m C:/Users/Administrator/go/src/mygencode/autocode/initialize/router.go:35 register swagger handler |
|||
[github.com/flipped-aurora/yibu/server]2022/01/15 - 21:12:24.649 [34minfo[0m C:/Users/Administrator/go/src/mygencode/autocode/initialize/router.go:58 router register success |
|||
[github.com/flipped-aurora/yibu/server]2022/01/15 - 21:12:24.654 [34minfo[0m C:/Users/Administrator/go/src/mygencode/autocode/core/server.go:31 server run success on {"address": ":8888"} |
|||
[github.com/flipped-aurora/yibu/server]2022/01/15 - 21:16:58.009 [34minfo[0m C:/Users/Administrator/go/src/awesomeProject5/autocode/initialize/router.go:29 use middleware logger |
|||
[github.com/flipped-aurora/yibu/server]2022/01/15 - 21:16:58.010 [34minfo[0m C:/Users/Administrator/go/src/awesomeProject5/autocode/initialize/router.go:33 use middleware cors |
|||
[github.com/flipped-aurora/yibu/server]2022/01/15 - 21:16:58.010 [34minfo[0m C:/Users/Administrator/go/src/awesomeProject5/autocode/initialize/router.go:35 register swagger handler |
|||
[github.com/flipped-aurora/yibu/server]2022/01/15 - 21:16:58.010 [34minfo[0m C:/Users/Administrator/go/src/awesomeProject5/autocode/initialize/router.go:58 router register success |
|||
[github.com/flipped-aurora/yibu/server]2022/01/15 - 21:16:58.012 [34minfo[0m C:/Users/Administrator/go/src/awesomeProject5/autocode/core/server.go:31 server run success on {"address": ":8888"} |
@ -0,0 +1,22 @@ |
|||
package main |
|||
|
|||
import ( |
|||
"autocode/core" |
|||
"autocode/global" |
|||
"autocode/initialize" |
|||
) |
|||
|
|||
func main() { |
|||
global.GVA_VP = core.Viper() // 初始化Viper
|
|||
global.GVA_LOG = core.Zap() // 初始化zap日志库
|
|||
global.GVA_DB = initialize.Gorm() // gorm连接数据库
|
|||
initialize.DBList() |
|||
if global.GVA_DB != nil { |
|||
initialize.RegisterTables(global.GVA_DB) // 初始化表
|
|||
// 程序结束前关闭数据库链接
|
|||
db, _ := global.GVA_DB.DB() |
|||
defer db.Close() |
|||
} |
|||
|
|||
core.RunWindowsServer() |
|||
} |
@ -0,0 +1,12 @@ |
|||
// 自动生成模板SysDictionaryDetail
|
|||
package autocode |
|||
|
|||
import ( |
|||
"autocode/global" |
|||
) |
|||
|
|||
// 如果含有time.Time 请自行import time包
|
|||
type AutoCodeExample struct { |
|||
global.GVA_MODEL |
|||
AutoCodeExampleField string `json:"autoCodeExampleField" form:"autoCodeExampleField" gorm:"column:auto_code_example_field;comment:仅作示例条目无实际作用"` // 展示值
|
|||
} |
@ -0,0 +1,13 @@ |
|||
// 自动生成模板SysDictionaryDetail
|
|||
package request |
|||
|
|||
import ( |
|||
"autocode/model/autocode" |
|||
"autocode/model/common/request" |
|||
) |
|||
|
|||
// 如果含有time.Time 请自行import time包
|
|||
type AutoCodeExampleSearch struct { |
|||
autocode.AutoCodeExample |
|||
request.PageInfo |
|||
} |
@ -0,0 +1,27 @@ |
|||
package request |
|||
|
|||
// PageInfo Paging common input parameter structure
|
|||
type PageInfo struct { |
|||
Page int `json:"page" form:"page"` // 页码
|
|||
PageSize int `json:"pageSize" form:"pageSize"` // 每页大小
|
|||
} |
|||
|
|||
// GetById Find by id structure
|
|||
type GetById struct { |
|||
ID float64 `json:"id" form:"id"` // 主键ID
|
|||
} |
|||
|
|||
func (r *GetById) Uint() uint { |
|||
return uint(r.ID) |
|||
} |
|||
|
|||
type IdsReq struct { |
|||
Ids []int `json:"ids" form:"ids"` |
|||
} |
|||
|
|||
// GetAuthorityId Get role by id structure
|
|||
type GetAuthorityId struct { |
|||
AuthorityId string `json:"authorityId" form:"authorityId"` // 角色ID
|
|||
} |
|||
|
|||
type Empty struct{} |
@ -0,0 +1,8 @@ |
|||
package response |
|||
|
|||
type PageResult struct { |
|||
List interface{} `json:"list"` |
|||
Total int64 `json:"total"` |
|||
Page int `json:"page"` |
|||
PageSize int `json:"pageSize"` |
|||
} |
@ -0,0 +1,55 @@ |
|||
package response |
|||
|
|||
import ( |
|||
"net/http" |
|||
|
|||
"github.com/gin-gonic/gin" |
|||
) |
|||
|
|||
type Response struct { |
|||
Code int `json:"code"` |
|||
Data interface{} `json:"data"` |
|||
Msg string `json:"msg"` |
|||
} |
|||
|
|||
const ( |
|||
ERROR = 7 |
|||
SUCCESS = 0 |
|||
) |
|||
|
|||
func Result(code int, data interface{}, msg string, c *gin.Context) { |
|||
// 开始时间
|
|||
c.JSON(http.StatusOK, Response{ |
|||
code, |
|||
data, |
|||
msg, |
|||
}) |
|||
} |
|||
|
|||
func Ok(c *gin.Context) { |
|||
Result(SUCCESS, map[string]interface{}{}, "操作成功", c) |
|||
} |
|||
|
|||
func OkWithMessage(message string, c *gin.Context) { |
|||
Result(SUCCESS, map[string]interface{}{}, message, c) |
|||
} |
|||
|
|||
func OkWithData(data interface{}, c *gin.Context) { |
|||
Result(SUCCESS, data, "操作成功", c) |
|||
} |
|||
|
|||
func OkWithDetailed(data interface{}, message string, c *gin.Context) { |
|||
Result(SUCCESS, data, message, c) |
|||
} |
|||
|
|||
func Fail(c *gin.Context) { |
|||
Result(ERROR, map[string]interface{}{}, "操作失败", c) |
|||
} |
|||
|
|||
func FailWithMessage(message string, c *gin.Context) { |
|||
Result(ERROR, map[string]interface{}{}, message, c) |
|||
} |
|||
|
|||
func FailWithDetailed(data interface{}, message string, c *gin.Context) { |
|||
Result(ERROR, data, message, c) |
|||
} |
@ -0,0 +1,24 @@ |
|||
package example |
|||
|
|||
import ( |
|||
"autocode/global" |
|||
) |
|||
|
|||
// file struct, 文件结构体
|
|||
type ExaFile struct { |
|||
global.GVA_MODEL |
|||
FileName string |
|||
FileMd5 string |
|||
FilePath string |
|||
ExaFileChunk []ExaFileChunk |
|||
ChunkTotal int |
|||
IsFinish bool |
|||
} |
|||
|
|||
// file chunk struct, 切片结构体
|
|||
type ExaFileChunk struct { |
|||
global.GVA_MODEL |
|||
ExaFileID uint |
|||
FileChunkNumber int |
|||
FileChunkPath string |
|||
} |
@ -0,0 +1,15 @@ |
|||
package example |
|||
|
|||
import ( |
|||
"autocode/global" |
|||
"autocode/model/system" |
|||
) |
|||
|
|||
type ExaCustomer struct { |
|||
global.GVA_MODEL |
|||
CustomerName string `json:"customerName" form:"customerName" gorm:"comment:客户名"` // 客户名
|
|||
CustomerPhoneData string `json:"customerPhoneData" form:"customerPhoneData" gorm:"comment:客户手机号"` // 客户手机号
|
|||
SysUserID uint `json:"sysUserId" form:"sysUserId" gorm:"comment:管理ID"` // 管理ID
|
|||
SysUserAuthorityID string `json:"sysUserAuthorityID" form:"sysUserAuthorityID" gorm:"comment:管理角色ID"` // 管理角色ID
|
|||
SysUser system.SysUser `json:"sysUser" form:"sysUser" gorm:"comment:管理详情"` // 管理详情
|
|||
} |
@ -0,0 +1,8 @@ |
|||
package example |
|||
|
|||
import "autocode/model/system" |
|||
|
|||
type ExcelInfo struct { |
|||
FileName string `json:"fileName"` // 文件名
|
|||
InfoList []system.SysBaseMenu `json:"infoList"` |
|||
} |
@ -0,0 +1,13 @@ |
|||
package example |
|||
|
|||
import ( |
|||
"autocode/global" |
|||
) |
|||
|
|||
type ExaFileUploadAndDownload struct { |
|||
global.GVA_MODEL |
|||
Name string `json:"name" gorm:"comment:文件名"` // 文件名
|
|||
Url string `json:"url" gorm:"comment:文件地址"` // 文件地址
|
|||
Tag string `json:"tag" gorm:"comment:文件标签"` // 文件标签
|
|||
Key string `json:"key" gorm:"comment:编号"` // 编号
|
|||
} |
@ -0,0 +1,11 @@ |
|||
package response |
|||
|
|||
import "autocode/model/example" |
|||
|
|||
type FilePathResponse struct { |
|||
FilePath string `json:"filePath"` |
|||
} |
|||
|
|||
type FileResponse struct { |
|||
File example.ExaFile `json:"file"` |
|||
} |
@ -0,0 +1,7 @@ |
|||
package response |
|||
|
|||
import "autocode/model/example" |
|||
|
|||
type ExaCustomerResponse struct { |
|||
Customer example.ExaCustomer `json:"customer"` |
|||
} |
@ -0,0 +1,7 @@ |
|||
package response |
|||
|
|||
import "autocode/model/example" |
|||
|
|||
type ExaFileResponse struct { |
|||
File example.ExaFileUploadAndDownload `json:"file"` |
|||
} |
@ -0,0 +1,21 @@ |
|||
package request |
|||
|
|||
import ( |
|||
"github.com/dgrijalva/jwt-go" |
|||
uuid "github.com/satori/go.uuid" |
|||
) |
|||
|
|||
// Custom claims structure
|
|||
type CustomClaims struct { |
|||
BaseClaims |
|||
BufferTime int64 |
|||
jwt.StandardClaims |
|||
} |
|||
|
|||
type BaseClaims struct { |
|||
UUID uuid.UUID |
|||
ID uint |
|||
Username string |
|||
NickName string |
|||
AuthorityId string |
|||
} |
@ -0,0 +1,14 @@ |
|||
package request |
|||
|
|||
import ( |
|||
"autocode/model/common/request" |
|||
"autocode/model/system" |
|||
) |
|||
|
|||
// api分页条件查询及排序结构体
|
|||
type SearchApiParams struct { |
|||
system.SysApi |
|||
request.PageInfo |
|||
OrderKey string `json:"orderKey"` // 排序
|
|||
Desc bool `json:"desc"` // 排序方式:升序false(默认)|降序true
|
|||
} |
@ -0,0 +1,7 @@ |
|||
package request |
|||
|
|||
import "autocode/model/common/request" |
|||
|
|||
type SysAutoHistory struct { |
|||
request.PageInfo |
|||
} |
@ -0,0 +1,26 @@ |
|||
package request |
|||
|
|||
// Casbin info structure
|
|||
type CasbinInfo struct { |
|||
Path string `json:"path"` // 路径
|
|||
Method string `json:"method"` // 方法
|
|||
} |
|||
|
|||
// Casbin structure for input parameters
|
|||
type CasbinInReceive struct { |
|||
AuthorityId string `json:"authorityId"` // 权限id
|
|||
CasbinInfos []CasbinInfo `json:"casbinInfos"` |
|||
} |
|||
|
|||
func DefaultCasbin() []CasbinInfo { |
|||
return []CasbinInfo{ |
|||
{Path: "/menu/getMenu", Method: "POST"}, |
|||
{Path: "/jwt/jsonInBlacklist", Method: "POST"}, |
|||
{Path: "/base/login", Method: "POST"}, |
|||
{Path: "/user/register", Method: "POST"}, |
|||
{Path: "/user/changePassword", Method: "POST"}, |
|||
{Path: "/user/setUserAuthority", Method: "POST"}, |
|||
{Path: "/user/setUserInfo", Method: "PUT"}, |
|||
{Path: "/user/getUserInfo", Method: "GET"}, |
|||
} |
|||
} |
@ -0,0 +1,11 @@ |
|||
package request |
|||
|
|||
import ( |
|||
"autocode/model/common/request" |
|||
"autocode/model/system" |
|||
) |
|||
|
|||
type SysDictionarySearch struct { |
|||
system.SysDictionary |
|||
request.PageInfo |
|||
} |
@ -0,0 +1,11 @@ |
|||
package request |
|||
|
|||
import ( |
|||
"autocode/model/common/request" |
|||
"autocode/model/system" |
|||
) |
|||
|
|||
type SysDictionaryDetailSearch struct { |
|||
system.SysDictionaryDetail |
|||
request.PageInfo |
|||
} |
@ -0,0 +1,66 @@ |
|||
package request |
|||
|
|||
import ( |
|||
"fmt" |
|||
|
|||
"autocode/config" |
|||
) |
|||
|
|||
type InitDB struct { |
|||
DBType string `json:"dbType"` // 数据库类型
|
|||
Host string `json:"host"` // 服务器地址
|
|||
Port string `json:"port"` // 数据库连接端口
|
|||
UserName string `json:"userName" binding:"required"` // 数据库用户名
|
|||
Password string `json:"password"` // 数据库密码
|
|||
DBName string `json:"dbName" binding:"required"` // 数据库名
|
|||
} |
|||
|
|||
// MysqlEmptyDsn msyql 空数据库 建库链接
|
|||
// Author SliverHorn
|
|||
func (i *InitDB) MysqlEmptyDsn() string { |
|||
if i.Host == "" { |
|||
i.Host = "127.0.0.1" |
|||
} |
|||
if i.Port == "" { |
|||
i.Port = "3306" |
|||
} |
|||
return fmt.Sprintf("%s:%s@tcp(%s:%s)/", i.UserName, i.Password, i.Host, i.Port) |
|||
} |
|||
|
|||
// PgsqlEmptyDsn pgsql 空数据库 建库链接
|
|||
// Author SliverHorn
|
|||
func (i *InitDB) PgsqlEmptyDsn() string { |
|||
if i.Host == "" { |
|||
i.Host = "127.0.0.1" |
|||
} |
|||
if i.Port == "" { |
|||
i.Port = "3306" |
|||
} |
|||
return "host=" + i.Host + " user=" + i.UserName + " password=" + i.Password + " port=" + i.Port + " " + "sslmode=disable TimeZone=Asia/Shanghai" |
|||
} |
|||
|
|||
// ToMysqlConfig 转换 config.Mysql
|
|||
// Author [SliverHorn](https://github.com/SliverHorn)
|
|||
func (i *InitDB) ToMysqlConfig() config.Mysql { |
|||
return config.Mysql{ |
|||
Path: i.Host, |
|||
Port: i.Port, |
|||
Dbname: i.DBName, |
|||
Username: i.UserName, |
|||
Password: i.Password, |
|||
Config: "charset=utf8mb4&parseTime=True&loc=Local", |
|||
} |
|||
} |
|||
|
|||
// ToPgsqlConfig 转换 config.Pgsql
|
|||
// Author [SliverHorn](https://github.com/SliverHorn)
|
|||
func (i *InitDB) ToPgsqlConfig() config.Pgsql { |
|||
return config.Pgsql{ |
|||
Path: i.Host, |
|||
Port: i.Port, |
|||
Dbname: i.DBName, |
|||
Username: i.UserName, |
|||
Password: i.Password, |
|||
Config: "sslmode=disable TimeZone=Asia/Shanghai", |
|||
} |
|||
} |
@ -0,0 +1,27 @@ |
|||
package request |
|||
|
|||
import ( |
|||
"autocode/global" |
|||
"autocode/model/system" |
|||
) |
|||
|
|||
// Add menu authority info structure
|
|||
type AddMenuAuthorityInfo struct { |
|||
Menus []system.SysBaseMenu `json:"menus"` |
|||
AuthorityId string `json:"authorityId"` // 角色ID
|
|||
} |
|||
|
|||
func DefaultMenu() []system.SysBaseMenu { |
|||
return []system.SysBaseMenu{{ |
|||
GVA_MODEL: global.GVA_MODEL{ID: 1}, |
|||
ParentId: "0", |
|||
Path: "dashboard", |
|||
Name: "dashboard", |
|||
Component: "view/dashboard/index.vue", |
|||
Sort: 1, |
|||
Meta: system.Meta{ |
|||
Title: "仪表盘", |
|||
Icon: "setting", |
|||
}, |
|||
}} |
|||
} |
@ -0,0 +1,11 @@ |
|||
package request |
|||
|
|||
import ( |
|||
"autocode/model/common/request" |
|||
"autocode/model/system" |
|||
) |
|||
|
|||
type SysOperationRecordSearch struct { |
|||
system.SysOperationRecord |
|||
request.PageInfo |
|||
} |
@ -0,0 +1,37 @@ |
|||
package request |
|||
|
|||
// User register structure
|
|||
type Register struct { |
|||
Username string `json:"userName"` |
|||
Password string `json:"passWord"` |
|||
NickName string `json:"nickName" gorm:"default:'QMPlusUser'"` |
|||
HeaderImg string `json:"headerImg" gorm:"default:'https://qmplusimg.henrongyi.top/gva_header.jpg'"` |
|||
AuthorityId string `json:"authorityId" gorm:"default:888"` |
|||
AuthorityIds []string `json:"authorityIds"` |
|||
} |
|||
|
|||
// User login structure
|
|||
type Login struct { |
|||
Username string `json:"username"` // 用户名
|
|||
Password string `json:"password"` // 密码
|
|||
Captcha string `json:"captcha"` // 验证码
|
|||
CaptchaId string `json:"captchaId"` // 验证码ID
|
|||
} |
|||
|
|||
// Modify password structure
|
|||
type ChangePasswordStruct struct { |
|||
Username string `json:"username"` // 用户名
|
|||
Password string `json:"password"` // 密码
|
|||
NewPassword string `json:"newPassword"` // 新密码
|
|||
} |
|||
|
|||
// Modify user's auth structure
|
|||
type SetUserAuth struct { |
|||
AuthorityId string `json:"authorityId"` // 角色ID
|
|||
} |
|||
|
|||
// Modify user's auth structure
|
|||
type SetUserAuthorities struct { |
|||
ID uint |
|||
AuthorityIds []string `json:"authorityIds"` // 角色ID
|
|||
} |
@ -0,0 +1,11 @@ |
|||
package response |
|||
|
|||
import "autocode/model/system" |
|||
|
|||
type SysAPIResponse struct { |
|||
Api system.SysApi `json:"api"` |
|||
} |
|||
|
|||
type SysAPIListResponse struct { |
|||
Apis []system.SysApi `json:"apis"` |
|||
} |
@ -0,0 +1,12 @@ |
|||
package response |
|||
|
|||
import "autocode/model/system" |
|||
|
|||
type SysAuthorityResponse struct { |
|||
Authority system.SysAuthority `json:"authority"` |
|||
} |
|||
|
|||
type SysAuthorityCopyResponse struct { |
|||
Authority system.SysAuthority `json:"authority"` |
|||
OldAuthorityId string `json:"oldAuthorityId"` // 旧角色ID
|
|||
} |
@ -0,0 +1,16 @@ |
|||
package response |
|||
|
|||
type Db struct { |
|||
Database string `json:"database" gorm:"column:database"` |
|||
} |
|||
|
|||
type Table struct { |
|||
TableName string `json:"tableName" gorm:"column:table_name"` |
|||
} |
|||
|
|||
type Column struct { |
|||
DataType string `json:"dataType" gorm:"column:data_type"` |
|||
ColumnName string `json:"columnName" gorm:"column:column_name"` |
|||
DataTypeLong string `json:"dataTypeLong" gorm:"column:data_type_long"` |
|||
ColumnComment string `json:"columnComment" gorm:"column:column_comment"` |
|||
} |
@ -0,0 +1,13 @@ |
|||
package response |
|||
|
|||
import "time" |
|||
|
|||
type AutoCodeHistory struct { |
|||
ID uint `json:"ID" gorm:"column:id"` |
|||
CreatedAt time.Time `json:"CreatedAt" gorm:"column:created_at"` |
|||
UpdatedAt time.Time `json:"UpdatedAt" gorm:"column:updated_at"` |
|||
TableName string `json:"tableName" gorm:"column:table_name"` |
|||
StructName string `json:"structName" gorm:"column:struct_name"` |
|||
StructCNName string `json:"structCNName" gorm:"column:struct_cn_name"` |
|||
Flag int `json:"flag" gorm:"column:flag"` |
|||
} |
@ -0,0 +1,9 @@ |
|||
package response |
|||
|
|||
import ( |
|||
"autocode/model/system/request" |
|||
) |
|||
|
|||
type PolicyPathResponse struct { |
|||
Paths []request.CasbinInfo `json:"paths"` |
|||
} |
@ -0,0 +1,15 @@ |
|||
package response |
|||
|
|||
import "autocode/model/system" |
|||
|
|||
type SysMenusResponse struct { |
|||
Menus []system.SysMenu `json:"menus"` |
|||
} |
|||
|
|||
type SysBaseMenusResponse struct { |
|||
Menus []system.SysBaseMenu `json:"menus"` |
|||
} |
|||
|
|||
type SysBaseMenuResponse struct { |
|||
Menu system.SysBaseMenu `json:"menu"` |
|||
} |
@ -0,0 +1,7 @@ |
|||
package response |
|||
|
|||
import "autocode/config" |
|||
|
|||
type SysConfigResponse struct { |
|||
Config config.Server `json:"config"` |
|||
} |
@ -0,0 +1,15 @@ |
|||
package response |
|||
|
|||
import ( |
|||
"autocode/model/system" |
|||
) |
|||
|
|||
type SysUserResponse struct { |
|||
User system.SysUser `json:"user"` |
|||
} |
|||
|
|||
type LoginResponse struct { |
|||
User system.SysUser `json:"user"` |
|||
Token string `json:"token"` |
|||
ExpiresAt int64 `json:"expiresAt"` |
|||
} |
@ -0,0 +1,13 @@ |
|||
package system |
|||
|
|||
import ( |
|||
"autocode/global" |
|||
) |
|||
|
|||
type SysApi struct { |
|||
global.GVA_MODEL |
|||
Path string `json:"path" gorm:"comment:api路径"` // api路径
|
|||
Description string `json:"description" gorm:"comment:api中文描述"` // api中文描述
|
|||
ApiGroup string `json:"apiGroup" gorm:"comment:api组"` // api组
|
|||
Method string `json:"method" gorm:"default:POST;comment:方法"` // 方法:创建POST(默认)|查看GET|更新PUT|删除DELETE
|
|||
} |
@ -0,0 +1,18 @@ |
|||
package system |
|||
|
|||
import ( |
|||
"time" |
|||
) |
|||
|
|||
type SysAuthority struct { |
|||
CreatedAt time.Time // 创建时间
|
|||
UpdatedAt time.Time // 更新时间
|
|||
DeletedAt *time.Time `sql:"index"` |
|||
AuthorityId string `json:"authorityId" gorm:"not null;unique;primary_key;comment:角色ID;size:90"` // 角色ID
|
|||
AuthorityName string `json:"authorityName" gorm:"comment:角色名"` // 角色名
|
|||
ParentId string `json:"parentId" gorm:"comment:父角色ID"` // 父角色ID
|
|||
DataAuthorityId []SysAuthority `json:"dataAuthorityId" gorm:"many2many:sys_data_authority_id"` |
|||
Children []SysAuthority `json:"children" gorm:"-"` |
|||
SysBaseMenus []SysBaseMenu `json:"menus" gorm:"many2many:sys_authority_menus;"` |
|||
DefaultRouter string `json:"defaultRouter" gorm:"comment:默认菜单;default:dashboard"` // 默认菜单(默认dashboard)
|
|||
} |
@ -0,0 +1,13 @@ |
|||
package system |
|||
|
|||
type SysMenu struct { |
|||
SysBaseMenu |
|||
MenuId string `json:"menuId" gorm:"comment:菜单ID"` |
|||
AuthorityId string `json:"-" gorm:"comment:角色ID"` |
|||
Children []SysMenu `json:"children" gorm:"-"` |
|||
Parameters []SysBaseMenuParameter `json:"parameters" gorm:"foreignKey:SysBaseMenuID;references:MenuId"` |
|||
} |
|||
|
|||
func (s SysMenu) TableName() string { |
|||
return "authority_menu" |
|||
} |
@ -0,0 +1,31 @@ |
|||
package system |
|||
|
|||
import "errors" |
|||
|
|||
// AutoCodeStruct 初始版本自动化代码工具
|
|||
type AutoCodeStruct struct { |
|||
StructName string `json:"structName"` // Struct名称
|
|||
TableName string `json:"tableName"` // 表名
|
|||
PackageName string `json:"packageName"` // 文件名称
|
|||
HumpPackageName string `json:"humpPackageName"` // go文件名称
|
|||
Abbreviation string `json:"abbreviation"` // Struct简称
|
|||
Description string `json:"description"` // Struct中文名称
|
|||
AutoCreateApiToSql bool `json:"autoCreateApiToSql"` // 是否自动创建api
|
|||
AutoMoveFile bool `json:"autoMoveFile"` // 是否自动移动文件
|
|||
Fields []*Field `json:"fields"` |
|||
DictTypes []string `json:"-"` |
|||
} |
|||
|
|||
type Field struct { |
|||
FieldName string `json:"fieldName"` // Field名
|
|||
FieldDesc string `json:"fieldDesc"` // 中文名
|
|||
FieldType string `json:"fieldType"` // Field数据类型
|
|||
FieldJson string `json:"fieldJson"` // FieldJson
|
|||
DataTypeLong string `json:"dataTypeLong"` // 数据库字段长度
|
|||
Comment string `json:"comment"` // 数据库字段描述
|
|||
ColumnName string `json:"columnName"` // 数据库字段
|
|||
FieldSearchType string `json:"fieldSearchType"` // 搜索条件
|
|||
DictType string `json:"dictType"` // 字典
|
|||
} |
|||
|
|||
var AutoMoveErr error = errors.New("创建代码成功并移动文件成功") |
@ -0,0 +1,38 @@ |
|||
package system |
|||
|
|||
import ( |
|||
"strconv" |
|||
"strings" |
|||
|
|||
"autocode/global" |
|||
"autocode/model/common/request" |
|||
) |
|||
|
|||
// SysAutoCodeHistory 自动迁移代码记录,用于回滚,重放使用
|
|||
type SysAutoCodeHistory struct { |
|||
global.GVA_MODEL |
|||
TableName string `json:"tableName"` |
|||
RequestMeta string `gorm:"type:text" json:"requestMeta,omitempty"` // 前端传入的结构化信息
|
|||
AutoCodePath string `gorm:"type:text" json:"autoCodePath,omitempty"` // 其他meta信息 path;path
|
|||
InjectionMeta string `gorm:"type:text" json:"injectionMeta,omitempty"` // 注入的内容 RouterPath@functionName@RouterString;
|
|||
StructName string `json:"structName"` |
|||
StructCNName string `json:"structCNName"` |
|||
ApiIDs string `json:"apiIDs,omitempty"` // api表注册内容
|
|||
Flag int `json:"flag"` // 表示对应状态 0 代表创建, 1 代表回滚 ...
|
|||
} |
|||
|
|||
// ToRequestIds ApiIDs 转换 request.IdsReq
|
|||
// Author [SliverHorn](https://github.com/SliverHorn)
|
|||
func (m *SysAutoCodeHistory) ToRequestIds() request.IdsReq { |
|||
if m.ApiIDs == "" { |
|||
return request.IdsReq{} |
|||
} |
|||
slice := strings.Split(m.ApiIDs, ";") |
|||
ids := make([]int, 0, len(slice)) |
|||
length := len(slice) |
|||
for i := 0; i < length; i++ { |
|||
id, _ := strconv.ParseInt(slice[i], 10, 32) |
|||
ids = append(ids, int(id)) |
|||
} |
|||
return request.IdsReq{Ids: ids} |
|||
} |
@ -0,0 +1,36 @@ |
|||
package system |
|||
|
|||
import ( |
|||
"autocode/global" |
|||
) |
|||
|
|||
type SysBaseMenu struct { |
|||
global.GVA_MODEL |
|||
MenuLevel uint `json:"-"` |
|||
ParentId string `json:"parentId" gorm:"comment:父菜单ID"` // 父菜单ID
|
|||
Path string `json:"path" gorm:"comment:路由path"` // 路由path
|
|||
Name string `json:"name" gorm:"comment:路由name"` // 路由name
|
|||
Hidden bool `json:"hidden" gorm:"comment:是否在列表隐藏"` // 是否在列表隐藏
|
|||
Component string `json:"component" gorm:"comment:对应前端文件路径"` // 对应前端文件路径
|
|||
Sort int `json:"sort" gorm:"comment:排序标记"` // 排序标记
|
|||
Meta `json:"meta" gorm:"comment:附加属性"` // 附加属性
|
|||
SysAuthoritys []SysAuthority `json:"authoritys" gorm:"many2many:sys_authority_menus;"` |
|||
Children []SysBaseMenu `json:"children" gorm:"-"` |
|||
Parameters []SysBaseMenuParameter `json:"parameters"` |
|||
} |
|||
|
|||
type Meta struct { |
|||
KeepAlive bool `json:"keepAlive" gorm:"comment:是否缓存"` // 是否缓存
|
|||
DefaultMenu bool `json:"defaultMenu" gorm:"comment:是否是基础路由(开发中)"` // 是否是基础路由(开发中)
|
|||
Title string `json:"title" gorm:"comment:菜单名"` // 菜单名
|
|||
Icon string `json:"icon" gorm:"comment:菜单图标"` // 菜单图标
|
|||
CloseTab bool `json:"closeTab" gorm:"comment:自动关闭tab"` // 自动关闭tab
|
|||
} |
|||
|
|||
type SysBaseMenuParameter struct { |
|||
global.GVA_MODEL |
|||
SysBaseMenuID uint |
|||
Type string `json:"type" gorm:"comment:地址栏携带参数为params还是query"` // 地址栏携带参数为params还是query
|
|||
Key string `json:"key" gorm:"comment:地址栏携带参数的key"` // 地址栏携带参数的key
|
|||
Value string `json:"value" gorm:"comment:地址栏携带参数的值"` // 地址栏携带参数的值
|
|||
} |
@ -0,0 +1,8 @@ |
|||
package system |
|||
|
|||
type CasbinModel struct { |
|||
Ptype string `json:"ptype" gorm:"column:ptype"` |
|||
AuthorityId string `json:"rolename" gorm:"column:v0"` |
|||
Path string `json:"path" gorm:"column:v1"` |
|||
Method string `json:"method" gorm:"column:v2"` |
|||
} |
@ -0,0 +1,16 @@ |
|||
// 自动生成模板SysDictionary
|
|||
package system |
|||
|
|||
import ( |
|||
"autocode/global" |
|||
) |
|||
|
|||
// 如果含有time.Time 请自行import time包
|
|||
type SysDictionary struct { |
|||
global.GVA_MODEL |
|||
Name string `json:"name" form:"name" gorm:"column:name;comment:字典名(中)"` // 字典名(中)
|
|||
Type string `json:"type" form:"type" gorm:"column:type;comment:字典名(英)"` // 字典名(英)
|
|||
Status *bool `json:"status" form:"status" gorm:"column:status;comment:状态"` // 状态
|
|||
Desc string `json:"desc" form:"desc" gorm:"column:desc;comment:描述"` // 描述
|
|||
SysDictionaryDetails []SysDictionaryDetail `json:"sysDictionaryDetails" form:"sysDictionaryDetails"` |
|||
} |
@ -0,0 +1,16 @@ |
|||
// 自动生成模板SysDictionaryDetail
|
|||
package system |
|||
|
|||
import ( |
|||
"autocode/global" |
|||
) |
|||
|
|||
// 如果含有time.Time 请自行import time包
|
|||
type SysDictionaryDetail struct { |
|||
global.GVA_MODEL |
|||
Label string `json:"label" form:"label" gorm:"column:label;comment:展示值"` // 展示值
|
|||
Value int `json:"value" form:"value" gorm:"column:value;comment:字典值"` // 字典值
|
|||
Status *bool `json:"status" form:"status" gorm:"column:status;comment:启用状态"` // 启用状态
|
|||
Sort int `json:"sort" form:"sort" gorm:"column:sort;comment:排序标记"` // 排序标记
|
|||
SysDictionaryID int `json:"sysDictionaryID" form:"sysDictionaryID" gorm:"column:sys_dictionary_id;comment:关联标记"` // 关联标记
|
|||
} |
@ -0,0 +1,79 @@ |
|||
package system |
|||
|
|||
import "github.com/gookit/color" |
|||
|
|||
type InitDBFunc interface { |
|||
Init() (err error) |
|||
} |
|||
|
|||
const ( |
|||
Mysql = "mysql" |
|||
Pgsql = "pgsql" |
|||
InitSuccess = "\n[%v] --> 初始数据成功!\n" |
|||
AuthorityMenu = "\n[%v] --> %v 视图已存在!\n" |
|||
InitDataExist = "\n[%v] --> %v 表的初始数据已存在!\n" |
|||
InitDataFailed = "\n[%v] --> %v 表初始数据失败! \nerr: %+v\n" |
|||
InitDataSuccess = "\n[%v] --> %v 表初始数据成功!\n" |
|||
) |
|||
|
|||
type InitData interface { |
|||
TableName() string |
|||
Initialize() error |
|||
CheckDataExist() bool |
|||
} |
|||
|
|||
// MysqlDataInitialize Mysql 初始化接口使用封装
|
|||
// Author [SliverHorn](https://github.com/SliverHorn)
|
|||
func MysqlDataInitialize(inits ...InitData) error { |
|||
var entity SysMenu |
|||
for i := 0; i < len(inits); i++ { |
|||
if inits[i].TableName() == entity.TableName() { |
|||
if k := inits[i].CheckDataExist(); k { |
|||
color.Info.Printf(AuthorityMenu, Mysql, inits[i].TableName()) |
|||
continue |
|||
} |
|||
} else { |
|||
if inits[i].CheckDataExist() { |
|||
color.Info.Printf(InitDataExist, Mysql, inits[i].TableName()) |
|||
continue |
|||
} |
|||
} |
|||
|
|||
if err := inits[i].Initialize(); err != nil { |
|||
color.Info.Printf(InitDataFailed, Mysql, err) |
|||
return err |
|||
} else { |
|||
color.Info.Printf(InitDataSuccess, Mysql, inits[i].TableName()) |
|||
} |
|||
} |
|||
color.Info.Printf(InitSuccess, Mysql) |
|||
return nil |
|||
} |
|||
|
|||
// PgsqlDataInitialize Pgsql 初始化接口使用封装
|
|||
// Author [SliverHorn](https://github.com/SliverHorn)
|
|||
func PgsqlDataInitialize(inits ...InitData) error { |
|||
var entity SysMenu |
|||
for i := 0; i < len(inits); i++ { |
|||
if inits[i].TableName() == entity.TableName() { |
|||
if k := inits[i].CheckDataExist(); k { |
|||
color.Info.Printf(AuthorityMenu, Pgsql, inits[i].TableName()) |
|||
continue |
|||
} |
|||
} else { |
|||
if inits[i].CheckDataExist() { |
|||
color.Info.Printf(InitDataExist, Pgsql, inits[i].TableName()) |
|||
continue |
|||
} |
|||
} |
|||
|
|||
if err := inits[i].Initialize(); err != nil { |
|||
color.Info.Printf(InitDataFailed, Pgsql, err) |
|||
continue |
|||
} else { |
|||
color.Info.Printf(InitDataSuccess, Pgsql, inits[i].TableName()) |
|||
} |
|||
} |
|||
color.Info.Printf(InitSuccess, Pgsql) |
|||
return nil |
|||
} |
@ -0,0 +1,10 @@ |
|||
package system |
|||
|
|||
import ( |
|||
"autocode/global" |
|||
) |
|||
|
|||
type JwtBlacklist struct { |
|||
global.GVA_MODEL |
|||
Jwt string `gorm:"type:text;comment:jwt"` |
|||
} |
@ -0,0 +1,24 @@ |
|||
// 自动生成模板SysOperationRecord
|
|||
package system |
|||
|
|||
import ( |
|||
"time" |
|||
|
|||
"autocode/global" |
|||
) |
|||
|
|||
// 如果含有time.Time 请自行import time包
|
|||
type SysOperationRecord struct { |
|||
global.GVA_MODEL |
|||
Ip string `json:"ip" form:"ip" gorm:"column:ip;comment:请求ip"` // 请求ip
|
|||
Method string `json:"method" form:"method" gorm:"column:method;comment:请求方法"` // 请求方法
|
|||
Path string `json:"path" form:"path" gorm:"column:path;comment:请求路径"` // 请求路径
|
|||
Status int `json:"status" form:"status" gorm:"column:status;comment:请求状态"` // 请求状态
|
|||
Latency time.Duration `json:"latency" form:"latency" gorm:"column:latency;comment:延迟" swaggertype:"string"` // 延迟
|
|||
Agent string `json:"agent" form:"agent" gorm:"column:agent;comment:代理"` // 代理
|
|||
ErrorMessage string `json:"error_message" form:"error_message" gorm:"column:error_message;comment:错误信息"` // 错误信息
|
|||
Body string `json:"body" form:"body" gorm:"type:text;column:body;comment:请求Body"` // 请求Body
|
|||
Resp string `json:"resp" form:"resp" gorm:"type:text;column:resp;comment:响应Body"` // 响应Body
|
|||
UserID int `json:"user_id" form:"user_id" gorm:"column:user_id;comment:用户id"` // 用户id
|
|||
User SysUser `json:"user"` |
|||
} |
@ -0,0 +1,10 @@ |
|||
package system |
|||
|
|||
import ( |
|||
"autocode/config" |
|||
) |
|||
|
|||
// 配置文件结构体
|
|||
type System struct { |
|||
Config config.Server `json:"config"` |
|||
} |
@ -0,0 +1,21 @@ |
|||
package system |
|||
|
|||
import ( |
|||
"autocode/global" |
|||
"github.com/satori/go.uuid" |
|||
) |
|||
|
|||
type SysUser struct { |
|||
global.GVA_MODEL |
|||
UUID uuid.UUID `json:"uuid" gorm:"comment:用户UUID"` // 用户UUID
|
|||
Username string `json:"userName" gorm:"comment:用户登录名"` // 用户登录名
|
|||
Password string `json:"-" gorm:"comment:用户登录密码"` // 用户登录密码
|
|||
NickName string `json:"nickName" gorm:"default:系统用户;comment:用户昵称"` // 用户昵称
|
|||
SideMode string `json:"sideMode" gorm:"default:dark;comment:用户侧边主题"` // 用户侧边主题
|
|||
HeaderImg string `json:"headerImg" gorm:"default:https://qmplusimg.henrongyi.top/gva_header.jpg;comment:用户头像"` // 用户头像
|
|||
BaseColor string `json:"baseColor" gorm:"default:#fff;comment:基础颜色"` // 基础颜色
|
|||
ActiveColor string `json:"activeColor" gorm:"default:#1890ff;comment:活跃颜色"` // 活跃颜色
|
|||
AuthorityId string `json:"authorityId" gorm:"default:888;comment:用户角色ID"` // 用户角色ID
|
|||
Authority SysAuthority `json:"authority" gorm:"foreignKey:AuthorityId;references:AuthorityId;comment:用户角色"` |
|||
Authorities []SysAuthority `json:"authorities" gorm:"many2many:sys_user_authority;"` |
|||
} |
@ -0,0 +1,10 @@ |
|||
package system |
|||
|
|||
type SysUseAuthority struct { |
|||
SysUserId uint `gorm:"column:sys_user_id"` |
|||
SysAuthorityAuthorityId string `gorm:"column:sys_authority_authority_id"` |
|||
} |
|||
|
|||
func (s *SysUseAuthority) TableName() string { |
|||
return "sys_user_authority" |
|||
} |
@ -0,0 +1,4 @@ |
|||
//go:build !packfile
|
|||
// +build !packfile
|
|||
|
|||
package packfile |
@ -0,0 +1,46 @@ |
|||
//go:build packfile
|
|||
// +build packfile
|
|||
|
|||
package packfile |
|||
|
|||
import ( |
|||
"fmt" |
|||
"io/ioutil" |
|||
"os" |
|||
"path/filepath" |
|||
"strings" |
|||
) |
|||
|
|||
//go:generate go-bindata -o=staticFile.go -pkg=packfile -tags=packfile ../resource/... ../config.yaml
|
|||
|
|||
func writeFile(path string, data []byte) { |
|||
// 如果文件夹不存在,预先创建文件夹
|
|||
if lastSeparator := strings.LastIndex(path, "/"); lastSeparator != -1 { |
|||
dirPath := path[:lastSeparator] |
|||
if _, err := os.Stat(dirPath); err != nil && os.IsNotExist(err) { |
|||
os.MkdirAll(dirPath, os.ModePerm) |
|||
} |
|||
} |
|||
|
|||
// 已存在的文件,不应该覆盖重写,可能在前端更改了配置文件等
|
|||
if _, err := os.Stat(path); os.IsNotExist(err) { |
|||
if err2 := ioutil.WriteFile(path, data, os.ModePerm); err2 != nil { |
|||
fmt.Printf("Write file failed: %s\n", path) |
|||
} |
|||
} else { |
|||
fmt.Printf("File exist, skip: %s\n", path) |
|||
} |
|||
} |
|||
|
|||
func init() { |
|||
for key := range _bindata { |
|||
filePath, _ := filepath.Abs(strings.TrimPrefix(key, ".")) |
|||
data, err := Asset(key) |
|||
if err != nil { |
|||
// Asset was not found.
|
|||
fmt.Printf("Fail to find: %s\n", filePath) |
|||
} else { |
|||
writeFile(filePath, data) |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,20 @@ |
|||
package autocode |
|||
|
|||
import ( |
|||
v1 "autocode/api/v1" |
|||
"github.com/gin-gonic/gin" |
|||
) |
|||
|
|||
type AutoCodeExampleRouter struct{} |
|||
|
|||
func (s *AutoCodeExampleRouter) InitSysAutoCodeExampleRouter(Router *gin.RouterGroup) { |
|||
autoCodeExampleRouter := Router.Group("hi") |
|||
autoCodeExampleRouterWithoutRecord := Router.Group("hi") |
|||
autoCodeExampleApi := v1.ApiGroupApp |
|||
{ |
|||
autoCodeExampleRouter.POST("hi", autoCodeExampleApi.CreateAutoCodeExample) // 新建AutoCodeExample
|
|||
} |
|||
{ |
|||
autoCodeExampleRouterWithoutRecord.GET("hi", autoCodeExampleApi.FindAutoCodeExample) // 根据ID获取AutoCodeExample
|
|||
} |
|||
} |
@ -0,0 +1,7 @@ |
|||
package autocode |
|||
|
|||
type RouterGroup struct { |
|||
// Code generated by github.com/flipped-aurora/yibu/server Begin; DO NOT EDIT.
|
|||
AutoCodeExampleRouter |
|||
// Code generated by github.com/flipped-aurora/yibu/server End; DO NOT EDIT.
|
|||
} |
@ -0,0 +1,11 @@ |
|||
package router |
|||
|
|||
import ( |
|||
"autocode/router/autocode" |
|||
) |
|||
|
|||
type RouterGroup struct { |
|||
Autocode autocode.RouterGroup |
|||
} |
|||
|
|||
var RouterGroupApp = new(RouterGroup) |
@ -0,0 +1,77 @@ |
|||
package autocode |
|||
|
|||
import ( |
|||
"autocode/global" |
|||
"autocode/model/autocode" |
|||
"autocode/model/autocode/request" |
|||
) |
|||
|
|||
type AutoCodeExampleService struct{} |
|||
|
|||
//@author: [piexlmax](https://github.com/piexlmax)
|
|||
//@function: CreateAutoCodeExample
|
|||
//@description: 创建自动化示例数据
|
|||
//@param: autoCodeExampleService *AutoCodeExampleService
|
|||
//@return: err error
|
|||
|
|||
func (autoCodeExampleService *AutoCodeExampleService) CreateAutoCodeExample(autoCodeExample autocode.AutoCodeExample) (err error) { |
|||
err = global.GVA_DB.Create(&autoCodeExample).Error |
|||
return err |
|||
} |
|||
|
|||
//@author: [piexlmax](https://github.com/piexlmax)
|
|||
//@function: DeleteAutoCodeExample
|
|||
//@description: 删除自动化示例数据
|
|||
//@param: autoCodeExample autocode.AutoCodeExample
|
|||
//@return: err error
|
|||
|
|||
func (autoCodeExampleService *AutoCodeExampleService) DeleteAutoCodeExample(autoCodeExample autocode.AutoCodeExample) (err error) { |
|||
err = global.GVA_DB.Delete(&autoCodeExample).Error |
|||
return err |
|||
} |
|||
|
|||
//@author: [piexlmax](https://github.com/piexlmax)
|
|||
//@function: UpdateAutoCodeExample
|
|||
//@description: 更新自动化示例数据
|
|||
//@param: autoCodeExample *autocode.AutoCodeExample
|
|||
//@return: err error
|
|||
|
|||
func (autoCodeExampleService *AutoCodeExampleService) UpdateAutoCodeExample(autoCodeExample *autocode.AutoCodeExample) (err error) { |
|||
err = global.GVA_DB.Save(autoCodeExample).Error |
|||
return err |
|||
} |
|||
|
|||
//@author: [piexlmax](https://github.com/piexlmax)
|
|||
//@function: GetAutoCodeExampleDetail
|
|||
//@description: 根据id获取自动化示例数据
|
|||
//@param: id uint
|
|||
//@return: err error, autoCodeExample autocode.AutoCodeExample
|
|||
|
|||
func (autoCodeExampleService *AutoCodeExampleService) GetAutoCodeExample(id uint) (err error, autoCodeExample autocode.AutoCodeExample) { |
|||
err = global.GVA_DB.Where("id = ?", id).First(&autoCodeExample).Error |
|||
return |
|||
} |
|||
|
|||
//@author: [piexlmax](https://github.com/piexlmax)
|
|||
//@function: GetAutoCodeExampleInfoList
|
|||
//@description: 分页获取自动化示例数据
|
|||
//@param: info request.AutoCodeExampleSearch
|
|||
//@return: err error, list interface{}, total int64
|
|||
|
|||
func (autoCodeExampleService *AutoCodeExampleService) GetAutoCodeExampleInfoList(info request.AutoCodeExampleSearch) (err error, list interface{}, total int64) { |
|||
limit := info.PageSize |
|||
offset := info.PageSize * (info.Page - 1) |
|||
// 创建db
|
|||
db := global.GVA_DB.Model(&autocode.AutoCodeExample{}) |
|||
var autoCodeExamples []autocode.AutoCodeExample |
|||
// 如果有条件搜索 下方会自动创建搜索语句
|
|||
if info.AutoCodeExampleField != "" { |
|||
db = db.Where("label LIKE ?", "%"+info.AutoCodeExampleField+"%") |
|||
} |
|||
err = db.Count(&total).Error |
|||
if err != nil { |
|||
return |
|||
} |
|||
err = db.Limit(limit).Offset(offset).Find(&autoCodeExamples).Error |
|||
return err, autoCodeExamples, total |
|||
} |
@ -0,0 +1,7 @@ |
|||
package autocode |
|||
|
|||
type ServiceGroup struct { |
|||
// Code generated by github.com/flipped-aurora/yibu/server Begin; DO NOT EDIT.
|
|||
AutoCodeExampleService |
|||
// Code generated by github.com/flipped-aurora/yibu/server End; DO NOT EDIT.
|
|||
} |
@ -0,0 +1,11 @@ |
|||
package service |
|||
|
|||
import ( |
|||
"autocode/service/autocode" |
|||
) |
|||
|
|||
type ServiceGroup struct { |
|||
AutoCodeServiceGroup autocode.ServiceGroup |
|||
} |
|||
|
|||
var ServiceGroupApp = new(ServiceGroup) |
@ -0,0 +1,108 @@ |
|||
package utils |
|||
|
|||
import ( |
|||
"io/ioutil" |
|||
"os" |
|||
"strconv" |
|||
) |
|||
|
|||
// 前端传来文件片与当前片为什么文件的第几片
|
|||
// 后端拿到以后比较次分片是否上传 或者是否为不完全片
|
|||
// 前端发送每片多大
|
|||
// 前端告知是否为最后一片且是否完成
|
|||
|
|||
const ( |
|||
breakpointDir = "./breakpointDir/" |
|||
finishDir = "./fileDir/" |
|||
) |
|||
|
|||
//@author: [piexlmax](https://github.com/piexlmax)
|
|||
//@function: BreakPointContinue
|
|||
//@description: 断点续传
|
|||
//@param: content []byte, fileName string, contentNumber int, contentTotal int, fileMd5 string
|
|||
//@return: error, string
|
|||
|
|||
func BreakPointContinue(content []byte, fileName string, contentNumber int, contentTotal int, fileMd5 string) (error, string) { |
|||
path := breakpointDir + fileMd5 + "/" |
|||
err := os.MkdirAll(path, os.ModePerm) |
|||
if err != nil { |
|||
return err, path |
|||
} |
|||
err, pathc := makeFileContent(content, fileName, path, contentNumber) |
|||
return err, pathc |
|||
} |
|||
|
|||
//@author: [piexlmax](https://github.com/piexlmax)
|
|||
//@function: CheckMd5
|
|||
//@description: 检查Md5
|
|||
//@param: content []byte, chunkMd5 string
|
|||
//@return: CanUpload bool
|
|||
|
|||
func CheckMd5(content []byte, chunkMd5 string) (CanUpload bool) { |
|||
fileMd5 := MD5V(content) |
|||
if fileMd5 == chunkMd5 { |
|||
return true // 可以继续上传
|
|||
} else { |
|||
return false // 切片不完整,废弃
|
|||
} |
|||
} |
|||
|
|||
//@author: [piexlmax](https://github.com/piexlmax)
|
|||
//@function: makeFileContent
|
|||
//@description: 创建切片内容
|
|||
//@param: content []byte, fileName string, FileDir string, contentNumber int
|
|||
//@return: error, string
|
|||
|
|||
func makeFileContent(content []byte, fileName string, FileDir string, contentNumber int) (error, string) { |
|||
path := FileDir + fileName + "_" + strconv.Itoa(contentNumber) |
|||
f, err := os.Create(path) |
|||
if err != nil { |
|||
return err, path |
|||
} else { |
|||
_, err = f.Write(content) |
|||
if err != nil { |
|||
return err, path |
|||
} |
|||
} |
|||
defer f.Close() |
|||
return nil, path |
|||
} |
|||
|
|||
//@author: [piexlmax](https://github.com/piexlmax)
|
|||
//@function: makeFileContent
|
|||
//@description: 创建切片文件
|
|||
//@param: fileName string, FileMd5 string
|
|||
//@return: error, string
|
|||
|
|||
func MakeFile(fileName string, FileMd5 string) (error, string) { |
|||
rd, err := ioutil.ReadDir(breakpointDir + FileMd5) |
|||
if err != nil { |
|||
return err, finishDir + fileName |
|||
} |
|||
_ = os.MkdirAll(finishDir, os.ModePerm) |
|||
fd, err := os.OpenFile(finishDir+fileName, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0o644) |
|||
if err != nil { |
|||
return err, finishDir + fileName |
|||
} |
|||
defer fd.Close() |
|||
for k := range rd { |
|||
content, _ := ioutil.ReadFile(breakpointDir + FileMd5 + "/" + fileName + "_" + strconv.Itoa(k)) |
|||
_, err = fd.Write(content) |
|||
if err != nil { |
|||
_ = os.Remove(finishDir + fileName) |
|||
return err, finishDir + fileName |
|||
} |
|||
} |
|||
return nil, finishDir + fileName |
|||
} |
|||
|
|||
//@author: [piexlmax](https://github.com/piexlmax)
|
|||
//@function: RemoveChunk
|
|||
//@description: 移除切片
|
|||
//@param: FileMd5 string
|
|||
//@return: error
|
|||
|
|||
func RemoveChunk(FileMd5 string) error { |
|||
err := os.RemoveAll(breakpointDir + FileMd5) |
|||
return err |
|||
} |
@ -0,0 +1,57 @@ |
|||
package captcha |
|||
|
|||
import ( |
|||
"context" |
|||
"time" |
|||
|
|||
"autocode/global" |
|||
"github.com/mojocn/base64Captcha" |
|||
"go.uber.org/zap" |
|||
) |
|||
|
|||
func NewDefaultRedisStore() *RedisStore { |
|||
return &RedisStore{ |
|||
Expiration: time.Second * 180, |
|||
PreKey: "CAPTCHA_", |
|||
} |
|||
} |
|||
|
|||
type RedisStore struct { |
|||
Expiration time.Duration |
|||
PreKey string |
|||
Context context.Context |
|||
} |
|||
|
|||
func (rs *RedisStore) UseWithCtx(ctx context.Context) base64Captcha.Store { |
|||
rs.Context = ctx |
|||
return rs |
|||
} |
|||
|
|||
func (rs *RedisStore) Set(id string, value string) { |
|||
err := global.GVA_REDIS.Set(rs.Context, rs.PreKey+id, value, rs.Expiration).Err() |
|||
if err != nil { |
|||
global.GVA_LOG.Error("RedisStoreSetError!", zap.Error(err)) |
|||
} |
|||
} |
|||
|
|||
func (rs *RedisStore) Get(key string, clear bool) string { |
|||
val, err := global.GVA_REDIS.Get(rs.Context, key).Result() |
|||
if err != nil { |
|||
global.GVA_LOG.Error("RedisStoreGetError!", zap.Error(err)) |
|||
return "" |
|||
} |
|||
if clear { |
|||
err := global.GVA_REDIS.Del(rs.Context, key).Err() |
|||
if err != nil { |
|||
global.GVA_LOG.Error("RedisStoreClearError!", zap.Error(err)) |
|||
return "" |
|||
} |
|||
} |
|||
return val |
|||
} |
|||
|
|||
func (rs *RedisStore) Verify(id, answer string, clear bool) bool { |
|||
key := rs.PreKey + id |
|||
v := rs.Get(key, clear) |
|||
return v == answer |
|||
} |
@ -0,0 +1,74 @@ |
|||
package utils |
|||
|
|||
import ( |
|||
"autocode/global" |
|||
systemReq "autocode/model/system/request" |
|||
"github.com/gin-gonic/gin" |
|||
uuid "github.com/satori/go.uuid" |
|||
) |
|||
|
|||
func GetClaims(c *gin.Context) (*systemReq.CustomClaims, error) { |
|||
token := c.Request.Header.Get("x-token") |
|||
j := NewJWT() |
|||
claims, err := j.ParseToken(token) |
|||
if err != nil { |
|||
global.GVA_LOG.Error("从Gin的Context中获取从jwt解析信息失败, 请检查请求头是否存在x-token且claims是否为规定结构") |
|||
} |
|||
return claims, err |
|||
} |
|||
|
|||
// 从Gin的Context中获取从jwt解析出来的用户ID
|
|||
func GetUserID(c *gin.Context) uint { |
|||
if claims, exists := c.Get("claims"); !exists { |
|||
if cl, err := GetClaims(c); err != nil { |
|||
return 0 |
|||
} else { |
|||
return cl.ID |
|||
} |
|||
} else { |
|||
waitUse := claims.(*systemReq.CustomClaims) |
|||
return waitUse.ID |
|||
} |
|||
} |
|||
|
|||
// 从Gin的Context中获取从jwt解析出来的用户UUID
|
|||
func GetUserUuid(c *gin.Context) uuid.UUID { |
|||
if claims, exists := c.Get("claims"); !exists { |
|||
if cl, err := GetClaims(c); err != nil { |
|||
return uuid.UUID{} |
|||
} else { |
|||
return cl.UUID |
|||
} |
|||
} else { |
|||
waitUse := claims.(*systemReq.CustomClaims) |
|||
return waitUse.UUID |
|||
} |
|||
} |
|||
|
|||
// 从Gin的Context中获取从jwt解析出来的用户角色id
|
|||
func GetUserAuthorityId(c *gin.Context) string { |
|||
if claims, exists := c.Get("claims"); !exists { |
|||
if cl, err := GetClaims(c); err != nil { |
|||
return "" |
|||
} else { |
|||
return cl.AuthorityId |
|||
} |
|||
} else { |
|||
waitUse := claims.(*systemReq.CustomClaims) |
|||
return waitUse.AuthorityId |
|||
} |
|||
} |
|||
|
|||
// 从Gin的Context中获取从jwt解析出来的用户角色id
|
|||
func GetUserInfo(c *gin.Context) *systemReq.CustomClaims { |
|||
if claims, exists := c.Get("claims"); !exists { |
|||
if cl, err := GetClaims(c); err != nil { |
|||
return nil |
|||
} else { |
|||
return cl |
|||
} |
|||
} else { |
|||
waitUse := claims.(*systemReq.CustomClaims) |
|||
return waitUse |
|||
} |
|||
} |
Some files were not shown because too many files changed in this diff
Write
Preview
Loading…
Cancel
Save
Reference in new issue