You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
crhym3 edited this page Apr 16, 2013
·
10 revisions
A possible way (just a thought for now) of registering a service and how the discovery doc would be inferred from it:
typeReqstruct {
Aint`endpoints:"path"`// implies "required"Bfloat64`endpoints:"required"`// does not imply "path"Cbool// default location is "query"Dstring`endpoints:"{hello|goodbye},path"`// regexp "pattern"
}
typeMyServicestruct {}
func (s*MyService) DoSomething(req*Req, resp*Resp) {
// ...
}
funcinit() {
s:=new(MyService)
// Will implicitly call// endpoints.RegisterService(s, "myservice", "v1", "My Service API", "description")// then register methods of s and create a discovery doc (REST+RPC) inferred from// their declarations.endpoints.RegisterServiceWithDefaults(s)
// I could also modify defaults for a specific methodmethod:=endpoints.MethodByName("MyService.DoSomething")
// or endpoints.Method(s.DoSomething)// Default was POST because not all fields of Req struct are in "path" location, // and not all fields have explicit location specified (either "path" or "query").// Otherwise, this would've been inferred as GET.method.SetHttpMethod("GET")
// Default was "do_something/{a}/{d}"// (inferred from the method name and Req struct fields)method.SetPath("/do/{a}/foo-bar/{d}")
// Serve discovery + REST and RPC registered service methods.http.Handle("/_ah/spi/", endpoints.HttpHandler)
// or endpoints.HandleHttp()
}