engine

package
v2.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2024 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Ctx

type Ctx struct {
	Error      error                  // represents an error
	Req        *http.Request          // http request
	Res        http.ResponseWriter    // http response
	Params     httprouter.Params      // http params
	BodyParser bodyparser.BodyParserI // body parser
	// contains filtered or unexported fields
}

request and response context

func (*Ctx) DecodeCookie

func (c *Ctx) DecodeCookie(name string, dest *http.Cookie) error

Decodes encrypted cookie named 'name' to dest

func (*Ctx) JSON

func (c *Ctx) JSON(status int, data interface{}) error

Sends JSON with 'application/json' content type. 'data' is a pointer to the struct, and it is a JSON unmarshalled object this function marshalls the JSON and sends it to the client

func (*Ctx) RenderHTML

func (c *Ctx) RenderHTML(name string, data H) error

Renders given HTML template file with the std go templating engine

func (*Ctx) Session

func (c *Ctx) Session(config *sessions.Config) (*sessions.Session, error)

func (*Ctx) SetCookie

func (c *Ctx) SetCookie(cookie *http.Cookie) error

Sets secure cookie

func (*Ctx) String

func (c *Ctx) String(status int, data string) error

Sends string with custom status code

type Engine

type Engine struct {
	MaxBodySize  int64          // max request body size
	SecureCookie crypt.CrypterI // crypter to use for secure cookie impl

	Storage sessions.Store
	Timeout time.Duration // defines timeout for handlers
	// contains filtered or unexported fields
}

Engine describes the engine for the HTTP server

func New

func New() *Engine

Creates a new app instance.

Do not load crypter or secret keys from randomized keys each app startup. Rather load them from safe environments. Make sure for them to be 32 bytes long to satisfy AES-256

func (*Engine) Get

func (e *Engine) Get(name string, handler ...Handler)

Register POST route; shorthand for 'RegisterRoute'

func (*Engine) GetRoute

func (e *Engine) GetRoute(name string, method string) (*Route, error)

Get existing route by name and it's method

func (*Engine) GetTemplate

func (e *Engine) GetTemplate() *template.Template

Gets the underlying templating engine if it is present

func (*Engine) Post

func (e *Engine) Post(name string, handler ...Handler)

Register GET route; shorthand for 'RegisterRoute'

func (*Engine) RegisterRoute

func (e *Engine) RegisterRoute(name, method string, handler ...Handler)

Function to register route with all HTTP methods supported

func (*Engine) Run

func (e *Engine) Run(addr string)

run the http server on given addr

func (*Engine) SetBodyParser

func (e *Engine) SetBodyParser(parser bodyparser.BodyParserI)

Set custom body parser

func (*Engine) SetErrorHandler

func (e *Engine) SetErrorHandler(h Handler)

Set custom error handling function

func (*Engine) SetTemplate

func (e *Engine) SetTemplate(temp *template.Template)

Set templating

func (*Engine) SetValidatorEngine

func (e *Engine) SetValidatorEngine(validator binding.ValidatorImpl)

Define custom validator engine. Keep in mind that validator should be a struct pointer See: '/binding/validator.go' for example

func (*Engine) Static

func (e *Engine) Static(path string, root http.FileSystem)

Serves static files

type H

type H map[string]any

type Handler

type Handler func(c *Ctx) error

route handling function

type Route

type Route struct {
	// contains filtered or unexported fields
}

defines a route

Directories

Path Synopsis
Default crypters: - AES GCM HMAC - AES CTR HMAC
Default crypters: - AES GCM HMAC - AES CTR HMAC
parsers

Jump to

Keyboard shortcuts

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