Search and commands

↑ ↓ to select · Enter to open · Esc to close

Type to search packages.

http

v0.0.0-20240711162211-159a3375b30a
taylz.io/http

Documentation

pkg.go.dev ↗

Table of contents

↓ to select · Enter to jump· Shift+Enter for source

140 matches

Top ↑

Constants

MethodRouterCONNECT (8 declarations)

const (
	MethodRouterCONNECT methodRouter = "CONNECT"
	MethodRouterDELETE  methodRouter = "DELETE"
	MethodRouterGET     methodRouter = "GET"
	MethodRouterHEAD    methodRouter = "HEAD"
	MethodRouterOPTIONS methodRouter = "OPTIONS"
	MethodRouterPOST    methodRouter = "POST"
	MethodRouterPUT     methodRouter = "PUT"
	MethodRouterTRACE   methodRouter = "TRACE"
)

StatusOK (15 declarations)

const (
	// StatusOK = 200
	StatusOK = http.StatusOK
	// StatusPartialContent = 206
	StatusPartialContent = http.StatusPartialContent
	// StatusMovedPermanently = 301
	StatusMovedPermanently = http.StatusMovedPermanently
	// StatusNotModified = 304
	StatusNotModified = http.StatusNotModified
	// StatusBadRequest = 400
	StatusBadRequest = http.StatusBadRequest
	// StatusUnauthorized = 401
	StatusUnauthorized = http.StatusUnauthorized
	// StatusPaymentRequired = 402
	StatusPaymentRequired = http.StatusPaymentRequired
	// StatusForbidden = 403
	StatusForbidden = http.StatusForbidden
	// StatusNotFound = 404
	StatusNotFound = http.StatusNotFound
	// StatusMethodNotAllowed = 405
	StatusMethodNotAllowed = http.StatusMethodNotAllowed
	// StatusConflict = 409
	StatusConflict = http.StatusConflict
	// StatusPreconditionFailed = 412
	StatusPreconditionFailed = http.StatusPreconditionFailed
	// StatusRequestedRangeNotSatisfiable = 416
	StatusRequestedRangeNotSatisfiable = http.StatusRequestedRangeNotSatisfiable
	// StatusTooManyRequests = 429
	StatusTooManyRequests = http.StatusTooManyRequests
	// StatusInternalServerError = 500
	StatusInternalServerError = http.StatusInternalServerError
)

Variables

MethodMiddlewareCONNECT (8 declarations)

var (
	MethodMiddlewareCONNECT = middlewareMethod("CONNECT")
	MethodMiddlewareDELETE  = middlewareMethod("DELETE")
	MethodMiddlewareGET     = middlewareMethod("GET")
	MethodMiddlewareHEAD    = middlewareMethod("HEAD")
	MethodMiddlewareOPTIONS = middlewareMethod("OPTIONS")
	MethodMiddlewarePOST    = middlewareMethod("POST")
	MethodMiddlewarePUT     = middlewareMethod("PUT")
	MethodMiddlewareTRACE   = middlewareMethod("TRACE")
)

RouterMiddlewareCONNECT (8 declarations)

var (
	RouterMiddlewareCONNECT = routerRouterMiddleware(MethodRouterCONNECT)
	RouterMiddlewareDELETE  = routerRouterMiddleware(MethodRouterDELETE)
	RouterMiddlewareGET     = routerRouterMiddleware(MethodRouterGET)
	RouterMiddlewareHEAD    = routerRouterMiddleware(MethodRouterHEAD)
	RouterMiddlewareOPTIONS = routerRouterMiddleware(MethodRouterOPTIONS)
	RouterMiddlewarePOST    = routerRouterMiddleware(MethodRouterPOST)
	RouterMiddlewarePUT     = routerRouterMiddleware(MethodRouterPUT)
	RouterMiddlewareTRACE   = routerRouterMiddleware(MethodRouterTRACE)
)

ErrRegexp

var ErrRegexp = Error(StatusInternalServerError, "url path regexp mismatch")

MarshalJSON

var MarshalJSON = json.Marshal

UnmarshalJSON

var UnmarshalJSON = json.Unmarshal

Functions

Error

func Error(code int, err string) statusError

Error creates a StatusError

ListenAndServe

func ListenAndServe(addr string, handler Handler) error

ListenAndServe calls http.ListenAndServe

ListenAndServeTLS

func ListenAndServeTLS(addr, certFile, keyFile string, handler Handler) error

ListenAndServe calls http.ListenAndServeTLS

MustMarshalJSON

func MustMarshalJSON(v any) []byte

NewMD5SaltHashFunc

func NewMD5SaltHashFunc(salt string) func(string) string

NewMD5SaltHashFunc creates a Func type which salts input to crypto/md5.Sum

ParseRequestBody

func ParseRequestBody[T any](r *Request, parserFunc func([]byte, any) error) (*T, error)

QueryEscape

func QueryEscape(s string) string

QueryEscape calls url.QueryEscape

RealClientAddr

