gen

package module
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2024 License: MIT Imports: 16 Imported by: 0

README

gen

A demo web framework for golang

Documentation

Index

Constants

View Source
const (
	MIMEJSON      = "application/json"
	MIMEHTML      = "text/html"
	MIMEPlain     = "text/plain"
	MIMEPOSTForm  = "application/x-www-form-urlencoded"
	MIMEMultipart = "multipart/form-data"
)
View Source
const AuthProxyUserKey = "proxy_user"
View Source
const AuthUserKey = "user"

Variables

This section is empty.

Functions

This section is empty.

Types

type Accounts added in v0.3.1

type Accounts map[string]string

type Context

type Context struct {
	Writer  http.ResponseWriter
	Request *http.Request

	Path   string
	Method string
	Params httprouter.Params

	Keys       map[string]any
	StatusCode int
	Errors     []*error // Errors is a list of errors attached to all the handlers/middlewares
	// contains filtered or unexported fields
}

func (*Context) Abort added in v0.2.0

func (c *Context) Abort()

Abort Note that this will not stop the current handler, often followed by `return`

func (*Context) AbortWithStatus added in v0.3.0

func (c *Context) AbortWithStatus(code int)

func (*Context) Cookie added in v0.3.0

func (c *Context) Cookie(name string) (string, error)

func (*Context) Copy added in v0.5.0

func (c *Context) Copy() *Context

Copy returns a copy of the current context that can be safely used outside the request's scope. This has to be used when the context has to be passed to a goroutine.

func (*Context) Data

func (c *Context) Data(code int, contentType string, data []byte)

func (*Context) File added in v0.3.0

func (c *Context) File(filePath string)

func (*Context) Get added in v0.3.0

func (c *Context) Get(key string) (value any, ok bool)

func (*Context) HTML

func (c *Context) HTML(code int, name string, data any)

func (*Context) HandlerName added in v0.5.0

func (c *Context) HandlerName() string

HandlerName returns the main handler's name

func (*Context) JSON

func (c *Context) JSON(code int, obj any)

func (*Context) MustGet added in v0.5.0

func (c *Context) MustGet(key string) any

func (*Context) Next added in v0.1.1

func (c *Context) Next()

func (*Context) Param added in v0.0.2

func (c *Context) Param(key string) string

func (*Context) PostForm

func (c *Context) PostForm(key string) string

PostForm for x-www-form-urlencoded POST

func (*Context) Query

func (c *Context) Query(key string) string

func (*Context) Redirect added in v0.3.0

func (c *Context) Redirect(location string)

func (*Context) RemoteIP added in v0.2.1

func (c *Context) RemoteIP() string

func (*Context) Set added in v0.3.0

func (c *Context) Set(key string, value any)

func (*Context) SetCookie added in v0.3.0

func (c *Context) SetCookie(
	name string,
	value string,
	maxAge int,
	path string,
	domain string,
	secure bool,
	httpOnly bool,
)

func (*Context) SetHeader

func (c *Context) SetHeader(key, value string)

func (*Context) Status

func (c *Context) Status(code int)

func (*Context) String

func (c *Context) String(code int, format string, a ...any)

type Engine

type Engine struct {
	*RouterGroup
	// contains filtered or unexported fields
}

func Default added in v0.2.0

func Default() *Engine

Default use Logger & Recovery middlewares

func New

func New() *Engine

func (*Engine) LoadHTMLFiles added in v0.3.0

func (e *Engine) LoadHTMLFiles(files ...string)

func (*Engine) LoadHTMLGlob added in v0.2.0

func (e *Engine) LoadHTMLGlob(path string)

func (*Engine) Run

func (e *Engine) Run(addr string) error

func (*Engine) RunTLS added in v0.3.0

func (e *Engine) RunTLS(addr, certFile, keyFile string) error

func (*Engine) ServeHTTP

func (e *Engine) ServeHTTP(w http.ResponseWriter, req *http.Request)

func (*Engine) SetFuncMap added in v0.1.1

func (e *Engine) SetFuncMap(funcMap template.FuncMap)

SetFuncMap assume that only invoke one time

type H

type H map[string]any

type HandlerFunc

type HandlerFunc func(c *Context)

func BasicAuth added in v0.3.1

func BasicAuth(accounts Accounts) HandlerFunc

BasicAuth returns a Basic HTTP Authorization middleware.

func BasicAuthForProxy added in v0.3.1

func BasicAuthForProxy(accounts Accounts) HandlerFunc

BasicAuthForProxy returns a Basic HTTP Proxy Authorization middleware.

func BasicAuthForProxyWithRealm added in v0.3.1

func BasicAuthForProxyWithRealm(accounts Accounts, realm string) HandlerFunc

BasicAuthForProxyWithRealm If the realm is empty, "Proxy Authorization Required" will be used by default.

func BasicAuthWithRealm added in v0.3.1

func BasicAuthWithRealm(accounts Accounts, realm string) HandlerFunc

BasicAuthWithRealm If the realm is empty, "Authorization Required" will be used by default.

func Logger added in v0.1.1

func Logger() HandlerFunc

Logger middleware that top group use

func Recovery added in v0.2.0

func Recovery() HandlerFunc

type RouterGroup added in v0.1.1

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

func (*RouterGroup) Any added in v0.2.0

func (g *RouterGroup) Any(path string, handlers ...HandlerFunc)

func (*RouterGroup) CONNECT added in v0.2.0

func (g *RouterGroup) CONNECT(path string, handlers ...HandlerFunc)

func (*RouterGroup) DELETE added in v0.2.0

func (g *RouterGroup) DELETE(path string, handlers ...HandlerFunc)

func (*RouterGroup) GET added in v0.1.1

func (g *RouterGroup) GET(path string, handlers ...HandlerFunc)

func (*RouterGroup) Group added in v0.1.1

func (g *RouterGroup) Group(prefix string, handlers ...HandlerFunc) *RouterGroup

func (*RouterGroup) HEAD added in v0.2.0

func (g *RouterGroup) HEAD(path string, handlers ...HandlerFunc)

func (*RouterGroup) OPTIONS added in v0.2.0

func (g *RouterGroup) OPTIONS(path string, handlers ...HandlerFunc)

func (*RouterGroup) PATCH added in v0.2.0

func (g *RouterGroup) PATCH(path string, handlers ...HandlerFunc)

func (*RouterGroup) POST added in v0.1.1

func (g *RouterGroup) POST(path string, handlers ...HandlerFunc)

func (*RouterGroup) Static added in v0.1.1

func (g *RouterGroup) Static(relativePath, root string)

func (*RouterGroup) TRACE added in v0.2.0

func (g *RouterGroup) TRACE(path string, handlers ...HandlerFunc)

func (*RouterGroup) Use added in v0.1.1

func (g *RouterGroup) Use(middlewares ...HandlerFunc)

Jump to

Keyboard shortcuts

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