Skip to content

Instantly share code, notes, and snippets.

@rdarder
Created November 2, 2014 04:18
Show Gist options
  • Save rdarder/c72b8f36778910f211be to your computer and use it in GitHub Desktop.
Save rdarder/c72b8f36778910f211be to your computer and use it in GitHub Desktop.
Go-endpoints default values annotations
/* app.yaml
application: ping
version: 1
runtime: go
api_version: go1
handlers:
- url: /_ah/spi/.*
script: _go_app
*/
package ping
// "appengine/datastore"
import (
"github.com/crhym3/go-endpoints/endpoints"
"net/http"
)
type Ping struct {
Ttl int `json:"ttl" endpoints:"req"`
}
type Pong struct {
Ttl int `endpoints: "d=20"`
}
type PingService struct{}
func (svc *PingService) Ping(r *http.Request, ping *Ping, pong *Pong) error {
pong.Ttl = ping.Ttl
return nil
}
func init() {
pingService := &PingService{}
api, err := endpoints.RegisterService(pingService,
"ping", "v1", "Ping API", true)
if err != nil {
panic(err.Error())
}
info := api.MethodByName("Ping").Info()
info.Name, info.HTTPMethod, info.Path, info.Desc =
"Service.Ping", "GET", "ping", "Ping/Pong"
endpoints.HandleHTTP()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment