request

package
v0.0.0-...-3be023f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 27, 2017 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package formam implements functions to decode values of a html form.

Index

Constants

View Source
const TAG_NAME = "formam"

Variables

View Source
var ContextType = reflect.TypeOf((*Context)(nil))

Functions

func Advance

func Advance(c *Context, name string, w http.ResponseWriter, r *http.Request, p router.Parameter, v *container.IoC, h []Handler)

Advance entry point

Types

type Context

type Context struct {
	Name    string         // The name associated with the route
	IoC     *container.IoC // Dependency injection context
	Request *http.Request  // Request data passed by the router
	Gen     *common.URLGen

	Response   http.ResponseWriter // Response Writer passed by the router
	Parameters router.Parameter    // Route Variables passed by the router
	// contains filtered or unexported fields
}

Context holds context information about the incoming request

func GetContext

func GetContext(cdi *container.IoC) *Context

GetContext get's a Context from the Global context

func (*Context) Advance

func (ctx *Context) Advance() error

Advance will continue with the request flow

func (*Context) BindForm

func (ctx *Context) BindForm(target interface{}) error

BindForm decodes request post data into target

func (*Context) BindGetForm

func (ctx *Context) BindGetForm(target interface{}) error

BindGetForm decodes the request url values into target

func (*Context) BindJSON

func (ctx *Context) BindJSON(target interface{}) error

BindJSON decodes request body as json into the target

func (*Context) CookieByName

func (ctx *Context) CookieByName(name string) (value string)

CookieByName returns a cookie value from the request

func (*Context) FormByName

func (ctx *Context) FormByName(name string) string

FormByName returns a form value from the request, FormByName is shortcut for Context.Request.Form.Get method

func (*Context) ParamByName

func (ctx *Context) ParamByName(name string) string

ParamByName returns a parameter from the url route, ParamByName is shortcut for Context.Parameters.ByName method

func (*Context) Printf

func (ctx *Context) Printf(format string, v ...interface{}) (int, error)

Printf prints a formatted text to response writer

func (*Context) Redirect

func (ctx *Context) Redirect(urlStr string)

Redirect redirects the request to the specified urlStr and send a http StatusFound code

func (*Context) RedirectStatus

func (ctx *Context) RedirectStatus(urlStr string, httpStatus int)

RedirectStatus redirects the request to the specified urlStr and send the the status code specified by httpStatus

func (*Context) URLFormByName

func (ctx *Context) URLFormByName(name string) string

URLFormByName returns a form value from the request, FormByName is shortcut for Context.Request.Form.Get method

func (*Context) WriteString

func (ctx *Context) WriteString(txt string) (int, error)

WriteString writes the string txt into the the response

type Handler

type Handler interface {
	Handle(*Context)
}

Handler is responsible to handle the request or part of the request, ex: a middleware handler would process some data put the data into the scope.Variables and invoke Advance which will invoke the next handler, the last handler is responsible for the main logic of the request. calling Advance in the last handler will panic.

type HandlerFunc

type HandlerFunc func(*Context)

HandlerFunc func implementing Handler interface

func (HandlerFunc) Handle

func (fn HandlerFunc) Handle(c *Context)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL