Last active
November 16, 2024 14:45
-
-
Save hekki/5d98f764e6e4cfe91309f54a17b3db96 to your computer and use it in GitHub Desktop.
さくらのクラウドのオブジェクトストレージをaws-sdk-go-v2から扱うサンプルコード
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"context" | |
"fmt" | |
"log" | |
"github.com/aws/aws-sdk-go-v2/config" | |
"github.com/aws/aws-sdk-go-v2/service/s3" | |
) | |
var ( | |
baseEndpoint = "https://s3.isk01.sakurastorage.jp" | |
) | |
func main() { | |
ctx := context.Background() | |
cfg, err := config.LoadDefaultConfig(ctx) | |
if err != nil { | |
log.Fatalln(err) | |
} | |
client := s3.NewFromConfig(cfg, func(options *s3.Options) { | |
options.BaseEndpoint = &baseEndpoint | |
}) | |
bs, err := client.ListBuckets(ctx, nil) | |
if err != nil { | |
panic(err) | |
} | |
for _, b := range bs.Buckets { | |
fmt.Println(*b.Name) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment