server

package module
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: MIT Imports: 8 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddContextValue

func AddContextValue(req *http.Request, key, value any)

func File

func File(contentType string, f io.Reader) func(w http.ResponseWriter, req *http.Request)

func GetContextValue

func GetContextValue[t any](req *http.Request, key any, value *t) bool

func Handle

func Handle(handlers ...any) func(w http.ResponseWriter, req *http.Request)

func HasContextValue

func HasContextValue[t any](req *http.Request, key any) bool

func Html

func Html(str string) func(w http.ResponseWriter, req *http.Request)

func PathParams

func PathParams(req *http.Request) map[any]string

func Recover

func Recover(req *http.Request) any

Types

type ChainHandler

type ChainHandler func(http.ResponseWriter, *http.Request) bool
var Get ChainHandler = Method("GET")
var Path ChainHandler = Method("PATCH")
var Post ChainHandler = Method("POST")
var Put ChainHandler = Method("PUT")

func BasicAuthHandler

func BasicAuthHandler(user, pass string) ChainHandler

func Method

func Method(method string) ChainHandler

func NopHandler

func NopHandler() ChainHandler

type ResponseBuilder

type ResponseBuilder interface {
	Status(status int) ResponseBuilder
	WithBody(body any) ResponseBuilder
	WithHeader(key, value string) ResponseBuilder
	WithCookie(cookie *http.Cookie) ResponseBuilder
	Redirect(redirect string)
	HtmlTemplate(temp *template.Template, data any)
	As(contentType string)
	AsTextPlain()
	AsJson()
	AsHtml()
}

type ResponseWriter added in v1.1.0

type ResponseWriter interface {
	http.ResponseWriter
	Status() int
	Written() bool
	Size() int
}

func NewResponseWriter added in v1.1.0

func NewResponseWriter(rw http.ResponseWriter) ResponseWriter

type Router

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

func NewRouter added in v1.1.0

func NewRouter() *Router

func (*Router) Delete added in v1.1.0

func (r *Router) Delete(pathExpr string, handler http.HandlerFunc) *Router

func (*Router) Get added in v1.1.0

func (r *Router) Get(pathExpr string, handler http.HandlerFunc) *Router

func (*Router) NotFoundHandler added in v1.1.0

func (r *Router) NotFoundHandler(handler http.HandlerFunc) *Router

func (*Router) Patch added in v1.1.0

func (r *Router) Patch(pathExpr string, handler http.HandlerFunc) *Router

func (*Router) Post added in v1.1.0

func (r *Router) Post(pathExpr string, handler http.HandlerFunc) *Router

func (*Router) PostFilters added in v1.1.0

func (r *Router) PostFilters(filters ...http.HandlerFunc) *Router

func (*Router) PreFilters added in v1.1.0

func (r *Router) PreFilters(filters ...http.HandlerFunc) *Router

func (*Router) Put added in v1.1.0

func (r *Router) Put(pathExpr string, handler http.HandlerFunc) *Router

func (*Router) RecoverHandler added in v1.1.0

func (r *Router) RecoverHandler(handler http.HandlerFunc) *Router

func (*Router) ServeHTTP

func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)

func (*Router) SubRoute added in v1.1.0

func (r *Router) SubRoute(pathExpr string, router *Router) *Router

Directories

Path Synopsis
from https://github.com/pillarjs/path-to-regexp/tree/c7ec332e87d8560673884d5629e1cb23cb03cb87
from https://github.com/pillarjs/path-to-regexp/tree/c7ec332e87d8560673884d5629e1cb23cb03cb87

Jump to

Keyboard shortcuts

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