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
| func fetch(w http.ResponseWriter, r *http.Request) { | |
| c := appengine.NewContext(r) | |
| // If we omitted the .Ancestor from this query there would be | |
| // a slight chance that Quote that had just been written would not | |
| // show up in a query. | |
| q := datastore.NewQuery("Quote").Ancestor(quoteKey(c)).Limit(10) | |
| quotes := make([]Quote, 0, 10) | |
| _, err := q.GetAll(c, "es) |
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
| // quoteKey returns the key used for all quote entries. | |
| func quoteKey(c context.Context) *datastore.Key { | |
| return datastore.NewKey(c, "Quote", "default_quote", 0, nil) | |
| } | |
| // Add creates a new quote given the fields in AddRequest, stores it in the | |
| // datastore, and returns it. | |
| func (QuotesAPI) Add(c context.Context, r *AddRequest) (*Quote, error) { | |
| // We set the same parent key on every Quote entity to ensure each Quote | |
| // is in the same entity group. Queries across the single entity group |
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
| // List returns a list of all the existing quotes. | |
| func (QuotesAPI) List(c context.Context) (*Quotes, error) { | |
| quotes := []Quote{} | |
| // If we omitted the .Ancestor from this query there would be | |
| // a slight chance that Quote that had just been written would not | |
| // show up in a query. | |
| keys, err := datastore.NewQuery("Quote").Ancestor(quoteKey(c)).GetAll(c, "es) | |
| if err != nil { | |
| return nil, err | |
| } |
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
| func init() { | |
| // register the quotes API with cloud endpoints. | |
| api, err := endpoints.RegisterService(QuotesAPI{}, "quotesService", "v1", "Quotes API", true) | |
| if err != nil { | |
| panic(err) | |
| } | |
| // adapt the name, method, and path for each method. | |
| info := api.MethodByName("List").Info() | |
| info.Name, info.HTTPMethod, info.Path = "getQuotes", "GET", "quotesService" |
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 goendpoint exposes a REST API to manage quotes stored in the Google | |
| // Cloud Datastore using the Cloud Endpoints feature of App Engine. | |
| package goendpoint | |
| import ( | |
| // Package endpoints will let you write Cloud Endpoints backend in Go. | |
| // http://godoc.org/github.com/GoogleCloudPlatform/go-endpoints/endpoints | |
| "github.com/GoogleCloudPlatform/go-endpoints/endpoints" | |
| // Package context defines the Context type | |
| // Do not store Contexts inside a struct type; instead, pass a |
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
| application: quotesnew-2983 | |
| module: default | |
| version: v1 | |
| runtime: go | |
| api_version: go1 | |
| # Important! Even though there's a catch all routing above, | |
| # without these two lines it's not going to work. | |
| # Make sure you have this: | |
| handlers: |
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
| // 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:"-"` |
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 geowebgap | |
| import ( | |
| "fmt" | |
| "net/http" | |
| ) | |
| func init() { | |
| http.HandleFunc("/", handler) | |
| } |
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
| # application is mandatory | |
| application: geowebgap | |
| # version is mandatory | |
| version: 1-0 | |
| # runtime is mandatory | |
| runtime: go | |
| # api_version is mandatory |
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
| type Response struct { | |
| Results []struct { | |
| Geometry struct { | |
| Location struct { | |
| Lat float64 | |
| Lng float64 | |
| } | |
| } | |
| } | |
| } |