package c_oss

import "os"

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

type OssConnectInfoStruct struct {
	Endpoint        string `json:"endpoint"`
	AccessKeyId     string `json:"accessKeyId"`
	AccessKeySecret string `json:"accessKeySecret"`
	BucketName      string `json:"bucketName"`
}

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
)

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)
	}
}
