From 1b15bbc7d4993a164b39a33c39e8d76783925006 Mon Sep 17 00:00:00 2001 From: csnero Date: Sat, 26 Jun 2021 20:54:12 +0800 Subject: [PATCH 01/10] =?UTF-8?q?[=E4=BF=AE=E5=A4=8D=E9=98=BF=E9=87=8C?= =?UTF-8?q?=E4=BA=91OSS=E5=9B=BE=E7=89=87=E4=B8=8A=E4=BC=A0=E8=B7=AF?= =?UTF-8?q?=E5=BE=84=E4=B8=8D=E4=B8=80=E8=87=B4=E9=94=99=E8=AF=AF]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/config.yaml | 1 + server/config/oss.go | 1 + server/utils/upload/aliyun_oss.go | 4 ++-- web/src/components/upload/image.vue | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/server/config.yaml b/server/config.yaml index 9d969a7d..716b007f 100644 --- a/server/config.yaml +++ b/server/config.yaml @@ -104,6 +104,7 @@ aliyun-oss: access-key-secret: 'yourAccessKeySecret' bucket-name: 'yourBucketName' bucket-url: 'yourBucketUrl' + base-path: 'yourBasePath' # tencent cos configuration tencent-cos: diff --git a/server/config/oss.go b/server/config/oss.go index a78420af..37957ddf 100644 --- a/server/config/oss.go +++ b/server/config/oss.go @@ -20,6 +20,7 @@ type AliyunOSS struct { 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"` } type TencentCOS struct { Bucket string `mapstructure:"bucket" json:"bucket" yaml:"bucket"` diff --git a/server/utils/upload/aliyun_oss.go b/server/utils/upload/aliyun_oss.go index fcba9700..beb7b2bc 100644 --- a/server/utils/upload/aliyun_oss.go +++ b/server/utils/upload/aliyun_oss.go @@ -6,7 +6,6 @@ import ( "github.com/aliyun/aliyun-oss-go-sdk/oss" "go.uber.org/zap" "mime/multipart" - "path/filepath" "time" ) @@ -27,7 +26,8 @@ func (*AliyunOSS) UploadFile(file *multipart.FileHeader) (string, string, error) } defer f.Close() // 创建文件 defer 关闭 // 上传阿里云路径 文件名格式 自己可以改 建议保证唯一性 - yunFileTmpPath := filepath.Join("uploads", time.Now().Format("2006-01-02")) + "/" + file.Filename + //yunFileTmpPath := filepath.Join("uploads", time.Now().Format("2006-01-02")) + "/" + file.Filename + yunFileTmpPath := global.GVA_CONFIG.AliyunOSS.BasePath + "/" + "uploads" + "/" + time.Now().Format("2006-01-02") + "/" + file.Filename // 上传文件流。 err = bucket.PutObject(yunFileTmpPath, f) diff --git a/web/src/components/upload/image.vue b/web/src/components/upload/image.vue index 3db8f8e4..57e7734e 100644 --- a/web/src/components/upload/image.vue +++ b/web/src/components/upload/image.vue @@ -17,7 +17,7 @@ :before-upload="beforeImageUpload" :multiple="false" > - + From 5b1fc9b1ab96fca04a7f0c276ad3d316f05173fc Mon Sep 17 00:00:00 2001 From: Jamie Slome Date: Tue, 6 Jul 2021 09:53:20 +0100 Subject: [PATCH 02/10] Create SECURITY.md --- SECURITY.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 SECURITY.md diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 00000000..db76aea0 --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,5 @@ +# Security Policy + +## Reporting a Vulnerability + +Please report security issues to qimiaojiangjizhao@gmail.com From ff1f61bf694b9d3aa2ed0156758f85209683ca5a Mon Sep 17 00:00:00 2001 From: SliverHorn Date: Fri, 9 Jul 2021 21:52:17 +0800 Subject: [PATCH 03/10] =?UTF-8?q?update:=20=E8=87=AA=E5=AE=9A=E4=B9=89gorm?= =?UTF-8?q?=E7=9A=84logger=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/config/gorm.go | 4 +- server/initialize/gorm.go | 16 ++----- server/initialize/internal/logger.go | 72 ++++++++-------------------- server/initialize/timer.go | 1 - 4 files changed, 28 insertions(+), 65 deletions(-) diff --git a/server/config/gorm.go b/server/config/gorm.go index 2524b190..ae6c7384 100644 --- a/server/config/gorm.go +++ b/server/config/gorm.go @@ -8,8 +8,8 @@ type Mysql struct { 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 bool `mapstructure:"log-mode" json:"logMode" yaml:"log-mode"` // 是否开启Gorm全局日志 - LogZap string `mapstructure:"log-zap" json:"logZap" yaml:"log-zap"` + 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 { diff --git a/server/initialize/gorm.go b/server/initialize/gorm.go index 0ac364c9..c3d997c8 100644 --- a/server/initialize/gorm.go +++ b/server/initialize/gorm.go @@ -78,7 +78,7 @@ func GormMysql() *gorm.DB { DontSupportRenameColumn: true, // 用 `change` 重命名列,MySQL 8 之前的数据库和 MariaDB 不支持重命名列 SkipInitializeWithVersion: false, // 根据版本自动配置 } - if db, err := gorm.Open(mysql.New(mysqlConfig), gormConfig(m.LogMode)); err != nil { + if db, err := gorm.Open(mysql.New(mysqlConfig), gormConfig()); err != nil { //global.GVA_LOG.Error("MySQL启动异常", zap.Any("err", err)) //os.Exit(0) //return nil @@ -97,9 +97,9 @@ func GormMysql() *gorm.DB { //@param: mod bool //@return: *gorm.Config -func gormConfig(mod bool) *gorm.Config { - var config = &gorm.Config{DisableForeignKeyConstraintWhenMigrating: true} - switch global.GVA_CONFIG.Mysql.LogZap { +func gormConfig() *gorm.Config { + config := &gorm.Config{DisableForeignKeyConstraintWhenMigrating: true} + switch global.GVA_CONFIG.Mysql.LogMode { case "silent", "Silent": config.Logger = internal.Default.LogMode(logger.Silent) case "error", "Error": @@ -108,14 +108,8 @@ func gormConfig(mod bool) *gorm.Config { config.Logger = internal.Default.LogMode(logger.Warn) case "info", "Info": config.Logger = internal.Default.LogMode(logger.Info) - case "zap", "Zap": - config.Logger = internal.Default.LogMode(logger.Info) default: - if mod { - config.Logger = internal.Default.LogMode(logger.Info) - break - } - config.Logger = internal.Default.LogMode(logger.Silent) + config.Logger = internal.Default.LogMode(logger.Info) } return config } diff --git a/server/initialize/internal/logger.go b/server/initialize/internal/logger.go index e44f563c..c7fe9254 100644 --- a/server/initialize/internal/logger.go +++ b/server/initialize/internal/logger.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "gin-vue-admin/global" - "go.uber.org/zap" "gorm.io/gorm/logger" "gorm.io/gorm/utils" "io/ioutil" @@ -13,11 +12,6 @@ import ( "time" ) -// writer log writer interface -type writer interface { - Printf(string, ...interface{}) -} - type config struct { SlowThreshold time.Duration Colorful bool @@ -34,27 +28,27 @@ var ( Recorder = traceRecorder{Interface: Default, BeginAt: time.Now()} ) -func New(writer writer, config config) logger.Interface { +func New(writer logger.Writer, config config) logger.Interface { var ( infoStr = "%s\n[info] " warnStr = "%s\n[warn] " errStr = "%s\n[error] " - traceStr = "%s\n[%.3fms] [rows:%v] %s" - traceWarnStr = "%s %s\n[%.3fms] [rows:%v] %s" - traceErrStr = "%s %s\n[%.3fms] [rows:%v] %s" + traceStr = "%s\n[%.3fms] [rows:%v] %s\n" + traceWarnStr = "%s %s\n[%.3fms] [rows:%v] %s\n" + traceErrStr = "%s %s\n[%.3fms] [rows:%v] %s\n" ) if config.Colorful { infoStr = logger.Green + "%s\n" + logger.Reset + logger.Green + "[info] " + logger.Reset warnStr = logger.BlueBold + "%s\n" + logger.Reset + logger.Magenta + "[warn] " + logger.Reset errStr = logger.Magenta + "%s\n" + logger.Reset + logger.Red + "[error] " + logger.Reset - traceStr = logger.Green + "%s\n" + logger.Reset + logger.Yellow + "[%.3fms] " + logger.BlueBold + "[rows:%v]" + logger.Reset + " %s" - traceWarnStr = logger.Green + "%s " + logger.Yellow + "%s\n" + logger.Reset + logger.RedBold + "[%.3fms] " + logger.Yellow + "[rows:%v]" + logger.Magenta + " %s" + logger.Reset - traceErrStr = logger.RedBold + "%s " + logger.MagentaBold + "%s\n" + logger.Reset + logger.Yellow + "[%.3fms] " + logger.BlueBold + "[rows:%v]" + logger.Reset + " %s" + traceStr = logger.Green + "%s\n" + logger.Reset + logger.Yellow + "[%.3fms] " + logger.BlueBold + "[rows:%v]" + logger.Reset + " %s\n" + traceWarnStr = logger.Green + "%s " + logger.Yellow + "%s\n" + logger.Reset + logger.RedBold + "[%.3fms] " + logger.Yellow + "[rows:%v]" + logger.Magenta + " %s\n" + logger.Reset + traceErrStr = logger.RedBold + "%s " + logger.MagentaBold + "%s\n" + logger.Reset + logger.Yellow + "[%.3fms] " + logger.BlueBold + "[rows:%v]" + logger.Reset + " %s\n" } - return &customLogger{ - writer: writer, + return &_logger{ + Writer: writer, config: config, infoStr: infoStr, warnStr: warnStr, @@ -65,43 +59,43 @@ func New(writer writer, config config) logger.Interface { } } -type customLogger struct { - writer +type _logger struct { config + logger.Writer infoStr, warnStr, errStr string traceStr, traceErrStr, traceWarnStr string } // LogMode log mode -func (c *customLogger) LogMode(level logger.LogLevel) logger.Interface { +func (c *_logger) LogMode(level logger.LogLevel) logger.Interface { newLogger := *c newLogger.LogLevel = level return &newLogger } // Info print info -func (c *customLogger) Info(ctx context.Context, message string, data ...interface{}) { +func (c *_logger) Info(ctx context.Context, message string, data ...interface{}) { if c.LogLevel >= logger.Info { c.Printf(c.infoStr+message, append([]interface{}{utils.FileWithLineNum()}, data...)...) } } // Warn print warn messages -func (c *customLogger) Warn(ctx context.Context, message string, data ...interface{}) { +func (c *_logger) Warn(ctx context.Context, message string, data ...interface{}) { if c.LogLevel >= logger.Warn { c.Printf(c.warnStr+message, append([]interface{}{utils.FileWithLineNum()}, data...)...) } } // Error print error messages -func (c *customLogger) Error(ctx context.Context, message string, data ...interface{}) { +func (c *_logger) Error(ctx context.Context, message string, data ...interface{}) { if c.LogLevel >= logger.Error { c.Printf(c.errStr+message, append([]interface{}{utils.FileWithLineNum()}, data...)...) } } // Trace print sql message -func (c *customLogger) Trace(ctx context.Context, begin time.Time, fc func() (string, int64), err error) { +func (c *_logger) Trace(ctx context.Context, begin time.Time, fc func() (string, int64), err error) { if c.LogLevel > 0 { elapsed := time.Since(begin) switch { @@ -131,35 +125,11 @@ func (c *customLogger) Trace(ctx context.Context, begin time.Time, fc func() (st } } -func (c *customLogger) Printf(message string, data ...interface{}) { - if global.GVA_CONFIG.Mysql.LogZap != "" { - switch len(data) { - case 0: - global.GVA_LOG.Info(message) - case 1: - global.GVA_LOG.Info("gorm", zap.Any("src", data[0])) - case 2: - global.GVA_LOG.Info("gorm", zap.Any("src", data[0]), zap.Any("duration", data[1])) - case 3: - global.GVA_LOG.Info("gorm", zap.Any("src", data[0]), zap.Any("duration", data[1]), zap.Any("rows", data[2])) - case 4: - global.GVA_LOG.Info("gorm", zap.Any("src", data[0]), zap.Any("duration", data[1]), zap.Any("rows", data[2]), zap.Any("sql", data[3])) - } - return - } - switch len(data) { - case 0: - c.writer.Printf(message, "") - case 1: - c.writer.Printf(message, data[0]) - case 2: - c.writer.Printf(message, data[0], data[1]) - case 3: - c.writer.Printf(message, data[0], data[1], data[2]) - case 4: - c.writer.Printf(message, data[0], data[1], data[2], data[3]) - case 5: - c.writer.Printf(message, data[0], data[1], data[2], data[3], data[4]) +func (c *_logger) Printf(message string, data ...interface{}) { + if global.GVA_CONFIG.Mysql.LogZap { + global.GVA_LOG.Info(fmt.Sprintf(message, data...)) + } else { + c.Writer.Printf(message, data...) } } diff --git a/server/initialize/timer.go b/server/initialize/timer.go index 6fa27913..ecc41c8d 100644 --- a/server/initialize/timer.go +++ b/server/initialize/timer.go @@ -10,7 +10,6 @@ import ( func Timer() { if global.GVA_CONFIG.Timer.Start { for _, detail := range global.GVA_CONFIG.Timer.Detail { - fmt.Println(detail) go func(detail config.Detail) { global.GVA_Timer.AddTaskByFunc("ClearDB", global.GVA_CONFIG.Timer.Spec, func() { err := utils.ClearTable(global.GVA_DB, detail.TableName, detail.CompareField, detail.Interval) From a6e62f388eb9e15e063ac91e49e61ad474eec71a Mon Sep 17 00:00:00 2001 From: SliverHorn Date: Sat, 10 Jul 2021 10:22:25 +0800 Subject: [PATCH 04/10] update: server/README.md --- server/README.md | 96 ++++++++++++++++++++++++++---------------------- 1 file changed, 53 insertions(+), 43 deletions(-) diff --git a/server/README.md b/server/README.md index 2305e494..9a34870b 100644 --- a/server/README.md +++ b/server/README.md @@ -1,44 +1,54 @@ +## server项目结构 + +```shell +├── api +│   └── v1 +├── config +├── core +├── docs +├── global +├── initialize +│   └── internal +├── middleware +├── model +│   ├── request +│   └── response +├── packfile +├── resource +│   ├── excel +│   ├── page +│   └── template +├── router +├── service +├── source +└── utils + ├── timer + └── upload +``` + +| 文件夹 | 说明 | 描述 | +| ------------ | ----------------------- | --------------------------- | +| `api` | api层 | api层 | +| `--v1` | v1版本接口 | v1版本接口 | +| `config` | 配置包 | config.yaml对应的配置结构体 | +| `core` | 核心文件 | 核心组件(zap, viper, server)的初始化 | +| `docs` | swagger文档目录 | swagger文档目录 | +| `global` | 全局对象 | 全局对象 | +| `initialize` | 初始化 | router,redis,gorm,validator, timer的初始化 | +| `--internal` | 初始化内部函数 | gorm 的 longger 自定义,在此文件夹的函数只能由 `initialize` 层进行调用 | +| `middleware` | 中间件层 | 用于存放 `gin` 中间件代码 | +| `model` | 模型层 | 模型对应数据表 | +| `--request` | 入参结构体 | 接收前端发送到后端的数据。 | +| `--response` | 出参结构体 | 返回给前端的数据结构体 | +| `packfile` | 静态文件打包 | 静态文件打包 | +| `resource` | 静态资源文件夹 | 负责存放静态文件 | +| `--excel` | excel导入导出默认路径 | excel导入导出默认路径 | +| `--page` | 表单生成器 | 表单生成器 打包后的dist | +| `--template` | 模板 | 模板文件夹,存放的是代码生成器的模板 | +| `router` | 路由层 | 路由层 | +| `service` | service层 | 存放业务逻辑问题 | +| `source` | source层 | 存放初始化数据的函数 | +| `utils` | 工具包 | 工具函数封装 | +| `--timer` | timer | 定时器接口封装 | +| `--upload` | oss | oss接口封装 | -整理代码结构 -``` lua -web -├── api/v1 -- 主要API -| ├── sys_initdb.go -- ico -| └── sys_user.go -- -├── config -- 配置文件 设定操作的结构体 -| ├── auto_code.go -- ico captcha.go -| ├── ... -- ico captcha.go -| └── zap.go -- core -├── core -- 主要结构代码 -| ├── server_other.go -- ico captcha.go -| ├── ... -- ico captcha.go -| └── zap.go -- -├── docs -- 文档系统 -| ├── docs.go -- ico captcha.go -| ├── swagger.json -- json -| └── swagger.yaml -- yaml -├── global -- global -├── initialize -- initialize -├── middleware -- 中间键 -├── model -- global -│ ├── request -- 所有请求model结构体 -| | ├── common.go -| | ├── ... -| | └── sys_user.go -- yaml -| ├── response -- 返回数据 -| | ├── common.go -| | ├── ... -| | └── sys_user.go -- yaml -├── packfile -- 文件写入 -├── resource -- 资源文件 -├── router -- 路由 -├── service -- service层 -├── source -- 文件目录操作 -├── utils -├── config.yaml -- -├── Dockerfile -- docker配置 -├── go.mod -- mod 配置 -├── go.sum -- sum -├── latest_log -- vue-cli 配置 -└── main.go -- package.json -``` \ No newline at end of file From d252134f3c134f2bf5a4aae9ae9255585c60efb8 Mon Sep 17 00:00:00 2001 From: "bypanghu@163.com" Date: Sat, 10 Jul 2021 11:11:13 +0800 Subject: [PATCH 05/10] change web/init on method , update web README --- web/README.md | 15 ++++++++++++--- web/src/view/init/index.vue | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/web/README.md b/web/README.md index ad0c9d58..bd680747 100644 --- a/web/README.md +++ b/web/README.md @@ -38,6 +38,10 @@ web │ ├── api -- 所有请求 │ ├── assets -- 主题 字体等静态资源 | ├── components -- components组件 +| ├── core -- gva抽离的一些前端资源 +| | ├── config.js -- 配置文件 +| | └── element_lazy.js -- elementt按需引入文件 +| | └── gin-vue-admin.js -- gva前端控制库 | ├── directive -- 公用方法 | ├── mixins -- 公用方法 | ├── router -- 路由权限 @@ -57,15 +61,20 @@ web | | ├── example --上传案例 | | ├── iconList -- icon列表 | | ├── init -- 初始化数据 +| | | ├── index -- 新版本 +| | | ├── init -- 旧版本 | | ├── layout -- layout约束页面 | | | ├── aside -- | | | ├── bottomInfo -- bottomInfo | | | ├── screenfull -- 全屏设置 +| | | ├── setting -- 系统设置 | | | └── index.vue -- base 约束 -| | ├── login --结算单管理 -| | ├── person --结算单管理 +| | ├── login --登录 +| | ├── person --个人中心 | | ├── superAdmin -- 超级管理员操作 -| | └── home.vue -- page 入口页面 +| | ├── system -- 系统检测页面 +| | ├── systemTools -- 系统配置相关页面 +| | └── routerHolder.vue -- page 入口页面 │ ├── App.vue -- 入口页面 │ ├── main.js -- 入口文件 加载组件 初始化等 │ └── permission.js -- 跳转 diff --git a/web/src/view/init/index.vue b/web/src/view/init/index.vue index fbf71e4b..1531a75e 100644 --- a/web/src/view/init/index.vue +++ b/web/src/view/init/index.vue @@ -85,7 +85,7 @@ export default { console.log(this.hello) }, goDoc() { - window.open('https://www.gin-vue-admin.com') + window.open('https://www.gin-vue-admin.com/docs/first_master#3-init') }, async onSubmit() { const loading = this.$loading({ From 63af7ee4cb7de895ed19b62f166176da6e5093b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=92=8B=E5=90=89=E5=85=86?= <303176530@qq.com> Date: Sat, 10 Jul 2021 12:08:28 +0800 Subject: [PATCH 06/10] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=E5=9B=BE=E7=89=87=E7=9B=B8=E5=85=B3bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/components/upload/image.vue | 15 ++++++--------- web/src/view/example/upload/upload.vue | 2 +- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/web/src/components/upload/image.vue b/web/src/components/upload/image.vue index 57e7734e..c0acc258 100644 --- a/web/src/components/upload/image.vue +++ b/web/src/components/upload/image.vue @@ -1,10 +1,3 @@ - - + -