httpx

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: May 20, 2024 License: GPL-3.0 Imports: 26 Imported by: 0

README

httpx

Golang HTTP router for based on standard http module but with more features

Documentation

Index

Constants

View Source
const (
	ContentTypeJSON = "application/json; charset=utf-8"
	ContentTypeHTML = "text/html; charset=utf-8"
	ContentTypeTEXT = "text/plain; charset=utf-8"
)
View Source
const TraceIDHeader = "X-Trace-Id"

Variables

This section is empty.

Functions

func Data

func Data(w http.ResponseWriter, statusCode int, contentType string, body []byte) error

func DefaultLoggingFunc

func DefaultLoggingFunc(w *logging.Writer, r *http.Request)

func GetOrCreateTraceID

func GetOrCreateTraceID(r *http.Request) string

func GetTraceID

func GetTraceID(r *http.Request) string

func HandlerAuthJWT

func HandlerAuthJWT(secret string) func(next Handler) Handler

func JSON

func JSON(w http.ResponseWriter, statusCode int, obj any) error

func JWTDecode

func JWTDecode(secret, token string) ([]byte, error)

func JWTEncode

func JWTEncode(secret, payload string) string

func NoContent

func NoContent(w http.ResponseWriter) error

func ParseRequest

func ParseRequest(r *http.Request, obj any) error

func ReverseProxy

func ReverseProxy(addr string) *httputil.ReverseProxy

func Text

func Text(w http.ResponseWriter, statusCode int, msg string) error

func UserID

func UserID(r *http.Request) string

func UserIP

func UserIP(r *http.Request) string

Types

type File

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

func NewFile

func NewFile(filepath string, headers map[string]string) (*File, error)

func (*File) Serve

func (f *File) Serve(w http.ResponseWriter, r *http.Request)

type Group

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

func (Group) ANY

func (g Group) ANY(pattern string, handler Handler, middlewares ...Middleware)

func (Group) DELETE

func (g Group) DELETE(pattern string, handler Handler, middlewares ...Middleware)

func (Group) GET

func (g Group) GET(pattern string, handler Handler, middlewares ...Middleware)

func (Group) NewGroup

func (g Group) NewGroup(middlewares ...Middleware) Group

func (Group) PATCH

func (g Group) PATCH(pattern string, handler Handler, middlewares ...Middleware)

func (Group) POST

func (g Group) POST(pattern string, handler Handler, middlewares ...Middleware)

func (Group) PUT

func (g Group) PUT(pattern string, handler Handler, middlewares ...Middleware)

type Handler

type Handler func(w http.ResponseWriter, r *http.Request) error

func DELETE

func DELETE(handler Handler) Handler

func GET

func GET(handler Handler) Handler

func GZip

func GZip(next Handler) Handler

func PATCH

func PATCH(handler Handler) Handler

func POST

func POST(handler Handler) Handler

func PUT

func PUT(handler Handler) Handler

func TraceID

func TraceID(next Handler) Handler

type LoggingFunc

type LoggingFunc func(w *logging.Writer, r *http.Request)

type Middleware

type Middleware func(next Handler) Handler

func Cache

func Cache(cacheDir string, defaultTTL time.Duration) Middleware

type ResponseError

type ResponseError struct {
	Code        int    `json:"code"`
	Message     string `json:"message"`
	ContentType string `json:"content-type,omitempty"`
	Source      string `json:"source,omitempty"`
}

func BadGateway

func BadGateway(err error) ResponseError

func BadRequest

func BadRequest(err error) ResponseError

func Forbidden

func Forbidden(err error) ResponseError

func InternalServerError

func InternalServerError(err error) ResponseError

func MethodNotAllowed

func MethodNotAllowed() ResponseError

func NewError

func NewError(code int, err error) ResponseError

func NotFound

func NotFound() ResponseError

func Unauthorized

func Unauthorized(err error) ResponseError

func (ResponseError) Error

func (e ResponseError) Error() string

func (ResponseError) ServeHTTP

func (e ResponseError) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (ResponseError) WithJSON

func (e ResponseError) WithJSON() ResponseError

func (ResponseError) WithSource

func (e ResponseError) WithSource(source string) ResponseError

type Route

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

type Router

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

func NewRouter

func NewRouter() *Router

func (*Router) ANY

func (ro *Router) ANY(pattern string, h Handler, middlewares ...Middleware)

func (*Router) Catch

func (ro *Router) Catch(next Handler) http.HandlerFunc

func (*Router) DELETE

func (ro *Router) DELETE(pattern string, h Handler, middlewares ...Middleware)

func (*Router) GET

func (ro *Router) GET(pattern string, h Handler, middlewares ...Middleware)

func (*Router) NewGroup

func (ro *Router) NewGroup(middleware ...Middleware) Group

func (*Router) PATCH

func (ro *Router) PATCH(pattern string, h Handler, middlewares ...Middleware)

func (*Router) POST

func (ro *Router) POST(pattern string, h Handler, middlewares ...Middleware)

func (*Router) PUT

func (ro *Router) PUT(pattern string, h Handler, middlewares ...Middleware)

func (*Router) ServeHTTP

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

func (*Router) Use

func (ro *Router) Use(middlewares ...Middleware)

func (*Router) UseLogging

func (ro *Router) UseLogging(loggingFunc LoggingFunc)

type ServeMux added in v0.0.2

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

func (*ServeMux) HandlerOn404 added in v0.0.2

func (mux *ServeMux) HandlerOn404(h http.HandlerFunc)

func (*ServeMux) HandlerOn405 added in v0.0.2

func (mux *ServeMux) HandlerOn405(h http.HandlerFunc)

func (*ServeMux) Route added in v0.0.2

func (mux *ServeMux) Route(method, pattern string, h http.HandlerFunc) error

func (*ServeMux) ServeHTTP added in v0.0.2

func (mux *ServeMux) ServeHTTP(w http.ResponseWriter, r *http.Request)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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