user568280
user568280

Reputation: 465

Go Struct / Tag Syntax

I'm looking for an explanation of the below syntax:

type GetBucketTaggingInput struct {
    _ struct{} `locationName:"GetBucketTaggingRequest" type:"structure"`

    // The name of the bucket for which to get the tagging information.
    //
    // Bucket is a required field
    Bucket *string `location:"uri" locationName:"Bucket" type:"string" required:"true"`
}

Specifically, this line:

_ struct{} `locationName:"GetBucketTaggingRequest" type:"structure"`

I understand the tags are metadata but how is the metadata used in this context? Also, I don't understand:

_ struct{}

Regarding the Bucket variable, again, I'm unsure of the need for the metadata apart maybe from the required field.

Incidentally, this is from the AWS Go SDK.

Thanks!

Upvotes: 2

Views: 266

Answers (1)

Thundercat
Thundercat

Reputation: 121119

The AWS SDK uses _ struct{} to specify metadata for the struct.

_ is the blank identifier.

struct{} is an anonymous struct type with no fields. A value of this has zero size.

locationName:"GetBucketTaggingRequest" type:"structure" is a field tag.

The SDK uses the reflect package to find the tag for the field _.

Upvotes: 2

Related Questions