我正在尝试在 GoLang 中构建 Amazon S3 客户端,但在进行 API 调用时遇到问题。我收到一条错误消息,提示“没有这样的主机”,但我确信我提供的凭据是正确的。
定义一个结构体来保存客户端
// the Client struct holding the client itself as well as the bucket.
type S3Client struct {
S3clientObject s3.S3
bucket string
}
// Initialize the client
func CreateS3Client() S3Client{
S3clientCreate := S3Client{S3clientObject: Connect(), bucket: GetS3Bucket()}
if (!CheckBuckets(S3clientCreate)) {
exitErrorf("Bucket does not exist, try again.")
}
return S3clientCreate
}
Run Code Online (Sandbox Code Playgroud)
连接到存储桶
func Connect() s3.S3{
// Initialize a session
sess, err := session.NewSession(&aws.Config{
Credentials: credentials.NewStaticCredentials("myCredentials", "myCreds", ""),
Endpoint: aws.String("myDomain"),
Region: aws.String("myRegion"),
},
)
if …Run Code Online (Sandbox Code Playgroud)