Documentation
¶
Index ¶
- Constants
- func Call(ctrlrFn func(*Context)) func(http.ResponseWriter, *http.Request)
- func Encrypt(ctx *Context)
- func GetGraphQLHandlerConfig() *graphQLHandler.Handler
- func HomePage(ctx *Context)
- func JSONTest(ctx *Context)
- func ServeServiceWorker(ctx *Context)
- func StaticRouter(router *mux.Router, options *StaticConfig) *mux.Route
- type Context
- func (ctx *Context) ErrorMessage(statusCode int, err error)
- func (ctx *Context) JSON(obj interface{}, configs ...*ResponseConfig)
- func (ctx *Context) Render(templateName string, data interface{}, configs ...*ResponseConfig)
- func (ctx *Context) Respond(config *ResponseConfig)
- func (ctx *Context) Send(str string, configs ...*ResponseConfig)
- type ResponseConfig
- type StaticConfig
Constants ¶
const (
// EncryptionKey - Key to use in the encryption algorithm
EncryptionKey = "98c36hby8iwnseho8qwy38ryuagnukdshxkvastcvw4"
)
Variables ¶
This section is empty.
Functions ¶
func Call ¶
func Call(ctrlrFn func(*Context)) func(http.ResponseWriter, *http.Request)
Call - Wrapper function for passing server context to controllers
params -- ctrlrFn {func(*Context)} The route controller
returns -- {func(http.ResponseWriter, *http.Request)}
func GetGraphQLHandlerConfig ¶
func GetGraphQLHandlerConfig() *graphQLHandler.Handler
GetGraphQLHandlerConfig - Getter for graphql handler configuration
func HomePage ¶
func HomePage(ctx *Context)
HomePage - homepage controller
params -- ctx {*Context} Server request context
func JSONTest ¶
func JSONTest(ctx *Context)
JSONTest - Send json test data to the client
params -- ctx {*Context}
func ServeServiceWorker ¶
func ServeServiceWorker(ctx *Context)
ServeServiceWorker - Serve the service worker js file
params -- ctx {*Context}
func StaticRouter ¶
func StaticRouter(router *mux.Router, options *StaticConfig) *mux.Route
StaticRouter - Static routing for serving files
params -- router {*mux.Router} mux Router instance -- options {*StaticConfig} Static file serving configuration
returns -- {*mux.Route} To extend the chain
Types ¶
type Context ¶
type Context struct {
Response http.ResponseWriter
Request *http.Request
Router *mux.Router
Params map[string]string
}
Context - The server context
fields -- res {http.ResponseWriter} -- req {*http.Request}
func (*Context) ErrorMessage ¶
ErrorMessage - Send an error message
params -- statusCode {int} The status code of the response error -- err {error} Error object
func (*Context) JSON ¶
func (ctx *Context) JSON(obj interface{}, configs ...*ResponseConfig)
JSON - Send some jsonn data to the client
params -- obj {interface{}} The json content as a struct -- config {*ResponseConfig} Optional config
func (*Context) Render ¶
func (ctx *Context) Render(templateName string, data interface{}, configs ...*ResponseConfig)
Render - Render a template and write to response
params -- templateName {string} Name of the template to render
func (*Context) Respond ¶
func (ctx *Context) Respond(config *ResponseConfig)
Respond to the request using the config
params -- config {*ResponseConfig}
func (*Context) Send ¶
func (ctx *Context) Send(str string, configs ...*ResponseConfig)
Send - Writes a string of html to response
params -- str {string} The string to send -- config {*ResponseConfig} Optional configuration
type ResponseConfig ¶
type ResponseConfig struct {
StatusCode int
Body string
ContentType string `default:"text/plain; charset=utf-8"`
ContentEncoding string
}
ResponseConfig - Craft a custom response
fields -- StatusCode {int} The status code of the response to send -- Body {string} Content i.e. response body -- ContentType {string} The mimetype of the data (default = gzip) -- ContentEncoding {string} Specify the content encoding
type StaticConfig ¶
type StaticConfig struct {
Pathprefix string
Directory string
Response *ResponseConfig
}
StaticConfig - Static file serving configuration
fields -- Pathprefix {string} The prefix for the url pathname for static content -- Directory {string} The static content root directory on the server