Documentation
¶
Index ¶
- Constants
- func BuildNumber() int64
- func MarshallPayloadWrapper(pw *PayloadWrapper) ([]byte, error)
- func SimpleEmailValidation(email string) bool
- func SimplePasswordValidation(pw string) bool
- func StandardDeleteHandler(ctx *Context, controller DeletePerformer)
- 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 Account
- type AccountStore
- type AuthHandler
- type CommonLogger
- type Context
- func (ctx *Context) AddHeader(key, value string)
- func (ctx *Context) DecodeResponseBodyOrSendError(pc PayloadController, payloadReference interface{}) interface{}
- func (ctx *Context) DelHeader(key string)
- func (ctx *Context) GetHeader(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) 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) SetHeader(key, value string)
- func (ctx *Context) WrapAndSendPayload(payload Payload)
- func (ctx *Context) WrapAndSendPayloadsList(payloadList []Payload)
- func (ctx *Context) WrapAndSendPayloadsMap(payloads PayloadsMap)
- type CreatePerformer
- type CustomRouteResponse
- type DeletePerformer
- type DeleteValidator
- type Endpoint
- type ErrorInfo
- type MaybeAccount
- type MiddlewareProcessor
- type Payload
- type PayloadController
- type PayloadWrapper
- type PayloadsMap
- type PostProcessor
- 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 UpdatePerformer
- type VersionUint
Constants ¶
const ( MAX_EMAIL_LENGTH = 256 MAX_PASSWORD_LENGTH = 1024 )
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 SimpleEmailValidation ¶
Yes this could be better... good enough for now.
func StandardDeleteHandler ¶
func StandardDeleteHandler(ctx *Context, controller DeletePerformer)
func ValidateEntityName ¶
func ValidateHandlerName ¶
Types ¶
type Account ¶
type Account struct {
// System fields
PKey int64 `meddler:"pkey,pk"`
// User fields
Name string `meddler:"name"`
Email string `meddler:"email"`
Passhash []byte `meddler:"passhash"`
PublicKey string `meddler:"publickey"`
SecretKey string `meddler:"secretkey"`
// Times
Created time.Time `meddler:"created,utctimez"`
Modified time.Time `meddler:"modified,utctimez"`
LastLogin time.Time `meddler:"lastlogin,utctimez"`
}
type AccountStore ¶
type AccountStore interface {
// Common startup, shutdown, utility methods
Startup(attribs string) error
Shutdown() error
// CREATE
// returns created account's accountid
CreateAccount(name, email, password string) (*Account, error)
// DELETE
// returns true when pkey is valid account is successfully removed. if no account with pkey, returns false
// returns non-nil err on failure to execute
DeleteAccount(pkey int64) (bool, error)
// QUERY
AllAccounts() ([]*Account, error)
AccountWithId(pkey int64) (MaybeAccount, error)
AccountWithEmail(q string) (MaybeAccount, error)
AccountWithPublicKey(q string) (MaybeAccount, error)
EmailAddressAvailable(email string) (bool, *deeperror.DeepError)
// UPDATE
ChangeUserEmail(pkey int64, newEmail string) error
ChangeUserPassword(pkey int64, newPassword string) error
UpdateUserLastLogin(pkey int64) (MaybeAccount, error)
// AUTH
Login(submittedEmail, submittedPassword string) (*Account, error)
}
type AuthHandler ¶
type CommonLogger ¶
type CommonLogger struct {
}
type Context ¶
type Context struct {
Req *http.Request // original http request
End Endpoint // parsed endpoint information
// only populated after auth
PublicKey string // for Auth'd requests, will be set to public key if Auth was successful, "" otherwise
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.
// contains filtered or unexported fields
}
func (*Context) DecodeResponseBodyOrSendError ¶
func (ctx *Context) DecodeResponseBodyOrSendError(pc PayloadController, payloadReference interface{}) interface{}
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) 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) 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 CreatePerformer ¶
type CustomRouteResponse ¶
type CustomRouteResponse func(*Context)
type DeletePerformer ¶
type DeleteValidator ¶
type Endpoint ¶
type Endpoint struct {
VersionStr string
EntityName string
PrimaryKey int64
Action 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 MaybeAccount ¶
type MaybeAccount struct {
// contains filtered or unexported fields
}
func MakeMaybeAccount ¶
func MakeMaybeAccount(acct *Account) MaybeAccount
func (MaybeAccount) AccountOrCrash ¶
func (ma MaybeAccount) AccountOrCrash(optionalErrNum int64) *Account
func (MaybeAccount) HasValidAccountPointer ¶
func (ma MaybeAccount) HasValidAccountPointer() bool
func (MaybeAccount) IsNil ¶
func (ma MaybeAccount) IsNil() bool
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 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 {
// 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
}
func StandardCreateHandler ¶
func StandardCreateHandler(controller CreatePerformer, ctx *Context, createRequestPayload Payload) RouteHandlerResult
func StandardUpdateHandler ¶
func StandardUpdateHandler(controller UpdatePerformer, ctx *Context, updateRequestPayload Payload) RouteHandlerResult
type Router ¶
type Router struct {
BasePath string
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 UpdatePerformer ¶
type VersionUint ¶
type VersionUint uint16