diff --git a/app/admin/apis/public/file.go b/app/admin/apis/public/file.go index af899de..c69241c 100644 --- a/app/admin/apis/public/file.go +++ b/app/admin/apis/public/file.go @@ -24,6 +24,8 @@ type FileResponse struct { Type string `json:"type"` } +const path = "static/uploadfile/" + type File struct { apis.Api } @@ -72,7 +74,11 @@ func (e *File) baseImg(c *gin.Context, fileResponse FileResponse, urlPerfix stri ddd, _ := base64.StdEncoding.DecodeString(file2list[1]) guid := uuid.New().String() fileName := guid + ".jpg" - base64File := "static/uploadfile/" + fileName + err := utils.IsNotExistMkDir(path) + if err != nil { + e.Error(c, 500, errors.New(""), "初始化文件路径失败") + } + base64File := path + fileName _ = ioutil.WriteFile(base64File, ddd, 0666) typeStr := strings.Replace(strings.Replace(file2list[0], "data:", "", -1), ";base64", "", -1) fileResponse = FileResponse{ @@ -83,7 +89,7 @@ func (e *File) baseImg(c *gin.Context, fileResponse FileResponse, urlPerfix stri Type: typeStr, } source, _ := c.GetPostForm("source") - err := thirdUpload(source, fileName, base64File) + err = thirdUpload(source, fileName, base64File) if err != nil { e.Error(c, 200, errors.New(""), "上传第三方失败") return fileResponse @@ -102,7 +108,12 @@ func (e *File) multipleFile(c *gin.Context, urlPerfix string) []FileResponse { for _, f := range files { guid := uuid.New().String() fileName := guid + utils.GetExt(f.Filename) - multipartFileName := "static/uploadfile/" + fileName + + err := utils.IsNotExistMkDir(path) + if err != nil { + e.Error(c, 500, errors.New(""), "初始化文件路径失败") + } + multipartFileName := path + fileName err1 := c.SaveUploadedFile(f, multipartFileName) fileType, _ := utils.GetType(multipartFileName) if err1 == nil { @@ -139,7 +150,12 @@ func (e *File) singleFile(c *gin.Context, fileResponse FileResponse, urlPerfix s guid := uuid.New().String() fileName := guid + utils.GetExt(files.Filename) - singleFile := "static/uploadfile/" + fileName + + err = utils.IsNotExistMkDir(path) + if err != nil { + e.Error(c, 500, errors.New(""), "初始化文件路径失败") + } + singleFile := path + fileName _ = c.SaveUploadedFile(files, singleFile) fileType, _ := utils.GetType(singleFile) fileResponse = FileResponse{ @@ -178,4 +194,4 @@ func ossUpload(name string, path string) error { func qiniuUpload(name string, path string) error { oss := file_store.ALiYunOSS{} return oss.UpLoad(name, path) -} +} \ No newline at end of file diff --git a/cmd/api/server.go b/cmd/api/server.go index 0b998e4..dde9044 100644 --- a/cmd/api/server.go +++ b/cmd/api/server.go @@ -22,6 +22,7 @@ import ( "go-admin/app/jobs" "go-admin/common/database" "go-admin/common/global" + ext "go-admin/config" ) var ( @@ -50,7 +51,8 @@ func init() { } func setup() { - + // 注入配置扩展项 + config.ExtendConfig = &ext.ExtConfig //1. 读取配置 config.Setup(file.NewSource, file.WithPath(configYml)) go config.Watch() @@ -148,4 +150,4 @@ func run() error { func tip() { usageStr := `欢迎使用 ` + pkg.Green(`go-admin `+global.Version) + ` 可以使用 ` + pkg.Red(`-h`) + ` 查看命令` fmt.Printf("%s \n\n", usageStr) -} +} \ No newline at end of file diff --git a/common/global/adm.go b/common/global/adm.go index 64267b8..8757d13 100644 --- a/common/global/adm.go +++ b/common/global/adm.go @@ -2,7 +2,7 @@ package global const ( // go-admin Version Info - Version = "1.3.2" + Version = "1.3.3" ) var ( diff --git a/config/extent.go b/config/extent.go new file mode 100644 index 0000000..e477fbf --- /dev/null +++ b/config/extent.go @@ -0,0 +1,16 @@ +package config + +var ExtConfig Extand + +// 扩展配置 +// extend: +// demo: +// name: demo-name +// 使用方法: config.ExtConfig......即可!! +type Extand struct { + // Demo Demo // 这里配置对应配置文件的结构即可 +} + +type Demo struct { + Name string +} \ No newline at end of file diff --git a/config/settings.full.yml b/config/settings.full.yml index 96b2aab..dfe7269 100644 --- a/config/settings.full.yml +++ b/config/settings.full.yml @@ -42,8 +42,14 @@ settings: source: user:password@tcp(127.0.0.1:3306)/dbname?charset=utf8&parseTime=True&loc=Local&timeout=1000ms # source: sqlite3.db # source: host=myhost port=myport user=gorm dbname=gorm password=mypassword + registers: + - sources: + - user:password@tcp(127.0.0.1:3306)/dbname?charset=utf8&parseTime=True&loc=Local&timeout=1000ms gen: # 代码生成读取的数据库名称 dbname: dbname # 代码生成是使用前端代码存放位置,需要指定到src文件夹,相对路径 frontpath: ../go-admin-ui/src + extend: # 扩展项使用说明 + demo: + name: data \ No newline at end of file diff --git a/config/settings.yml b/config/settings.yml index 878ec6a..c9fc749 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -31,8 +31,14 @@ settings: driver: mysql # 数据库连接字符串 mysql 缺省信息 charset=utf8&parseTime=True&loc=Local&timeout=1000ms source: user:password@tcp(127.0.0.1:3306)/dbname?charset=utf8&parseTime=True&loc=Local&timeout=1000ms + registers: + - sources: + - user:password@tcp(127.0.0.1:3306)/dbname?charset=utf8&parseTime=True&loc=Local&timeout=1000ms gen: # 代码生成读取的数据库名称 dbname: dbname # 代码生成是使用前端代码存放位置,需要指定到src文件夹,相对路径 frontpath: ../go-admin-ui/src + extend: # 扩展项使用说明 + demo: + name: data \ No newline at end of file