Browse Source

增加备注与调整一些细节

main
SliverHorn 4 years ago
parent
commit
c1f7658374
  1. 26
      server/config/gorm.go
  2. 2
      server/service/exa_file_upload_download.go
  3. 4
      server/utils/upload/local.go
  4. 5
      server/utils/upload/qiniu.go
  5. 2
      server/utils/upload/upload.go

26
server/config/gorm.go

@ -11,19 +11,6 @@ type Mysql struct {
LogMode bool `mapstructure:"log-mode" json:"logMode" yaml:"log-mode"`
}
type Postgresql struct {
Host string `mapstructure:"host" json:"host" yaml:"host"`
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"`
PreferSimpleProtocol bool `mapstructure:"prefer-simple-protocol" json:"preferSimpleProtocol" yaml:"prefer-simple-protocol"`
Logger bool `mapstructure:"logger" json:"logger" yaml:"logger"`
}
type Sqlite struct {
Path string `mapstructure:"path" json:"path" yaml:"path"`
MaxIdleConns int `mapstructure:"max-idle-conns" json:"maxIdleConns" yaml:"max-idle-conns"`
@ -41,3 +28,16 @@ type Sqlserver struct {
Logger bool `mapstructure:"logger" json:"logger" yaml:"logger"`
}
type Postgresql struct {
Host string `mapstructure:"host" json:"host" yaml:"host"`
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"`
PreferSimpleProtocol bool `mapstructure:"prefer-simple-protocol" json:"preferSimpleProtocol" yaml:"prefer-simple-protocol"`
Logger bool `mapstructure:"logger" json:"logger" yaml:"logger"`
}

2
server/service/exa_file_upload_download.go

@ -76,7 +76,7 @@ func GetFileRecordInfoList(info request.PageInfo) (err error, list interface{},
// @return file file model.ExaFileUploadAndDownload
func UploadFile(header *multipart.FileHeader, noSave string) (err error, file model.ExaFileUploadAndDownload) {
filePath, key, uploadErr := upload.Oss.Upload(header)
filePath, key, uploadErr := upload.Oss.UploadFile(header)
if uploadErr != nil {
panic(err)
}

4
server/utils/upload/local.go

@ -14,7 +14,8 @@ import (
type Local struct{}
func (l Local) Upload(file *multipart.FileHeader) (string, string, error) {
// UploadFile 上传文件
func (l Local) UploadFile(file *multipart.FileHeader) (string, string, error) {
// 读取文件后缀
ext := path.Ext(file.Filename)
// 读取文件名并加密
@ -54,6 +55,7 @@ func (l Local) Upload(file *multipart.FileHeader) (string, string, error) {
return p, filename, nil
}
// DeleteFile 删除文件
func (l Local) DeleteFile(key string) error {
p := global.GVA_CONFIG.Local.Path + "/" + key
if strings.Contains(p, global.GVA_CONFIG.Local.Path) {

5
server/utils/upload/qiniu.go

@ -14,8 +14,8 @@ import (
type Qiniu struct{}
// 接收两个参数 一个文件流 一个 bucket 你的七牛云标准空间的名字
func (*Qiniu) Upload(file *multipart.FileHeader) (string, string, error) {
// Upload 上传文件
func (*Qiniu) UploadFile(file *multipart.FileHeader) (string, string, error) {
putPolicy := storage.PutPolicy{Scope: global.GVA_CONFIG.Qiniu.Bucket}
mac := qbox.NewMac(global.GVA_CONFIG.Qiniu.AccessKey, global.GVA_CONFIG.Qiniu.SecretKey)
upToken := putPolicy.UploadToken(mac)
@ -39,6 +39,7 @@ func (*Qiniu) Upload(file *multipart.FileHeader) (string, string, error) {
return global.GVA_CONFIG.Qiniu.ImgPath + "/" + ret.Key, ret.Key, nil
}
// DeleteFile 删除文件
func (*Qiniu) DeleteFile(key string) error {
mac := qbox.NewMac(global.GVA_CONFIG.Qiniu.AccessKey, global.GVA_CONFIG.Qiniu.SecretKey)
cfg := qiniuConfig()

2
server/utils/upload/upload.go

@ -8,7 +8,7 @@ import (
var Oss OSS
type OSS interface {
Upload(file *multipart.FileHeader) (string, string, error)
UploadFile(file *multipart.FileHeader) (string, string, error)
DeleteFile(key string) error
}

Loading…
Cancel
Save