package infra

import (
	"github.com/aliyun/aliyun-oss-go-sdk/oss"
	"os"
)

var (
	GlobalOssClient *oss.Client
	GlobalOssBucket *oss.Bucket
)

func InitOss(isUseCname bool, endpoint string, accessKeyId string, accessKeySecret string, bucketName string) {
	var err error
	if isUseCname {
		GlobalOssClient, err = oss.New(endpoint, accessKeyId, accessKeySecret, oss.UseCname(true)) // 公网
	} else {
		GlobalOssClient, err = oss.New(endpoint, accessKeyId, accessKeySecret, oss.UseCname(false)) // 内网
	}
	if err != nil {
		GlobalLogger.Error("无法创建阿里云client:", err)
		os.Exit(-1)
	}
	GlobalOssBucket, err = GlobalOssClient.Bucket(bucketName)
	if err != nil {
		GlobalLogger.Error("无法创建阿里云bucket:", err)
		os.Exit(-1)
	}
}
