webutil

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2021 License: MIT Imports: 15 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]interface{}

func CtxPrintf

func CtxPrintf(ctx context.Context, format string, v ...interface{})

func CtxSetPrefix

func CtxSetPrefix(ctx context.Context, prefix string)

func EncodePhpQuery

func EncodePhpQuery(q map[string]interface{}) 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 NewContextLogger

func NewContextLogger(ctx context.Context, l *log.Logger) context.Context

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]interface{}

ParsePhpQuery parses PHP compatible query string, return as map[string]interface{}

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, url string, code int)

func ServeError

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

Types

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)

Jump to

Keyboard shortcuts

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