improve golang example

This commit is contained in:
Quentin 2023-11-23 10:46:14 +01:00
parent 5cedde9b9f
commit eb29f67298
Signed by: quentin
GPG key ID: E9602264D639FF68

View file

@ -54,4 +54,33 @@ func main() {
panic(err)
}
fmt.Printf(strings.Join(msg.Message, "\n"))
// Key
// -- create
key := "openapi-key"
keyInfo, r, err := client.KeyApi.AddKey(ctx).AddKeyRequest(garage.AddKeyRequest{Name: *garage.NewNullableString(&key) }).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `KeyApi.AddKey`\n")
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
panic(err)
}
fmt.Printf("AWS_ACCESS_KEY_ID=%s\nAWS_SECRET_ACCESS_KEY=%s\n", *keyInfo.AccessKeyId, *keyInfo.SecretAccessKey.Get())
// Bucket
// -- create
global_name := "global-ns-openapi-bucket"
local_name := "local-ns-openapi-bucket"
bucketInfo, r, err := client.BucketApi.CreateBucket(ctx).CreateBucketRequest(garage.CreateBucketRequest{
GlobalAlias: &global_name,
LocalAlias: &garage.CreateBucketRequestLocalAlias {
AccessKeyId: keyInfo.AccessKeyId,
Alias: &local_name,
},
}).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `BucketApi.CreateBucket`\n")
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
panic(err)
}
fmt.Printf("Bucket id: %s\n", *bucketInfo.Id)
}