Documentation ¶
Index ¶
- Constants
- func BuildNumber() int64
- func MarshallPayloadWrapper(pw *PayloadWrapper) ([]byte, error)
- func Start(routerPtr *Router, host string) error
- func ValidateEntityName(name string) (isValid bool, reason string)
- func ValidateHandlerName(handler interface{}) (isValid bool, reason string)
- func Version() string
- type AuthHandler
- type CommonLogger
- type Context
- func (ctx *Context) AddResponseHeader(key, value string)
- func (ctx *Context) DecodeResponseBodyOrSendError(pc PayloadController, payloadReference interface{}) interface{}
- func (ctx *Context) DeleteResponseHeader(key string)
- func (ctx *Context) GetResponseHeader(key string) string
- func (ctx *Context) MakeRouteHandlerResultAlert(code int, errNo int64, alert string) RouteHandlerResult
- func (ctx *Context) MakeRouteHandlerResultCustom(crr CustomRouteResponse) RouteHandlerResult
- func (ctx *Context) MakeRouteHandlerResultDebugError(code int, errNo int64, errMsg string, debugNo int64, debugMsg string) RouteHandlerResult
- func (ctx *Context) MakeRouteHandlerResultError(code int, errNo int64, errMsg string) RouteHandlerResult
- func (ctx *Context) MakeRouteHandlerResultErrorInfo(code int, errInfo ErrorInfo) RouteHandlerResult
- func (ctx *Context) MakeRouteHandlerResultGenericJSON(v interface{}) RouteHandlerResult
- func (ctx *Context) MakeRouteHandlerResultNotFound(errNo int64) RouteHandlerResult
- func (ctx *Context) MakeRouteHandlerResultOk() RouteHandlerResult
- func (ctx *Context) MakeRouteHandlerResultPayloads(payloads ...Payload) RouteHandlerResult
- func (ctx *Context) MakeRouteHandlerResultRawBytes(statusCode int, rawBytes []byte, contentType string) RouteHandlerResult
- func (ctx *Context) MakeRouteHandlerResultStatusGenericJSON(statusCode int, v interface{}) RouteHandlerResult
- func (ctx *Context) RequestBody() ([]byte, error)
- func (ctx *Context) SendErrorInfoPayload(code int, errInfo ErrorInfo)
- func (ctx *Context) SendSimpleAlertPayload(code int, errNo int64, errMsg, alert string)
- func (ctx *Context) SendSimpleErrorPayload(code int, errNo int64, errorMsg string)
- func (ctx *Context) SetResponseHeader(key, value string)
- func (ctx *Context) WrapAndSendPayload(payload Payload)
- func (ctx *Context) WrapAndSendPayloadsList(payloadList []Payload)
- func (ctx *Context) WrapAndSendPayloadsMap(payloads PayloadsMap)
- type CustomRouteResponse
- type Endpoint
- type ErrorInfo
- type MiddlewareProcessor
- type Payload
- type PayloadController
- type PayloadWrapper
- type PayloadsMap
- type PostProcessor
- type PreProcessor
- type Route
- type RouteError
- type RouteHandler
- type RouteHandlerResult
- type Router
- func (router *Router) AddEntityRoute(entityName, controllerName, handlerName string, unknownhandler interface{}, ...)
- func (router *Router) AllRoutesCount() int
- func (router *Router) AllRoutesDescription(addons ...string) []string
- func (router *Router) AllRoutesSummary(addons ...string) string
- func (router *Router) LogAllRoutes(addons ...string)
- func (router *Router) RegisterEntity(name string, payloadController PayloadController)
- func (router *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)
- type VersionUint
Constants ¶
const ( HttpHeaderContentType = "Content-Type" HttpHeaderContentTypeJSON = "application/json" )
const ( MAGIC_AUTH_REQUIRED_PREFIX = "Auth" MAGIC_HANDLER_KEYWORD = "Handler" MAGIC_GET_HANDLER_PREFIX = "GetHandler" // CRUD: read MAGIC_POST_HANDLER_PREFIX = "PostHandler" // CRUD: create MAGIC_PUT_HANDLER_PREFIX = "PutHandler" // CRUD: update (the whole thing) MAGIC_PATCH_HANDLER_PREFIX = "PatchHandler" // CRUD: update (just a field or two) MAGIC_DELETE_HANDLER_PREFIX = "DeleteHandler" // CRUD: delete (duh) MAGIC_HEAD_HANDLER_PREFIX = "HeadHandler" // usually when you just want to check Etags or something. )
const ( NotFoundPrefix = "404 Not Found" NotFoundErrorNumber = 4040000404 BadRequestPrefix = "400 Bad Request" BadRequestErrorNumber = 4000000000 BadRequestSyntaxErrorPrefix = BadRequestPrefix + ": Syntax Error" BadRequestSyntaxErrorErrorNumber = 4000000001 BadRequestMissingPrimaryKeyErrorNumber = 4000000002 BadRequestExtraneousPrimaryKeyErrorNumber = 4000000003 InternalServerErrorPrefix = "500 Internal Server Error" )
const ROUTE_MAP_SEPARATOR = "-{&|!?}-"
RouteMap helpers
const VERSION_BIT_DEPTH = 16
Variables ¶
This section is empty.
Functions ¶
func BuildNumber ¶
func BuildNumber() int64
func MarshallPayloadWrapper ¶
func MarshallPayloadWrapper(pw *PayloadWrapper) ([]byte, error)
func ValidateEntityName ¶
func ValidateHandlerName ¶
Types ¶
type AuthHandler ¶
type CommonLogger ¶
type CommonLogger struct { }
type Context ¶
type Context struct { Req *http.Request // original http request Endpoint Endpoint // parsed endpoint information StatusCode int // The http status code written out. Only populated after a write. ContentLength int // The number of bytes written out. Only populated after a write. AuthInfo map[string]interface{} // a k/v store of any info about the user which was gleaned during authentication // contains filtered or unexported fields }
func (*Context) AddResponseHeader ¶
func (*Context) DecodeResponseBodyOrSendError ¶
func (ctx *Context) DecodeResponseBodyOrSendError(pc PayloadController, payloadReference interface{}) interface{}
func (*Context) DeleteResponseHeader ¶
func (*Context) GetResponseHeader ¶
func (*Context) MakeRouteHandlerResultAlert ¶
func (ctx *Context) MakeRouteHandlerResultAlert(code int, errNo int64, alert string) RouteHandlerResult
func (*Context) MakeRouteHandlerResultCustom ¶
func (ctx *Context) MakeRouteHandlerResultCustom(crr CustomRouteResponse) RouteHandlerResult
func (*Context) MakeRouteHandlerResultDebugError ¶
func (*Context) MakeRouteHandlerResultError ¶
func (ctx *Context) MakeRouteHandlerResultError(code int, errNo int64, errMsg string) RouteHandlerResult
func (*Context) MakeRouteHandlerResultErrorInfo ¶
func (ctx *Context) MakeRouteHandlerResultErrorInfo(code int, errInfo ErrorInfo) RouteHandlerResult
func (*Context) MakeRouteHandlerResultGenericJSON ¶
func (ctx *Context) MakeRouteHandlerResultGenericJSON(v interface{}) RouteHandlerResult
func (*Context) MakeRouteHandlerResultNotFound ¶
func (ctx *Context) MakeRouteHandlerResultNotFound(errNo int64) RouteHandlerResult
func (*Context) MakeRouteHandlerResultOk ¶
func (ctx *Context) MakeRouteHandlerResultOk() RouteHandlerResult
func (*Context) MakeRouteHandlerResultPayloads ¶
func (ctx *Context) MakeRouteHandlerResultPayloads(payloads ...Payload) RouteHandlerResult
func (*Context) MakeRouteHandlerResultRawBytes ¶
func (ctx *Context) MakeRouteHandlerResultRawBytes(statusCode int, rawBytes []byte, contentType string) RouteHandlerResult
func (*Context) MakeRouteHandlerResultStatusGenericJSON ¶
func (ctx *Context) MakeRouteHandlerResultStatusGenericJSON(statusCode int, v interface{}) RouteHandlerResult
func (*Context) RequestBody ¶
func (*Context) SendErrorInfoPayload ¶
func (*Context) SendSimpleAlertPayload ¶
Alert payloads are designed as a general notification service for clients (ie client must upgrade, server is in maint mode, etc.)
func (*Context) SendSimpleErrorPayload ¶
Error
func (*Context) SetResponseHeader ¶
func (*Context) WrapAndSendPayload ¶
func (*Context) WrapAndSendPayloadsList ¶
for a slice of Entities
func (*Context) WrapAndSendPayloadsMap ¶
func (ctx *Context) WrapAndSendPayloadsMap(payloads PayloadsMap)
for a map of slices of Entities
type CustomRouteResponse ¶
type CustomRouteResponse func(*Context)
type Endpoint ¶
type Endpoint struct { VersionStr string EntityName string PrimaryKey string Action string Components []string Extras []string // contains filtered or unexported fields }
convenience struct holding all the stuff you usually want to know about an endpoint
func ParsePathForTesting ¶
exported for other packages to be able to unit test.
func (*Endpoint) Version ¶
func (e *Endpoint) Version() VersionUint
return a typed number, not a string cache value so we only do this once.
type ErrorInfo ¶
type ErrorInfo struct { ErrorNumber int64 `json:"errorNumber,omitempty"` // will be 0 on successful responses, non-zero otherwise ErrorMessage string `json:"errorMessage,omitempty"` // end-user appropriate error message DebugNumber int64 `json:"debugNumber,omitempty"` // optional debug code DebugMessage string `json:"debugMessage,omitempty"` // optional debug message }
type MiddlewareProcessor ¶
type Payload ¶
type Payload interface {
PayloadType() string
}
If a payload implements this method, then the wrapper will autopopulate the PayloadType field
type PayloadController ¶
type PayloadController interface { }
type PayloadWrapper ¶
type PayloadWrapper struct { Payloads PayloadsMap `json:",omitempty"` // key is type, value is list of payloads of that type ErrorInfo Alert string `json:",omitempty"` // used when the client end user needs to be alerted of something: (eg, maintenance mode, downtime, sercurity, required update, etc.) }
This will typically be serialized into a JSON formatted string
func NewPayloadWrapper ¶
func NewPayloadWrapper(payloadsList ...Payload) *PayloadWrapper
func UnmarshalPayloadWrapper ¶
func UnmarshalPayloadWrapper(jsonBytes []byte, supportedPayloads ...Payload) (*PayloadWrapper, error)
type PayloadsMap ¶
ALWAYS a map of array of objects. key is type, value is list of payloads of that type Typically, these are arrays of objects designed to be deserialized into entity structs (eg []BookPayload, []AuthorPayload)
func MakePayloadMapFromPayloads ¶
func MakePayloadMapFromPayloads(payloadsList ...Payload) PayloadsMap
type PostProcessor ¶
type PreProcessor ¶
type Route ¶
type Route struct { RequiresAuth bool Authenticator AuthHandler Method string Path string VersionStr string EntityName string Action string Handler RouteHandler HandlerName string // not actually used except for logging and debugging ControllerName string // not actually used except for logging and debugging }
type RouteError ¶
type RouteError struct { ErrorLevel levels.ErrorLevel // contains filtered or unexported fields }
func NewRouteError ¶
func NewRouteError(code int, errInfo ErrorInfo) *RouteError
type RouteHandler ¶
type RouteHandler func(*Context) RouteHandlerResult
func ValidateHandler ¶
func ValidateHandler(unknownHandler interface{}) (isValid bool, reason string, handler RouteHandler)
type RouteHandlerResult ¶
type RouteHandlerResult struct {
// contains filtered or unexported fields
}
type Router ¶
type Router struct { BasePath string PreProcessors []PreProcessor MiddlewareProcessors []MiddlewareProcessor PostProcessors []PostProcessor Controllers map[string]PayloadController // key is entity name RouteMap map[string]*Route // key is entity name }
func (*Router) AddEntityRoute ¶
func (router *Router) AddEntityRoute(entityName, controllerName, handlerName string, unknownhandler interface{}, authenticator AuthHandler)
func (*Router) AllRoutesDescription ¶
Basically just used for logging and debugging. the first addon is a prefix, all remaining addons are treated as suffixes and appended to the end
func (*Router) AllRoutesSummary ¶
Basically just used for logging and debugging. the first addon is a prefix, all remaining addons are treated as suffixes and appended to the end
func (*Router) LogAllRoutes ¶
func (*Router) RegisterEntity ¶
func (router *Router) RegisterEntity(name string, payloadController PayloadController)
type VersionUint ¶
type VersionUint uint16