Documentation
¶
Overview ¶
Package formam implements functions to decode values of a html form.
Index ¶
- Constants
- Variables
- func DispatchNext(context *Context, name string, writer http.ResponseWriter, ...) error
- func Env(def, key string, fallbacks ...string) string
- func GetEnv(key string, fallbacks ...string) (value string)
- func LookupEnv(Key string, fallbacks ...string) (value string, found bool)
- type Component
- type ComponentBundle
- type ComponentFunc
- type Context
- func (c *Context) BindForm(target interface{}) error
- func (c *Context) BindGetForm(target interface{}) error
- func (c *Context) BindJSON(target interface{}) error
- func (c *Context) GetBodyBytes() ([]byte, error)
- func (c *Context) GetBodyReader() io.ReadCloser
- func (c *Context) GetCookieValue(name string) (value string)
- func (c *Context) GetGetValue(name string) string
- func (c *Context) GetPostValue(name string) string
- func (c *Context) GetURLParameter(name string) string
- func (c *Context) GoContext() context.Context
- func (c *Context) Next() error
- func (c *Context) Printf(format string, v ...interface{}) (int, error)
- func (c *Context) Redirect(urlStr string)
- func (c *Context) RedirectStatus(urlStr string, httpStatus int)
- func (c *Context) SendJSON(v any) error
- func (c *Context) SendJSONWithStatus(v any, statusCode int) error
- func (c *Context) SendTextWithStatus(statusCode int, content string) error
- func (c *Context) WriteString(txt string) (int, error)
- type Controller
- type ControllerBundle
- type ControllerURLGen
- type Handler
- type HandlerFunc
- type Kernel
- func (kernel *Kernel) AddComponents(b ...Component)
- func (kernel *Kernel) AddControllers(contexts ...Controller)
- func (kernel *Kernel) AddHandler(method, path string, handler Handler, filters ...Handler)
- func (kernel *Kernel) AddHandlerContextName(registry Registry, name, method, path string, handler Handler, ...)
- func (kernel *Kernel) AddHandlerFunc(method, path string, fn HandlerFunc, filters ...Handler)
- func (kernel *Kernel) AddHandlerName(name, method, path string, handler Handler, filters ...Handler)
- func (kernel *Kernel) Container() Registry
- func (kernel *Kernel) Dispatch(eventName string, payload event.Payload)
- func (kernel *Kernel) Dispose()
- func (kernel *Kernel) Fork() *Kernel
- func (kernel *Kernel) MustDispose()
- func (kernel *Kernel) Root() *Kernel
- func (kernel *Kernel) RunServer(host string) error
- func (kernel *Kernel) RunServerTLS(host, certfile, keyfile string) error
- func (kernel *Kernel) Snapshot() *Kernel
- func (kernel *Kernel) Subscribe(eventName string, handler interface{})
- type MapURLGen
- type Mapper
- type MiddlewareBundle
- type Registry
- type RunServerEvent
- type RunServerEventTLS
Constants ¶
const TAG_NAME = "formam"
Variables ¶
var ContextType = reflect.TypeOf((*Context)(nil))
var DefaultKernel = NewKernel()
var KernelType = reflect.TypeOf((*Kernel)(nil))
Functions ¶
func DispatchNext ¶
func DispatchNext(context *Context, name string, writer http.ResponseWriter, request *http.Request, parameter router.Parameter, registry Registry, handlers []Handler) error
DispatchNext entry point
Types ¶
type Component ¶
type Component interface {
Bootstrap(app *Kernel)
}
Component represents a service component, a component need to implement a bootstrap method which is responsible to set up the component with the app, ex: register a type Providers, or add middleware handler
func NewComponentBundle ¶
func NewControllerBundle ¶
func NewControllerBundle(controllers ...Controller) Component
NewControllerBundle creates a component that will bind the passed context at bootstrap
type ComponentBundle ¶
type ComponentBundle []Component
func (ComponentBundle) Bootstrap ¶
func (c ComponentBundle) Bootstrap(a *Kernel)
type ComponentFunc ¶
type ComponentFunc func(*Kernel)
ComponentFunc func implementing Component interface
func (ComponentFunc) Bootstrap ¶
func (component ComponentFunc) Bootstrap(a *Kernel)
type Context ¶
type Context struct { Name string // The name associated with the route Registry Registry // Dependency injection context Request *http.Request // Request data passed by the router Gen *link.URLGen Response http.ResponseWriter // Response Writer passed by the router Params router.Parameter // Route Registry passed by the router // contains filtered or unexported fields }
Context holds context information about the incoming request
func GetContext ¶
GetContext gets a Context from the registry context
func (*Context) BindGetForm ¶
BindGetForm decodes the request url values into target
func (*Context) GetBodyBytes ¶
func (*Context) GetBodyReader ¶
func (c *Context) GetBodyReader() io.ReadCloser
GetBodyReader returns bytes bodyReader
func (*Context) GetCookieValue ¶
GetCookieValue returns a cookie value from the request
func (*Context) GetGetValue ¶
GetGetValue returns a form value from the request, GetPostValue is shortcut for Context.Request.Form.Get method
func (*Context) GetPostValue ¶
GetPostValue returns a form value from the request, GetPostValue is shortcut for Context.Request.Form.Get method
func (*Context) GetURLParameter ¶
GetURLParameter returns a parameter from the url route, GetURLParameter is shortcut for Context.Params.Get method
func (*Context) Redirect ¶
Redirect redirects the request to the specified urlStr and send a http StatusFound code
func (*Context) RedirectStatus ¶
RedirectStatus redirects the request to the specified urlStr and send the the status code specified by httpStatus
func (*Context) SendJSONWithStatus ¶ added in v1.0.2
func (*Context) SendTextWithStatus ¶
type Controller ¶
type Controller interface {
Mx(*Mapper)
}
type ControllerBundle ¶
type ControllerBundle []Controller
func (ControllerBundle) Bootstrap ¶
func (c ControllerBundle) Bootstrap(a *Kernel)
type ControllerURLGen ¶
func (*ControllerURLGen) URL ¶
func (urlGen *ControllerURLGen) URL(dst string, v ...interface{}) string
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)
type Kernel ¶
type Kernel struct { Registry Registry // Kernel Registry dependency injection context Router *router.Router // Router Prefix string // Prefix prefix for path added in this app URLGen MapURLGen MiddlewareBundle // contains filtered or unexported fields }
Kernel app holds your top level data for you service
Router, Dispatcher, Scope
func (*Kernel) AddComponents ¶
AddComponents bootstraps a list of components, a sub scope will be created, and a copy of the original app is used, in such form that modifying the app.Prefix will not reflect outside this call.
func (*Kernel) AddControllers ¶
func (kernel *Kernel) AddControllers(contexts ...Controller)
func (*Kernel) AddHandler ¶
AddHandler register a handler, see: Handler
func (*Kernel) AddHandlerContextName ¶
func (kernel *Kernel) AddHandlerContextName(registry Registry, name, method, path string, handler Handler, filters ...Handler)
AddHandlerContextName accepts a context, a ParamKey identifier, http method|methods, pattern path, handler and handlers ex: one handler app.AddHandlerContextName(myContext,"mySectionIdentifier","GET", "/public",fileServer,checkAuth)
multiples handles app.AddHandlerContextName(myContext,"mySectionIdentifier","GET|POST|SEARCH", "/products",productHandler,checkAuth)
func (*Kernel) AddHandlerFunc ¶
func (kernel *Kernel) AddHandlerFunc(method, path string, fn HandlerFunc, filters ...Handler)
AddHandlerFunc register a func handler, see: Handler
func (*Kernel) AddHandlerName ¶
func (kernel *Kernel) AddHandlerName(name, method, path string, handler Handler, filters ...Handler)
AddHandlerName register a named handler, see: Handler
func (*Kernel) Dispose ¶
func (kernel *Kernel) Dispose()
Dispose Close same as app.registry.Close() invoke this func before exiting the app to cleanup
func (*Kernel) MustDispose ¶
func (kernel *Kernel) MustDispose()
func (*Kernel) RunServer ¶
RunServer runs the server with the specified host Calling this func will emit a "app.run" event in the app
func (*Kernel) RunServerTLS ¶
RunServerTLS runs the server in tls mode Calling this func will emit a "app.run.tls" event in the app
type Mapper ¶
type Mapper struct { Prefix string Name string Registry Registry *ControllerURLGen MiddlewareBundle // contains filtered or unexported fields }
func (*Mapper) BindAction ¶
type MiddlewareBundle ¶
type MiddlewareBundle struct {
// contains filtered or unexported fields
}
func (*MiddlewareBundle) AddMiddleware ¶
func (filterHandlers *MiddlewareBundle) AddMiddleware(filters ...Handler)
AddMiddleware adds handlers to the request chain
func (*MiddlewareBundle) AddMiddlewareFunc ¶
func (filterHandlers *MiddlewareBundle) AddMiddlewareFunc(filters ...HandlerFunc)
func (*MiddlewareBundle) ClearMiddlewares ¶
func (filterHandlers *MiddlewareBundle) ClearMiddlewares()
ClearMiddlewares will clear the registered middlewares for next route added