Files
zt-closet-backend/pkg/cos/cosclient.go
T
2026-09-11 01:41:52 +08:00

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
}