func HandlerFunc(f func(c JSONContextLogger) (Resp, error), minAPIVersion, maxAPIVersion int, scopes ...string) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { c := NewJSONContext(httpcontext.NewHTTPContext(w, r)) Handle(c, func() (Resp, error) { return f(c) }, minAPIVersion, maxAPIVersion, scopes...) }) }
/* DataHandlerFunc creates an http.Handler out of a function that takes an HTTPContext and returns a *httpcontext.DataResp. Requests without tokens, or with tokens without one of the provided scopes, will receive a 401 status unless the scopes slice is empty. For all your tabular data generation needs. */ func DataHandlerFunc(f func(c HTTPContext) (resp *httpcontext.DataResp, err error), scopes ...string) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { gaeCont := appengine.NewContext(r) c := NewHTTPContext(gaeCont, httpcontext.NewHTTPContext(w, r)) httpcontext.DataHandle(c, func() (*httpcontext.DataResp, error) { return f(c) }, scopes...) }) }
/* JSONHandlerFunc creates an http.Handler out of a function that takes a JSONContext. Requests without tokens, or with tokens without one of the provided scopes, will receive a 401 status unless the scopes slice is empty. For all your JSON API needs. */ func JSONHandlerFunc(f func(c JSONContext) (resp jsoncontext.Resp, err error), minAPIVersion, maxAPIVersion int, scopes ...string) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { gaeCont := appengine.NewContext(r) c := NewJSONContext(gaeCont, jsoncontext.NewJSONContext(httpcontext.NewHTTPContext(w, r))) jsoncontext.Handle(c, func() (jsoncontext.Resp, error) { return f(c) }, minAPIVersion, maxAPIVersion, scopes...) }) }
/* DocHandle registeres a path/method/api version route in the provided router, handled by the provided f, wrapping it in appstats.NewHandler, registering the f-function and its route with jsoncontext.Document and then using jsoncontext.Handle to do something that acts like JSONHandlerFunc. */ func DocHandle(router *mux.Router, f interface{}, path string, method string, minAPIVersion, maxAPIVersion int, scopes ...string) { doc, fu := jsoncontext.Document(f, path, method, minAPIVersion, maxAPIVersion, scopes...) jsoncontext.Remember(doc) router.Path(path).Methods(method).Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { gaeCont := appengine.NewContext(r) c := NewJSONContext(gaeCont, jsoncontext.NewJSONContext(httpcontext.NewHTTPContext(w, r))) jsoncontext.Handle(c, func() (resp jsoncontext.Resp, err error) { return fu(c) }, minAPIVersion, maxAPIVersion, scopes...) })) }