func RealClientAddr(r *Request) string

RealClientAddr returns the Client IP, using "X-Real-Ip", and then "X-Forwarded-For", before defaulting to RemoteAddr

Redirect

func Redirect(w Writer, r *Request, url string, code int)

Redirect calls http.Redirect

StringContains

func StringContains(s, substr string) bool

WriteError

func WriteError(w Writer, r *Request, err error)

WriteErrorStatusJSON

func WriteErrorStatusJSON(w Writer, err error)

Types

AllOfRouters

type AllOfRouters []Router

AllOfRouters is a Router group that returns true when all Routers in the group return true

AllOfRouters.RouteHTTP

func (and AllOfRouters) RouteHTTP(r *Request) bool

AnyOfRouters

type AnyOfRouters []Router

AnyOfRouters is a Router group that returns true when any Routers in the group returns true

AnyOfRouters.RouteHTTP

func (or AnyOfRouters) RouteHTTP(r *Request) bool
type Cookie = http.Cookie

Cookie = http.Cookie

Dir

type Dir = http.Dir

Dir = http.Dir

FileSystem

type FileSystem = http.FileSystem

FileSystem = http.FileSystem

Fork

type Fork []Path

Fork is a Pather made of []Pather

NewFork

func NewFork() *Fork

NewFork creates a Fork

Fork.Add

func (f *Fork) Add(paths ...Path) ForkBuilder

Add appends Pathers to this Fork

Fork.Branch

func (f *Fork) Branch(path string) ForkBuilder

Fork.Handle

func (f *Fork) Handle(path string, h Handler) ForkBuilder

Handle is short for Path(RoutePathExact(path), h)

Fork.HandleFunc

func (f *Fork) HandleFunc(path string, hf func(Writer, *Request)) ForkBuilder

HandleFunc is short for Handle(path, HandlerFunc(hf))

Fork.Path

func (f *Fork) Path(r Router, h Handler) ForkBuilder

Path is short for Add(Path{r, h})

Fork.PathFunc

func (f *Fork) PathFunc(r Router, hf func(Writer, *Request)) ForkBuilder

PathFunc is short for Path(r, HandlerFunc(hf))

Fork.PathFuncs

func (f *Fork) PathFuncs(rf func(*Request) bool, hf func(Writer, *Request)) ForkBuilder

PathFunc is short for PathFunc(RouterFunc(rf), hf)

Fork.ServeHTTP

func (f *Fork) ServeHTTP(w Writer, r *Request)

Fork.With

func (f *Fork) With(routers []RouterMiddleware, middlewares []Middleware) ForkBuilder

Fork.WithMiddlewares

func (f *Fork) WithMiddlewares(middlewares ...Middleware) ForkBuilder

Fork.WithRouters

func (f *Fork) WithRouters(routers ...RouterMiddleware) ForkBuilder

ForkBuilder

type ForkBuilder interface {
	Add(...Path) ForkBuilder
	Branch(path string) ForkBuilder
	Path(Router, Handler) ForkBuilder
	PathFunc(Router, func(Writer, *Request)) ForkBuilder
	PathFuncs(func(*Request) bool, func(Writer, *Request)) ForkBuilder
	Handle(path string, h Handler) ForkBuilder
	HandleFunc(path string, hf func(Writer, *Request)) ForkBuilder
	With([]RouterMiddleware, []Middleware) ForkBuilder
	WithMiddlewares(...Middleware) ForkBuilder
	WithRouters(...RouterMiddleware) ForkBuilder
}

ForkFunc

type ForkFunc func(...Path)

ForkFunc.Add

func (f ForkFunc) Add(paths ...Path) ForkBuilder

ForkFunc.Branch

func (f ForkFunc) Branch(path string) ForkBuilder

ForkFunc.Handle

func (f ForkFunc) Handle(path string, h Handler) ForkBuilder

ForkFunc.HandleFunc

func (f ForkFunc) HandleFunc(path string, hf func(Writer, *Request)) ForkBuilder

ForkFunc.Path

func (f ForkFunc) Path(r Router, h Handler) ForkBuilder

ForkFunc.PathFunc

func (f ForkFunc) PathFunc(r Router, hf func(Writer, *Request)) ForkBuilder

ForkFunc.PathFuncs

func (f ForkFunc) PathFuncs(rf func(*Request) bool, hf func(Writer, *Request)) ForkBuilder

ForkFunc.With

func (f ForkFunc) With(routerMiddlewares []RouterMiddleware, middlewares []Middleware) ForkBuilder

ForkFunc.WithMiddlewares

func (f ForkFunc) WithMiddlewares(middlewares ...Middleware) ForkBuilder

ForkFunc.WithRouters

func (f ForkFunc) WithRouters(routers ...RouterMiddleware) ForkBuilder

FuncRouter

type FuncRouter func(*Request) bool

FuncRouter is a func type Router

FuncRouter.RouteHTTP

func (f FuncRouter) RouteHTTP(r *Request) bool

RouteHTTP implements Router by calling f

