initialize.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package file_store
  2. import (
  3. "cold-delivery/conf"
  4. "fmt"
  5. "os"
  6. "path/filepath"
  7. "strings"
  8. )
  9. type OXS struct {
  10. // Endpoint 访问域名
  11. Endpoint string
  12. // AccessKeyID AK
  13. AccessKeyID string
  14. // AccessKeySecret AKS
  15. AccessKeySecret string
  16. // BucketName 桶名称
  17. BucketName string
  18. }
  19. // Setup 配置文件存储driver
  20. func (e *OXS) Setup(driver DriverType, options ...ClientOption) FileStoreType {
  21. fileStoreType := driver
  22. var fileStore FileStoreType
  23. switch fileStoreType {
  24. case AliYunOSS:
  25. fileStore = new(ALiYunOSS)
  26. err := fileStore.Setup(e.Endpoint, e.AccessKeyID, e.AccessKeySecret, e.BucketName)
  27. if err != nil {
  28. fmt.Println(err)
  29. }
  30. return fileStore
  31. case HuaweiOBS:
  32. fileStore = new(HuaWeiOBS)
  33. err := fileStore.Setup(e.Endpoint, e.AccessKeyID, e.AccessKeySecret, e.BucketName)
  34. if err != nil {
  35. fmt.Println(err)
  36. }
  37. return fileStore
  38. case QiNiuKodo:
  39. fileStore = new(QiNiuKODO)
  40. err := fileStore.Setup(e.Endpoint, e.AccessKeyID, e.AccessKeySecret, e.BucketName)
  41. if err != nil {
  42. fmt.Println(err)
  43. }
  44. return fileStore
  45. }
  46. return nil
  47. }
  48. var QiniuFileStore FileStoreType
  49. func QiniuSetup() {
  50. e := OXS{
  51. conf.ExtConfig.Qiniu.Endpoint,
  52. conf.ExtConfig.Qiniu.AccessKeyID,
  53. conf.ExtConfig.Qiniu.AccessKeySecret,
  54. conf.ExtConfig.Qiniu.BucketName}
  55. QiniuFileStore = e.Setup(QiNiuKodo, map[string]interface{}{"Zone": "华东"})
  56. }
  57. // golang获取程序运行路径
  58. func GetCurrentDirectory() string {
  59. dir, _ := filepath.Abs(filepath.Dir(os.Args[0]))
  60. return strings.Replace(dir, "\\", "/", -1)
  61. }