request

package
v0.0.0-...-86833b7 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2023 License: MIT Imports: 16 Imported by: 4

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 DispatchNext

func DispatchNext(context *Context, name string, writer http.ResponseWriter, request *http.Request, parameter router.Parameter, registry *container.Registry, handlers []Handler) error

DispatchNext entry point

Types

type Context

type Context struct {
	Name     string              // The name associated with the route
	Registry *container.Registry // 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 Registry passed by the router
	// contains filtered or unexported fields
}

Context holds context information about the incoming request

func GetContext

func GetContext(cdi *container.Registry) *Context

GetContext gets a Context from the Registry context

func (*Context) BindForm

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

BindForm decodes request post data into target

func (*Context) BindGetForm

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

BindGetForm decodes the request url values into target

func (*Context) BindJSON

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

BindJSON decodes request body as json into the target

func (*Context) Context

func (c *Context) Context() context.Context

func (*Context) GetBodyBytes

func (c *Context) GetBodyBytes() ([]byte, error)

func (*Context) GetBodyReader

func (c *Context) GetBodyReader() io.ReadCloser

GetBodyReader returns bytes bodyReader

func (*Context) GetCookieValue

func (c *Context) GetCookieValue(name string) (value string)

GetCookieValue returns a cookie value from the request

func (*Context) GetGetValue

func (c *Context) GetGetValue(name string) string

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

func (*Context) GetPostValue

func (c *Context) GetPostValue(name string) string

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

func (*Context) GetURLParameter

func (c *Context) GetURLParameter(name string) string

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

func (*Context) Next

func (c *Context) Next() error

Next will continue with the request flow

func (*Context) Printf

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

Printf prints a formatted text to response writer

func (*Context) Redirect

func (c *Context) Redirect(urlStr string)

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

func (*Context) RedirectStatus

func (c *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) WriteString

func (c *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.Registry and invoke DispatchNext which will invoke the next handler, the last handler is responsible for the main logic of the request. calling DispatchNext 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