Handler

type Handler = http.Handler

Handler = http.Handler

AddPrefix

func AddPrefix(prefix string, h Handler) Handler

BufferedHandler

func BufferedHandler(bytes []byte) Handler

BufferedHandler returns a Handler that always writes the closured bytes

FileServer

func FileServer(root FileSystem) Handler

FileServer calls http.FileServer

IndexHandler

func IndexHandler(fs FileSystem) Handler

IndexHandler returns a Handler that maps every request to /index.html for injected FileSystem, without issuing a redirect

StripPrefix

func StripPrefix(prefix string, h Handler) Handler

Use

func Use(h Handler, m ...Middleware) Handler

Using

func Using(ms []Middleware, h Handler) Handler

HandlerFunc

type HandlerFunc = http.HandlerFunc

HandlerFunc = http.HandlerFunc

HostRouter

type HostRouter string

HostRouter is a string type for matching Request.Host

HostRouter.RouteHTTP

func (host HostRouter) RouteHTTP(r *Request) bool

JSON

type JSON = map[string]any

Middleware

type Middleware = func(next Handler) Handler

Middleware is a consumer type that manipulates Handlers

AddPrefixMiddleware

func AddPrefixMiddleware(prefix string) Middleware

RegexpPathContextMiddleware

func RegexpPathContextMiddleware(regexp *Regexp) Middleware

StripPrefixMiddleware

func StripPrefixMiddleware(prefix string) Middleware

Path

type Path struct {
	Router  Router
	Handler Handler
}

Path is a struct with Router and Handler pointers

NewPath

func NewPath(r Router, h Handler) Path

NewPath creates a Path

NewPathFunc

func NewPathFunc(r Router, hf func(Writer, *Request)) Path

NewPathFunc is short for NewPath(r, HandlerFunc(hf))

SinglePagePath

func SinglePagePath(fs FileSystem, cache bool) Path

Path.RouteHTTP

func (p Path) RouteHTTP(r *Request) bool

RouteHTTP implements Router by calling calling the internal Router

Path.ServeHTTP

func (p Path) ServeHTTP(w Writer, r *Request)

ServeHTTP implements Handler by calling calling the internal Handler

PathMatchRouter

type PathMatchRouter string

PathMatchRouter is a string type that matches a path literal

PathMatchRouter.RouteHTTP

func (path PathMatchRouter) RouteHTTP(r *Request) bool

RouteHTTP implements Router by literally matching the request path

PathPrefixRouter

type PathPrefixRouter string

PathPrefixRouter is a string type that matches a path prefix

PathPrefixRouter.RouteHTTP

func (prefix PathPrefixRouter) RouteHTTP(r *Request) bool

RouteHTTP implements Router by matching the path prefix

Regexp

type Regexp = regexp.Regexp

NewRegexp

func NewRegexp(str string) *Regexp

Request

type Request = http.Request

Request = http.Request

ResponseWriter

type ResponseWriter = http.ResponseWriter

Writer = http.ResponseWriter

Router

type Router interface {
	RouteHTTP(*Request) bool
}

Router is an routing interface

AnyRouter

func AnyRouter() Router

AnyRouter returns a Router that always returns true

RegexpPathRouter

func RegexpPathRouter(regexp *Regexp) Router

SinglePageRouter

func SinglePageRouter() Router

SinglePageRouter returns a Router that checks for Single Page App response

Request.Method is GET Request.URL.Path does not have a period (.) Request.Header["Accept"] contains "text/html"

UseRouter

func UseRouter(r Router, rm ...RouterMiddleware) Router

UsingRouter

func UsingRouter(mr []RouterMiddleware, r Router) Router

UsingRouter applies RouterMiddlewares to a Router

RouterMiddleware

type RouterMiddleware = func(Router) Router

PathPrefixRouterMiddleware

func PathPrefixRouterMiddleware(str string) RouterMiddleware

PathRouterMiddleware

func PathRouterMiddleware(path string) RouterMiddleware

RegexpPathRouterMiddleware

func RegexpPathRouterMiddleware(regexp *Regexp) RouterMiddleware

StatusError

type StatusError interface {
	error
	StatusCode() int
}

StatusError is an error with a status code

TLSRouter

type TLSRouter bool

TLSRouter is a bool type that matches Request.TLS != nil

TLSRouter.RouteHTTP

func (tls TLSRouter) RouteHTTP(r *Request) bool

RouteHTTP implements Router by matching Request.TLS != nil

URL

type URL = url.URL

URL = url.URL

ParseURL

func ParseURL(rawurl string) (*URL, error)

ParseURL calls url.Parse

UserAgentRouter

type UserAgentRouter string

UserAgentRouter is a string type for matching Request.Header["User-Agent"]

UserAgentRouter.RouteHTTP

func (ua UserAgentRouter) RouteHTTP(r *Request) bool

RouteHTTP matches the first chars of Request.Header["User-Agent"]

Writer

type Writer = ResponseWriter

Writer = ResponseWriter

Dependency graph