Documentation ¶
Overview ¶
Web App Helper functions.
Index ¶
- Constants
- func Form2M(values url.Values) map[string]interface{}
- func ValidateInt(value, min, max int) error
- func ValidateString(value string, minlength, maxlength int) error
- func WebappHandlerFunc(f func(*Context)) func(interface{})
- func WriteJson(w http.ResponseWriter, model interface{}) error
- func WriteString(w http.ResponseWriter, format string, data ...interface{})
- type Context
- func (this *Context) App() *Webapp
- func (this *Context) Auhtenticate() bool
- func (this *Context) BindForm(model interface{})
- func (this *Context) BindJson(model interface{})
- func (this *Context) DB() *mgo.Database
- func (this *Context) Error(errormessage string, code int)
- func (this *Context) File(filePath string)
- func (this *Context) Form() url.Values
- func (this *Context) Get(name string) interface{}
- func (this *Context) GetAll() map[string]interface{}
- func (this *Context) Http() (ResponseWriter, *http.Request)
- func (this *Context) Json(model interface{})
- func (this *Context) PostForm() url.Values
- func (this *Context) Redirect(path string)
- func (this *Context) ResponseWriter() ResponseWriter
- func (this *Context) Set(name string, value interface{})
- func (this *Context) View(view string, model interface{})
- func (this *Context) ViewString(format string, data ...interface{})
- type Handler
- type HandlerFunc
- type Html
- type JadeRenderer
- type Logger
- type MiddlewareHandler
- type MiddlewareHandlerFunc
- type MuxHandlerAdapter
- type Recovery
- type Renderer
- type ResponseWriter
- type RouterContext
- type Session
- type User
- type UserManager
- type ViewModel
- type Webapp
- func (this *Webapp) FileServer(path_prefix string, file_path string)
- func (this *Webapp) Get(path string, f func(*Context)) *mux.Route
- func (this *Webapp) Handle(path string, handler Handler) *mux.Route
- func (this *Webapp) HandleFunc(path string, f func(*Context)) *mux.Route
- func (n *Webapp) Handlers() []MiddlewareHandler
- func (this *Webapp) NewRoute(f func(*Context)) *mux.Route
- func (this *Webapp) Post(path string, f func(*Context)) *mux.Route
- func (this *Webapp) Run(addr string)
- func (n *Webapp) ServeHTTP(rw http.ResponseWriter, r *http.Request)
- func (n *Webapp) ServeHTTPContext(c *Context)
- func (this *Webapp) SubRoute(path string) *Webapp
- func (n *Webapp) Use(handler MiddlewareHandler)
- func (n *Webapp) UseFunc(handlerFunc func(c *Context, next HandlerFunc))
- func (n *Webapp) UseHandler(handler Handler)
- func (n *Webapp) UseHandlerFunc(handlerFunc func(c *Context))
Constants ¶
const ( KeySessionId = "SessionId" KeyDatabaseObject = "DatabaseObject" KeyUser = "User" )
Variables ¶
This section is empty.
Functions ¶
func ValidateInt ¶
func ValidateString ¶
func WebappHandlerFunc ¶
func WebappHandlerFunc(f func(*Context)) func(interface{})
WebappHandler Wrap a mux handler and calls a webapp handler
func WriteJson ¶
func WriteJson(w http.ResponseWriter, model interface{}) error
func WriteString ¶
func WriteString(w http.ResponseWriter, format string, data ...interface{})
Types ¶
type Context ¶
type Context struct { *mux.HandlerContext Session Session SessionId string User UserManager // contains filtered or unexported fields }
func NewContext ¶
func (*Context) Auhtenticate ¶
func (*Context) BindForm ¶
func (this *Context) BindForm(model interface{})
BindForms binds a go structure to a html form Uses gorilla.schema
func (*Context) DB ¶
func (this *Context) DB() *mgo.Database
DB get a mgo.Database instance for a mongo database. This function can be modified to return your database instance. The MongoDB Middleware must be used for this function to work.
func (*Context) Json ¶
func (this *Context) Json(model interface{})
View Render a template to html. By default gojade rendering engine is used, this can be customized.
func (*Context) ResponseWriter ¶
func (this *Context) ResponseWriter() ResponseWriter
func (*Context) View ¶
View Render a template to html. By default gojade rendering engine is used, this can be customized.
func (*Context) ViewString ¶
Return a String to the client.
type HandlerFunc ¶
type HandlerFunc func(c *Context)
func (HandlerFunc) ServeHTTP ¶
func (h HandlerFunc) ServeHTTP(c *Context)
type JadeRenderer ¶
type JadeRenderer struct {
// contains filtered or unexported fields
}
func NewJadeRender ¶
func NewJadeRender(viewpath string) *JadeRenderer
func (*JadeRenderer) Render ¶
func (this *JadeRenderer) Render(c *Context, view string, model interface{})
type Logger ¶
type Logger struct { // Logger inherits from log.Logger used to log messages with the Logger middleware *log.Logger }
Logger is a middleware handler that logs the request as it goes in and the response as it goes out.
func (*Logger) ServeHTTP ¶
func (l *Logger) ServeHTTP(c *Context, next HandlerFunc)
type MiddlewareHandler ¶
type MiddlewareHandler interface { //ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) ServeHTTP(c *Context, next HandlerFunc) }
Handler handler is an interface that objects can implement to be registered to serve as middleware in the Negroni middleware stack. ServeHTTP should yield to the next middleware in the chain by invoking the next http.HandlerFunc passed in.
If the Handler writes to the ResponseWriter, the next http.HandlerFunc should not be invoked.
func Wrap ¶
func Wrap(handler Handler) MiddlewareHandler
Wrap converts a http.Handler into a negroni.Handler so it can be used as a Negroni middleware. The next http.HandlerFunc is automatically called after the Handler is executed.
type MiddlewareHandlerFunc ¶
type MiddlewareHandlerFunc func(c *Context, next HandlerFunc)
HandlerFunc is an adapter to allow the use of ordinary functions as Negroni handlers. If f is a function with the appropriate signature, HandlerFunc(f) is a Handler object that calls f. type HandlerFunc func(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc)
func (MiddlewareHandlerFunc) ServeHTTP ¶
func (h MiddlewareHandlerFunc) ServeHTTP(c *Context, next HandlerFunc)
type MuxHandlerAdapter ¶
type MuxHandlerAdapter struct {
// contains filtered or unexported fields
}
func NewMuxHandlerAdapter ¶
func NewMuxHandlerAdapter(handler Handler) *MuxHandlerAdapter
func (*MuxHandlerAdapter) ServeHTTP ¶
func (this *MuxHandlerAdapter) ServeHTTP(c interface{})
type Recovery ¶
Recovery is a Negroni middleware that recovers from any panics and writes a 500 if there was one.
func (*Recovery) ServeHTTP ¶
func (rec *Recovery) ServeHTTP(c *Context, next HandlerFunc)
type ResponseWriter ¶
type ResponseWriter interface { http.ResponseWriter http.Flusher // Status returns the status code of the response or 0 if the response has not been written. Status() int // Written returns whether or not the ResponseWriter has been written. Written() bool // Size returns the size of the response body. Size() int // Before allows for a function to be called before the ResponseWriter has been written to. This is // useful for setting headers or any other operations that must happen before a response has been written. Before(func(ResponseWriter)) }
ResponseWriter is a wrapper around http.ResponseWriter that provides extra information about the response. It is recommended that middleware handlers use this construct to wrap a responsewriter if the functionality calls for it.
func NewResponseWriter ¶
func NewResponseWriter(rw http.ResponseWriter) ResponseWriter
NewResponseWriter creates a ResponseWriter that wraps an http.ResponseWriter
type RouterContext ¶
RouterContext Wrap mux.Router to support ServeHTTP(*Context)
func NewRouterBase ¶
func NewRouterBase(router *mux.Router) *RouterContext
NewRouter Create a new mux router adapter
func (*RouterContext) ServeHTTP ¶
func (this *RouterContext) ServeHTTP(c *Context)
Wrapped ServeHttp
type Session ¶
type Session interface { SessionId() string Get(string) interface{} Set(string, interface{}) Session GetAll() map[string]interface{} }
Session
type UserManager ¶
type UserManager interface { Login(username string, password string) (bool, error) Logout() Authenticated() bool UserId() string UserName() string Info() *User }
User
type ViewModel ¶
type ViewModel struct { Model interface{} User UserManager Html *Html }
type Webapp ¶
type Webapp struct { RenderEngine Renderer // contains filtered or unexported fields }
Negroni is a stack of Middleware Handlers that can be invoked as an http.Handler. Negroni middleware is evaluated in the order that they are added to the stack using the Use and UseHandler methods.
func Classic ¶
func Classic() *Webapp
Classic returns a new Negroni instance with the default middleware already in the stack.
Recovery - Panic Recovery Middleware Logger - Request/Response Logging
func New ¶
func New(handlers ...MiddlewareHandler) *Webapp
New returns a new Negroni instance with no middleware preconfigured.
func (*Webapp) FileServer ¶
func (*Webapp) HandleFunc ¶
func (*Webapp) Handlers ¶
func (n *Webapp) Handlers() []MiddlewareHandler
Returns a list of all the handlers in the current Negroni middleware chain.
func (*Webapp) Run ¶
Run is a convenience function that runs the negroni stack as an HTTP server. The addr string takes the same format as http.ListenAndServe.
func (*Webapp) ServeHTTPContext ¶
func (*Webapp) Use ¶
func (n *Webapp) Use(handler MiddlewareHandler)
Use adds a Handler onto the middleware stack. Handlers are invoked in the order they are added to a Negroni.
func (*Webapp) UseFunc ¶
func (n *Webapp) UseFunc(handlerFunc func(c *Context, next HandlerFunc))
UseFunc adds a Negroni-style handler function onto the middleware stack.
func (*Webapp) UseHandler ¶
UseHandler adds a http.Handler onto the middleware stack. Handlers are invoked in the order they are added to a Negroni.
func (*Webapp) UseHandlerFunc ¶
UseHandler adds a http.HandlerFunc-style handler function onto the middleware stack.