Skip to content

Instantly share code, notes, and snippets.

@IndianGuru
Last active September 20, 2015 07:24
Show Gist options
  • Select an option

  • Save IndianGuru/852fc85f55c3fdb1db26 to your computer and use it in GitHub Desktop.

Select an option

Save IndianGuru/852fc85f55c3fdb1db26 to your computer and use it in GitHub Desktop.
Declaring struts
// Declare structs which describe your data
// Quote is a datastore entity that represents a single quote.
// It also serves as (a part of) a response of QuotesAPI.
// Each attribute has its own json tag.
// All the attributes in the struct start with a capital letter
// so that the attribute is accessible outside the package.
// A "-" tag name means that the datastore will ignore that attribute.
type Quote struct {
UID *datastore.Key `json:"uid" datastore:"-"`
Author string `json:"author"`
Message string `json:"message"`
}
// A QuotesAPI struct defines all the endpoints of the quotes API.
// It will have functions for CRUD like Add, List etc.
type QuotesAPI struct {
}
// Quotes contains a slice of quotes. This type is needed because go-endpoints
// only supports pointers to structs as input and output types.
type Quotes struct {
Quotes []Quote `json:"quotes"`
}
// AddRequest contains all the fields needed to create a new Quote.
type AddRequest struct {
Author string
Message string
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment