package models

import (
	"fmt"
	"os"

	"github.com/aliyun/aliyun-oss-go-sdk/oss"
)

func GetBucket(bucketName string) *oss.Bucket {
	// 从config文件中读取配置
	endpoint := Viper.Get("oss.endpoint").(string)
	accessID := Viper.Get("oss.accessID").(string)
	accessKey := Viper.Get("oss.accessKey").(string)

	client, err := oss.New(endpoint, accessID, accessKey)
	if err != nil {
		HandleError(err)
	}

	bucket, err := client.Bucket(bucketName)
	if err != nil {
		HandleError(err)
	}

	return bucket
}

func HandleError(err error) {
	fmt.Println("Error:", err)
	os.Exit(-1)
}
