Documentation ¶
Index ¶
- Constants
- Variables
- func APIVersionMatcher(minAPIVersion, maxAPIVersion int) mux.MatcherFunc
- func CreateResponseFunc(fType reflect.Type, fVal reflect.Value) func(c JSONContext) (response Resp, err error)
- func DocHandle(router *mux.Router, f interface{}, path string, method string, ...)
- func DocHandler(templ *template.Template) http.Handler
- func Handle(c JSONContext, f func() (Resp, error), minAPIVersion, maxAPIVersion int, ...)
- func HandlerFunc(f func(c JSONContext) (Resp, error), minAPIVersion, maxAPIVersion int, ...) http.Handler
- func Remember(doc DocumentedRoute)
- type DefaultDocumentedRoute
- type DefaultJSONContext
- func (self *DefaultJSONContext) APIVersion() int
- func (self *DefaultJSONContext) CopyJSON(in, out interface{}) (err error)
- func (self *DefaultJSONContext) DecodeJSON(i interface{}) (err error)
- func (self *DefaultJSONContext) DecodedBody() []byte
- func (self *DefaultJSONContext) LoadJSON(out interface{}) (err error)
- func (self *DefaultJSONContext) MarshalJSON(c interface{}, body interface{}, arg interface{}) (result []byte, err error)
- type DocumentedRoute
- type DocumentedRoutes
- type JSONContext
- type JSONError
- type JSONType
- type Resp
- type ValidationError
- func (self *ValidationError) AddField(fieldName, message string, code int, cause error, status int) *ValidationError
- func (self ValidationError) Error() string
- func (self ValidationError) GetStack() string
- func (self ValidationError) GetStatus() int
- func (self ValidationError) Respond(c httpcontext.HTTPContext) error
Constants ¶
const ( APIVersionHeader = "X-API-Version" RespondMarshal = "respond" )
Variables ¶
var DefaultDocHandler http.Handler
var DefaultDocTemplate *template.Template
var DefaultDocTemplateContent = `` /* 1066-byte string literal not displayed */
var DefaultEndpointTemplateContent = `` /* 1400-byte string literal not displayed */
var DefaultTypeTemplateContent = `` /* 786-byte string literal not displayed */
Functions ¶
func APIVersionMatcher ¶
func APIVersionMatcher(minAPIVersion, maxAPIVersion int) mux.MatcherFunc
func CreateResponseFunc ¶
func CreateResponseFunc(fType reflect.Type, fVal reflect.Value) func(c JSONContext) (response Resp, err error)
CreateResponseFunc will take a function type and value, and return a handler function
func DocHandle ¶
func DocHandle(router *mux.Router, f interface{}, path string, method string, minAPIVersion, maxAPIVersion int, scopes ...string)
DocHandle will register f as handler for path, method, api versions and scopes in router.
It will also reflectively go through the parameters and return values of f, and register those in the DocumentedRoutes variable.
func DocHandler ¶
DocHandler will return a handler that renders the documentation for all routes registerd with DocHandle.
The resulting func will do this by going through each route in DocumentedRoutes and render the endpoint using the provided template, providing it template functions to render separate endpoints, types, sub types and examples of types.
func Handle ¶
func Handle(c JSONContext, f func() (Resp, error), minAPIVersion, maxAPIVersion int, scopes ...string)
func HandlerFunc ¶
func Remember ¶
func Remember(doc DocumentedRoute)
Remember will record the doc and make sure it shows up in the documentation.
Types ¶
type DefaultDocumentedRoute ¶
type DefaultDocumentedRoute struct { Methods []string Path string Scopes []string MinAPIVersion int MaxAPIVersion int In *JSONType Out *JSONType Comment string }
func Document ¶
func Document(fIn interface{}, path string, methods string, minAPIVersion, maxAPIVersion int, scopes ...string) (docRoute *DefaultDocumentedRoute, fOut func(JSONContext) (Resp, error))
Document will take a func, a path, a set of methods (separated by |) and a set of scopes that will be used when updating models in the func, and return a documented route and a function suitable for HandlerFunc.
The input func must match func(context JSONContext) (status int, err error)
One extra input argument after context is allowed, and will be JSON decoded from the request body, and used in the documentation struct.
One extra return value between status and error is allowed, and will be JSON encoded to the response body, and used in the documentation struct.
func (*DefaultDocumentedRoute) GetScopes ¶
func (self *DefaultDocumentedRoute) GetScopes() []string
func (*DefaultDocumentedRoute) GetSortString ¶
func (self *DefaultDocumentedRoute) GetSortString() string
type DefaultJSONContext ¶
type DefaultJSONContext struct { httpcontext.HTTPContext // contains filtered or unexported fields }
func NewJSONContext ¶
func NewJSONContext(c httpcontext.HTTPContext) (result *DefaultJSONContext)
func (*DefaultJSONContext) APIVersion ¶
func (self *DefaultJSONContext) APIVersion() int
func (*DefaultJSONContext) CopyJSON ¶
func (self *DefaultJSONContext) CopyJSON(in, out interface{}) (err error)
func (*DefaultJSONContext) DecodeJSON ¶
func (self *DefaultJSONContext) DecodeJSON(i interface{}) (err error)
func (*DefaultJSONContext) DecodedBody ¶
func (self *DefaultJSONContext) DecodedBody() []byte
func (*DefaultJSONContext) LoadJSON ¶
func (self *DefaultJSONContext) LoadJSON(out interface{}) (err error)
func (*DefaultJSONContext) MarshalJSON ¶
func (self *DefaultJSONContext) MarshalJSON(c interface{}, body interface{}, arg interface{}) (result []byte, err error)
MarshalJSON will recursively run any found `BeforeMarshal` functions on the content with arg and a stack of container instances, and then json marshal it.
It will not recurse down further after a BeforeMarshal function has been found, but it will run all top level BeforeMarshal functions that it finds.
type DocumentedRoute ¶
type DocumentedRoutes ¶
type DocumentedRoutes []DocumentedRoute
func (DocumentedRoutes) Len ¶
func (a DocumentedRoutes) Len() int
func (DocumentedRoutes) Less ¶
func (a DocumentedRoutes) Less(i, j int) bool
func (DocumentedRoutes) Swap ¶
func (a DocumentedRoutes) Swap(i, j int)
type JSONContext ¶
type JSONContext interface { httpcontext.HTTPContext APIVersion() int DecodeJSON(i interface{}) error DecodedBody() []byte LoadJSON(i interface{}) error CopyJSON(in, out interface{}) error MarshalJSON(subContext interface{}, body interface{}, reason interface{}) ([]byte, error) }
type JSONError ¶
type JSONError struct {
httpcontext.HTTPError
}
func (JSONError) Respond ¶
func (self JSONError) Respond(c httpcontext.HTTPContext) (err error)
type JSONType ¶
type JSONType struct { In bool ReflectType reflect.Type Type string Fields map[string]*JSONType Scopes []string Elem *JSONType Comment string }
JSONType handles the rendering of input and output types in the generated documentation
type Resp ¶
type Resp struct { Status int Body interface{} }
func (Resp) Respond ¶
func (self Resp) Respond(c httpcontext.HTTPContext) (err error)
type ValidationError ¶
type ValidationError struct { Status int Cause error Info string Fields map[string]field `json:"fields,omitempty"` }
func (*ValidationError) AddField ¶
func (self *ValidationError) AddField(fieldName, message string, code int, cause error, status int) *ValidationError
func (ValidationError) Error ¶
func (self ValidationError) Error() string
func (ValidationError) GetStack ¶
func (self ValidationError) GetStack() string
func (ValidationError) GetStatus ¶
func (self ValidationError) GetStatus() int
func (ValidationError) Respond ¶
func (self ValidationError) Respond(c httpcontext.HTTPContext) error