webutil

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2023 License: MIT Imports: 12 Imported by: 4

README

GoDoc

various web utils

This contains a number of useful libs for http servers and other web usage.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertPhpQuery

func ConvertPhpQuery(u url.Values) map[string]any

func EncodePhpQuery

func EncodePhpQuery(q map[string]any) string

func ErrorHandler added in v0.0.2

func ErrorHandler(f http.Handler) error

ErrorHandler returns an error that also complies with http.Handler for a given http.Handler.

func ErrorHandlerFunc added in v0.0.2

func ErrorHandlerFunc(f func(w http.ResponseWriter, req *http.Request)) error

ErrorHandlerFunc returns an error that also complies with http.Handler for a given function.

func ErrorToHttpHandler

func ErrorToHttpHandler(e error) http.Handler

func HTTPStatus added in v0.0.5

func HTTPStatus(err error) int

func HttpErrorHandler

func HttpErrorHandler(code int) http.Handler

func HttpHandlerToError

func HttpHandlerToError(h http.Handler) error

func IsRedirect

func IsRedirect(e error) http.Handler

func ParseDataUri

func ParseDataUri(u string) ([]byte, string, error)

ParseDataUri will parse a given data: uri and return its data and mime type.

func ParseIPPort

func ParseIPPort(ip string) *net.TCPAddr

ParseIPPort will parse an IP with optionally a port

func ParsePhpQuery

func ParsePhpQuery(q string) map[string]any

ParsePhpQuery parses PHP compatible query string, return as map[string]any

multiple cases may happen: a=b (simple) a[b]=c (object) a[]=c (array) a[b][]=c (multi levels) a[][][]=c (wtf)

func RedirectError

func RedirectError(u *url.URL) error

func RedirectErrorCode

func RedirectErrorCode(u *url.URL, code int) error

code can be one of http.StatusMovedPermanently or http.StatusFound or any 3xx http status code

func SendRedirect

func SendRedirect(w http.ResponseWriter, target string, code int)

SendRedirect is deprecated. http.Redirect() should be used instead

func ServeError

func ServeError(w http.ResponseWriter, req *http.Request, err error)

func Wrap added in v0.0.8

func Wrap(h Handler) http.Handler

Types

type Handler added in v0.0.8

type Handler interface {
	ServeHTTP(w http.ResponseWriter, req *http.Request) error
}

type HttpError

type HttpError int

func (HttpError) Error added in v0.0.4

func (e HttpError) Error() string

func (HttpError) HTTPStatus added in v0.0.5

func (e HttpError) HTTPStatus() int

HTTPStatus returns the value set in http error

func (HttpError) ServeHTTP added in v0.0.4

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

type Redirect added in v0.0.6

type Redirect struct {
	URL  *url.URL
	Code int
}

func (*Redirect) Error added in v0.0.6

func (e *Redirect) Error() string

func (*Redirect) HTTPStatus added in v0.0.6

func (e *Redirect) HTTPStatus() int

func (*Redirect) ServeHTTP added in v0.0.6

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

type WrapFunc added in v0.0.8

type WrapFunc func(w http.ResponseWriter, req *http.Request) error

func (WrapFunc) ServeHTTP added in v0.0.8

func (wf WrapFunc) ServeHTTP(w http.ResponseWriter, req *http.Request)

type Wrapper added in v0.0.8

type Wrapper struct {
	Child Handler
}

func (*Wrapper) ServeHTTP added in v0.0.8

func (wrapper *Wrapper) ServeHTTP(w http.ResponseWriter, req *http.Request)

Jump to

Keyboard shortcuts

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