songzhibin97
3 years ago
20 changed files with 302 additions and 55 deletions
-
12server/config.docker.yaml
-
32server/config.yaml
-
3server/config/config.go
-
21server/config/db_list.go
-
33server/config/oss.go
-
10server/config/oss_aliyun.go
-
9server/config/oss_huawei.go
-
5server/config/oss_local.go
-
11server/config/oss_qiniu.go
-
10server/config/oss_tencent.go
-
22server/global/global.go
-
1server/go.mod
-
2server/go.sum
-
31server/initialize/db_list.go
-
21server/initialize/gorm_mysql.go
-
20server/initialize/gorm_pgsql.go
-
1server/main.go
-
65server/utils/upload/obs.go
-
20server/utils/upload/upload.go
-
20web/src/view/systemTools/system/system.vue
@ -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 |
||||
|
} |
@ -1,33 +0,0 @@ |
|||||
package config |
|
||||
|
|
||||
type Local struct { |
|
||||
Path string `mapstructure:"path" json:"path" yaml:"path"` // 本地文件路径
|
|
||||
} |
|
||||
|
|
||||
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上传加速
|
|
||||
} |
|
||||
|
|
||||
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"` |
|
||||
} |
|
||||
|
|
||||
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,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,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,31 @@ |
|||||
|
package initialize |
||||
|
|
||||
|
import ( |
||||
|
"github.com/flipped-aurora/gin-vue-admin/server/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,65 @@ |
|||||
|
package upload |
||||
|
|
||||
|
import ( |
||||
|
"github.com/flipped-aurora/gin-vue-admin/server/global" |
||||
|
"github.com/huaweicloud/huaweicloud-sdk-go-obs/obs" |
||||
|
"github.com/pkg/errors" |
||||
|
"mime/multipart" |
||||
|
) |
||||
|
|
||||
|
var HuaWeiObs = new(_obs) |
||||
|
|
||||
|
type _obs struct{} |
||||
|
|
||||
|
func NewHuaWeiObsClient() (client *obs.ObsClient, err error) { |
||||
|
return obs.New(global.GVA_CONFIG.HuaWeiObs.AccessKey, global.GVA_CONFIG.HuaWeiObs.SecretKey, global.GVA_CONFIG.HuaWeiObs.Endpoint) |
||||
|
} |
||||
|
|
||||
|
func (o *_obs) UploadFile(file *multipart.FileHeader) (filename string, filepath string, err error) { |
||||
|
var open multipart.File |
||||
|
open, err = file.Open() |
||||
|
if err != nil { |
||||
|
return filename, filepath, err |
||||
|
} |
||||
|
filename = file.Filename |
||||
|
input := &obs.PutObjectInput{ |
||||
|
PutObjectBasicInput: obs.PutObjectBasicInput{ |
||||
|
ObjectOperationInput: obs.ObjectOperationInput{ |
||||
|
Bucket: global.GVA_CONFIG.HuaWeiObs.Bucket, |
||||
|
Key: filename, |
||||
|
}, |
||||
|
ContentType: file.Header.Get("content-type"), |
||||
|
}, |
||||
|
Body: open, |
||||
|
} |
||||
|
|
||||
|
var client *obs.ObsClient |
||||
|
client, err = NewHuaWeiObsClient() |
||||
|
if err != nil { |
||||
|
return filepath, filename, errors.Wrap(err, "获取华为对象存储对象失败!") |
||||
|
} |
||||
|
|
||||
|
_, err = client.PutObject(input) |
||||
|
if err != nil { |
||||
|
return filepath, filename, errors.Wrap(err, "文件上传失败!") |
||||
|
} |
||||
|
filepath = global.GVA_CONFIG.HuaWeiObs.Path + "/" + filename |
||||
|
return filepath, filename, err |
||||
|
} |
||||
|
|
||||
|
func (o *_obs) DeleteFile(key string) error { |
||||
|
client, err := NewHuaWeiObsClient() |
||||
|
if err != nil { |
||||
|
return errors.Wrap(err, "获取华为对象存储对象失败!") |
||||
|
} |
||||
|
input := &obs.DeleteObjectInput{ |
||||
|
Bucket: global.GVA_CONFIG.HuaWeiObs.Bucket, |
||||
|
Key: key, |
||||
|
} |
||||
|
var output *obs.DeleteObjectOutput |
||||
|
output, err = client.DeleteObject(input) |
||||
|
if err != nil { |
||||
|
return errors.Wrapf(err, "删除对象(%s)失败!, output: %v", key, output) |
||||
|
} |
||||
|
return nil |
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue