first commit
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
package models
|
||||
|
||||
import "time"
|
||||
|
||||
// StorageConfig 存储配置(单行配置)
|
||||
type StorageConfig struct {
|
||||
ID uint64 `orm:"column(id);pk;auto" json:"id"`
|
||||
StorageType string `orm:"column(storage_type);size(20);default(local)" json:"storage_type"` // local/qiniu
|
||||
// 七牛云配置
|
||||
QiniuAccessKey string `orm:"column(qiniu_access_key);size(255);null" json:"qiniu_access_key"`
|
||||
QiniuSecretKey string `orm:"column(qiniu_secret_key);size(255);null" json:"qiniu_secret_key"`
|
||||
QiniuBucket string `orm:"column(qiniu_bucket);size(128);null" json:"qiniu_bucket"`
|
||||
QiniuDomain string `orm:"column(qiniu_domain);size(255);null" json:"qiniu_domain"` // CDN域名
|
||||
QiniuRegion string `orm:"column(qiniu_region);size(50);null" json:"qiniu_region"` // 存储区域
|
||||
CreateTime time.Time `orm:"column(create_time);type(datetime);auto_now_add" json:"create_time"`
|
||||
UpdateTime *time.Time `orm:"column(update_time);type(datetime);auto_now;null" json:"update_time"`
|
||||
}
|
||||
|
||||
func (m *StorageConfig) TableName() string {
|
||||
return "yz_system_storage_config"
|
||||
}
|
||||
|
||||
// GetStorageConfig 获取存储配置
|
||||
func GetStorageConfig() (*StorageConfig, error) {
|
||||
var cfg StorageConfig
|
||||
err := Orm.QueryTable(new(StorageConfig)).OrderBy("-id").One(&cfg)
|
||||
if err != nil {
|
||||
// 默认配置:本地存储
|
||||
return &StorageConfig{StorageType: "local"}, nil
|
||||
}
|
||||
if cfg.StorageType == "" {
|
||||
cfg.StorageType = "local"
|
||||
}
|
||||
return &cfg, nil
|
||||
}
|
||||
Reference in New Issue
Block a user