27 lines
581 B
Go
27 lines
581 B
Go
package cos
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"net/url"
|
|
|
|
"git.lzcwy.cn/zhengchiliu/zt-closet-backend/global"
|
|
"github.com/tencentyun/cos-go-sdk-v5"
|
|
)
|
|
|
|
func NewCosClient() (*cos.Client, error) {
|
|
u, err := url.Parse("https://" + global.CosSetting.CosUploadDomain)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("parse cos upload domain: %w", err)
|
|
}
|
|
b := &cos.BaseURL{BucketURL: u}
|
|
client := cos.NewClient(b, &http.Client{
|
|
Transport: &cos.AuthorizationTransport{
|
|
SecretID: global.CosSetting.CosSecretID,
|
|
SecretKey: global.CosSetting.CosSecretKey,
|
|
},
|
|
})
|
|
|
|
return client, nil
|
|
}
|