123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- package file_store
- import (
- "cold-delivery/conf"
- "fmt"
- "os"
- "path/filepath"
- "strings"
- )
- type OXS struct {
- // Endpoint 访问域名
- Endpoint string
- // AccessKeyID AK
- AccessKeyID string
- // AccessKeySecret AKS
- AccessKeySecret string
- // BucketName 桶名称
- BucketName string
- }
- // Setup 配置文件存储driver
- func (e *OXS) Setup(driver DriverType, options ...ClientOption) FileStoreType {
- fileStoreType := driver
- var fileStore FileStoreType
- switch fileStoreType {
- case AliYunOSS:
- fileStore = new(ALiYunOSS)
- err := fileStore.Setup(e.Endpoint, e.AccessKeyID, e.AccessKeySecret, e.BucketName)
- if err != nil {
- fmt.Println(err)
- }
- return fileStore
- case HuaweiOBS:
- fileStore = new(HuaWeiOBS)
- err := fileStore.Setup(e.Endpoint, e.AccessKeyID, e.AccessKeySecret, e.BucketName)
- if err != nil {
- fmt.Println(err)
- }
- return fileStore
- case QiNiuKodo:
- fileStore = new(QiNiuKODO)
- err := fileStore.Setup(e.Endpoint, e.AccessKeyID, e.AccessKeySecret, e.BucketName)
- if err != nil {
- fmt.Println(err)
- }
- return fileStore
- }
- return nil
- }
- var QiniuFileStore FileStoreType
- func QiniuSetup() {
- e := OXS{
- conf.ExtConfig.Qiniu.Endpoint,
- conf.ExtConfig.Qiniu.AccessKeyID,
- conf.ExtConfig.Qiniu.AccessKeySecret,
- conf.ExtConfig.Qiniu.BucketName}
- QiniuFileStore = e.Setup(QiNiuKodo, map[string]interface{}{"Zone": "华东"})
- }
- // golang获取程序运行路径
- func GetCurrentDirectory() string {
- dir, _ := filepath.Abs(filepath.Dir(os.Args[0]))
- return strings.Replace(dir, "\\", "/", -1)
- }
|