go install github.com/zeromicro/go-zero/tools/goctl@latest
goctl api new core
goctl api go core.api -dir . -style gozero
https://console.cloud.tencent.com/cos
go get -u github.com/tencentyun/cos-go-sdk-v5
package main
import (
"context"
"github.com/tencentyun/cos-go-sdk-v5"
"net/http"
"net/url"
"os"
)
func main() {
u, _ := url.Parse("https://examplebucket-1250000000.cos.ap-guangzhou.myqcloud.com")
b := &cos.BaseURL{BucketURL: u}
client := cos.NewClient(b, &http.Client{
Transport: &cos.AuthorizationTransport{
SecretID: "YOUR-COS-SECRET-ID",
SecretKey: "YOUR-COS-SECRET-KEY",
},
})
key := "exampleobject"
_, _, err := client.Object.Upload(
context.Background(), key, "localfile", nil,
)
if err != nil {
panic(err)
}
}