I'm using Go and GoRestful to program a RESTFUL front end to some entities stored on Google App Engine Datastore.
The data is turned into JSON/XML and presented to the user with tags controlling the style for each format. How can I also apply tags to the name of the struct itself so it is output using the correct style?
An example of my structs would be:
type Shallow struct {
Key string `datastore:"-" json:"key" xml:"key"`
LastModified time.Time `json:"last_modified" xml:"last-modified"`
Version int `json:"version" xml:"version"`
Status int `json:"status" xml:"status"`
Link Link `datastore:"-" json:"link" xml:"link"`
Name string `json:"name" xml:"name"`
}
type ProbabilityEntry struct {
ItemId int64 `datastore:"ItemId" json:"item_id" xml:"item-id"`
Probability float32 `datastore:"Probability" json:"probability" xml:"probability"`
Quantity int16 `datastore:"Quantity" json:"quantity" xml:"quantity"`
}
type LootTable struct {
Shallow
AllowPreload bool `json:"allow_preload" xml:"allow-preload"`
Probabilities []ProbabilityEntry `json:"probabilities" xml:"probabilities"`
}
When the LootTable struct emits to JSON/XML it should represent itself as 'loot_table' or 'loot-table' rather than 'LootTable'.