package config

import (
	"cicv-data-closedloop/common/config/c_log"
	"fmt"
	"github.com/aliyun/aliyun-oss-go-sdk/oss"
	"os"
)

var (
	cname           = "http://open-bucket.oss.icvdc.com"
	endpoint        = "oss-cn-beijing-gqzl-d01-a.ops.gqzl-cloud.com"
	accessKeyId     = "n8glvFGS25MrLY7j"
	accessKeySecret = "xZ2Fozoarpfw0z28FUhtg8cu0yDc5d"
	bucketName      = "open-bucket"
	OssClient       *oss.Client
	OssBucket       *oss.Bucket

	cname2           = "http://pji-bucket1.oss.icvdc.com"
	endpoint2        = "oss-cn-beijing-gqzl-d01-a.ops.gqzl-cloud.com"
	accessKeyId2     = "n8glvFGS25MrLY7j"
	accessKeySecret2 = "xZ2Fozoarpfw0z28FUhtg8cu0yDc5d"
	bucketName2      = "pji-bucket1"
	OssClient2       *oss.Client
	OssBucket2       *oss.Bucket
)

func InitOss(isUseCname bool) {
	var err error
	if isUseCname {
		OssClient, err = oss.New(cname, accessKeyId, accessKeySecret, oss.UseCname(true)) // 公网
	} else {
		OssClient, err = oss.New(endpoint, accessKeyId, accessKeySecret, oss.UseCname(false)) // 内网
	}
	if err != nil {
		fmt.Println("无法创建阿里云client:", err)
		os.Exit(-1)
	}
	OssBucket, err = OssClient.Bucket(bucketName)
	if err != nil {
		fmt.Println("无法创建阿里云bucket:", err)
		os.Exit(-1)
	}
	c_log.GlobalLogger.Info("国汽oss信息为：", OssClient)
}

func InitOss2(isUseCname bool) {
	var err error
	if isUseCname {
		OssClient2, err = oss.New(cname2, accessKeyId2, accessKeySecret2, oss.UseCname(true)) // 公网
	} else {
		OssClient2, err = oss.New(endpoint2, accessKeyId2, accessKeySecret2, oss.UseCname(false)) // 内网
	}
	if err != nil {
		fmt.Println("无法创建阿里云client:", err)
		os.Exit(-1)
	}
	OssBucket2, err = OssClient2.Bucket(bucketName2)
	if err != nil {
		fmt.Println("无法创建阿里云bucket:", err)
		os.Exit(-1)
	}
	c_log.GlobalLogger.Info("朴津oss信息为：", OssClient2)
}
