uhttp

package
v0.7.28 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2024 License: MIT Imports: 31 Imported by: 4

Documentation

Index

Constants

View Source
const (
	UrlTag    string = "url"
	HeaderTag string = "http"
)
View Source
const XForwardedFor = "X-Forwarded-For"

Variables

This section is empty.

Functions

func ClientAddress added in v0.6.17

func ClientAddress(r *http.Request, xRemoteAddress string) string

func ClientRequestName added in v0.5.3

func ClientRequestName(r Request) string

func DumpBody added in v0.7.10

func DumpBody(r *http.Request) (v []byte, err error)

func HeaderString added in v0.2.18

func HeaderString(h http.Header) string

func HeaderTo added in v0.2.18

func HeaderTo(h http.Header, s any) (err error)

func IsEmpty added in v0.2.33

func IsEmpty(s string) bool

func Marshal added in v0.2.33

func Marshal(v any, omitempty bool) (s string, omit bool)

func OmitEmpty added in v0.2.33

func OmitEmpty(flags []string) bool

func ParamsString added in v0.5.3

func ParamsString(params url.Values) string

func ProxyRequestName added in v0.5.3

func ProxyRequestName(r *http.Request, xRemoteAddress string) string

func ProxyRequestNameDefault added in v0.7.13

func ProxyRequestNameDefault(r *http.Request) string

func RequestName added in v0.5.3

func RequestName(r *http.Request) string

func RouteName added in v0.5.3

func RouteName(method, uri string) string

func Title added in v0.5.3

func Title(name string, statusCode int, status string, tm time.Duration, requestBodyLen int, responseBodyLen int, err error) string

func UrlJoin added in v0.2.37

func UrlJoin(s ...any) string

func WebSocketName added in v0.5.3

func WebSocketName(name string) string

Types

type Client

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

func NewClient

func NewClient() *Client

func (*Client) Base added in v0.5.9

func (o *Client) Base() string

func (*Client) Copy added in v0.3.6

func (o *Client) Copy() *Client

func (*Client) Delete

func (o *Client) Delete(url string) *Performer

func (*Client) Get

func (o *Client) Get(url string) *Performer

func (*Client) Post

func (o *Client) Post(url string) *Performer

func (*Client) Put

func (o *Client) Put(url string) *Performer

func (*Client) Request

func (o *Client) Request(method string, url string) *Performer

func (*Client) Timeout

func (o *Client) Timeout() time.Duration

func (*Client) Transport added in v0.3.6

func (o *Client) Transport() http.RoundTripper

func (*Client) Url added in v0.2.25

func (o *Client) Url(url string) string

func (*Client) WithAppendPath added in v0.2.26

func (o *Client) WithAppendPath(path string) *Client

func (*Client) WithBase added in v0.2.25

func (o *Client) WithBase(base string) *Client

func (*Client) WithOnDoRequestError added in v0.3.15

func (o *Client) WithOnDoRequestError(f OnError) *Client

func (*Client) WithOnInitRequestError added in v0.3.15

func (o *Client) WithOnInitRequestError(f OnError) *Client

func (*Client) WithOnReadBodyError added in v0.3.15

func (o *Client) WithOnReadBodyError(f OnError) *Client

func (*Client) WithPath

func (o *Client) WithPath(path string) *Client

func (*Client) WithProxy

func (o *Client) WithProxy(proxy string) *Client

func (*Client) WithProxyUrl added in v0.2.21

func (o *Client) WithProxyUrl(url *url.URL) *Client

func (*Client) WithTimeout

func (o *Client) WithTimeout(timeout time.Duration) *Client

func (*Client) WithTrace

func (o *Client) WithTrace(trace func(Response)) *Client

func (*Client) WithTransport added in v0.3.6

func (o *Client) WithTransport(transport http.RoundTripper) *Client

type DomainMux added in v0.7.13

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

func NewDomainMux added in v0.7.13

func NewDomainMux() *DomainMux

func (*DomainMux) DefaultHandler added in v0.7.13

func (o *DomainMux) DefaultHandler(h http.Handler)

func (*DomainMux) Handler added in v0.7.13

func (o *DomainMux) Handler(domain string, h http.Handler)

func (*DomainMux) ServeHTTP added in v0.7.13

func (o *DomainMux) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Format

type Format struct {
	RequestParams     bool
	RequestHeader     bool
	ResponseHeader    bool
	RequestBody       bool
	ResponseBody      bool
	RequestBodyTrim   bool
	ResponseBodyTrim  bool
	RequestBodyLimit  int
	ResponseBodyLimit int
}

type FormatProvider added in v0.5.3

type FormatProvider struct {
	Title          func() string
	RequestParams  func() string
	RequestHeader  func() string
	RequestBody    func() string
	ResponseHeader func() string
	ResponseBody   func() string
}

func (FormatProvider) Format added in v0.5.3

func (o FormatProvider) Format(f Format) string

type OnError added in v0.3.15

type OnError func(error, *Response) error

type OnErrors added in v0.3.15

type OnErrors struct {
	InitRequest OnError
	DoRequest   OnError
	ReadBody    OnError
	// contains filtered or unexported fields
}

type OnRequest added in v0.5.3

type OnRequest func(http.ResponseWriter, *http.Request)

type OnWebsocket added in v0.5.3

type OnWebsocket func(*websocket.Conn)

type Performer

type Performer struct {
	Request Request
	// contains filtered or unexported fields
}

func (*Performer) Auth

func (o *Performer) Auth(v string) *Performer

func (*Performer) AuthBearer

func (o *Performer) AuthBearer(token string) *Performer

func (*Performer) Body

func (o *Performer) Body(body []byte) *Performer

func (*Performer) ContentType

func (o *Performer) ContentType(v string) *Performer

func (*Performer) ContentTypeJson

func (o *Performer) ContentTypeJson() *Performer

func (*Performer) Do

func (o *Performer) Do() (r Response)

func (*Performer) Header

func (o *Performer) Header(name string, value any) *Performer

func (*Performer) Headers

func (o *Performer) Headers(s any) *Performer

func (*Performer) Json

func (o *Performer) Json(v any) *Performer

func (*Performer) OnDoRequestError added in v0.3.15

func (o *Performer) OnDoRequestError(f OnError) *Performer

func (*Performer) OnInitRequestError added in v0.3.15

func (o *Performer) OnInitRequestError(f OnError) *Performer

func (*Performer) OnReadBodyError added in v0.3.15

func (o *Performer) OnReadBodyError(f OnError) *Performer

func (*Performer) Param

func (o *Performer) Param(name string, value any) *Performer

func (*Performer) Params

func (o *Performer) Params(s any) *Performer

func (*Performer) Trace

func (o *Performer) Trace(trace func(Response)) *Performer

type Request

type Request struct {
	Method string
	Url    string
	Params url.Values
	Header http.Header
	Body   []byte
}

func (*Request) BodyLenght added in v0.7.10

func (o *Request) BodyLenght() int

func (*Request) BodyString

func (o *Request) BodyString() string

func (*Request) HeaderString

func (o *Request) HeaderString() string

func (*Request) ParamsString

func (o *Request) ParamsString() string

func (*Request) Path

func (o *Request) Path(path string)

func (*Request) RefineUrl added in v0.2.17

func (o *Request) RefineUrl()

func (*Request) Uri

func (o *Request) Uri() string

type Response added in v0.7.9

type Response struct {
	Request    Request
	Time       time.Duration
	Status     string
	StatusCode int
	Header     http.Header
	Body       []byte
	Error      error
}

func (Response) BodyExists added in v0.7.9

func (o Response) BodyExists() bool

func (Response) BodyString added in v0.7.9

func (o Response) BodyString() string

func (Response) Format added in v0.7.9

func (o Response) Format(f Format) string

func (Response) GetStatus added in v0.7.9

func (o Response) GetStatus() string

func (Response) HeaderExists added in v0.7.9

func (o Response) HeaderExists(key string) bool

func (Response) HeaderFloat64 added in v0.7.9

func (o Response) HeaderFloat64(key string) (float64, error)

func (Response) HeaderInt64 added in v0.7.9

func (o Response) HeaderInt64(key string) (int64, error)

func (Response) HeaderString added in v0.7.9

func (o Response) HeaderString() string

func (Response) HeaderTo added in v0.7.9

func (o Response) HeaderTo(v any) error

func (Response) HeaderValue added in v0.7.9

func (o Response) HeaderValue(key string) string

func (Response) Json added in v0.7.9

func (o Response) Json(v any) error

func (Response) NotOkError added in v0.7.9

func (o Response) NotOkError() error

func (Response) Ok added in v0.7.9

func (o Response) Ok() bool

func (*Response) RefineError added in v0.7.9

func (o *Response) RefineError(text string, err error)

func (Response) Text added in v0.7.9

func (o Response) Text() string

func (Response) Title added in v0.7.9

func (o Response) Title() string

type ReverseProxy added in v0.5.9

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

func NewReverseProxy added in v0.5.9

func NewReverseProxy() *ReverseProxy

func (*ReverseProxy) Init added in v0.7.13

func (o *ReverseProxy) Init()

func (*ReverseProxy) Log added in v0.7.13

func (o *ReverseProxy) Log() *ulog.Log

func (*ReverseProxy) OnRequest added in v0.5.9

func (o *ReverseProxy) OnRequest(f func(http.ResponseWriter, *http.Request) error) *ReverseProxy

func (*ReverseProxy) OnRewrite added in v0.5.9

func (o *ReverseProxy) OnRewrite(f func(*httputil.ProxyRequest)) *ReverseProxy

func (*ReverseProxy) OnTarget added in v0.5.9

func (o *ReverseProxy) OnTarget(f func(*httputil.ProxyRequest) string) *ReverseProxy

func (*ReverseProxy) Pure added in v0.5.9

func (o *ReverseProxy) Pure() *ReverseProxy

func (*ReverseProxy) ServeHTTP added in v0.7.13

func (o *ReverseProxy) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*ReverseProxy) Target added in v0.5.9

func (o *ReverseProxy) Target() string

func (*ReverseProxy) Tracer added in v0.7.9

func (*ReverseProxy) WithLog added in v0.7.13

func (o *ReverseProxy) WithLog(log *ulog.Log) *ReverseProxy

func (*ReverseProxy) WithTarget added in v0.7.13

func (o *ReverseProxy) WithTarget(s string) *ReverseProxy

func (*ReverseProxy) WithTrace added in v0.7.9

func (o *ReverseProxy) WithTrace(tracer *Tracer[ReverseProxyResponse]) *ReverseProxy

type ReverseProxyResponse added in v0.7.10

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

func NewReverseProxyResponse added in v0.7.10

func NewReverseProxyResponse(r *http.Request, w http.ResponseWriter, tracer *Tracer[ReverseProxyResponse]) *ReverseProxyResponse

func (ReverseProxyResponse) Close added in v0.7.10

func (o ReverseProxyResponse) Close()

func (ReverseProxyResponse) ErrorFree added in v0.7.10

func (o ReverseProxyResponse) ErrorFree() bool

func (ReverseProxyResponse) Format added in v0.7.10

func (o ReverseProxyResponse) Format(f Format) string

func (*ReverseProxyResponse) Header added in v0.7.10

func (o *ReverseProxyResponse) Header() http.Header

func (ReverseProxyResponse) Ok added in v0.7.10

func (o ReverseProxyResponse) Ok() bool

func (*ReverseProxyResponse) SetError added in v0.7.10

func (o *ReverseProxyResponse) SetError(err error)

func (*ReverseProxyResponse) Write added in v0.7.10

func (o *ReverseProxyResponse) Write(v []byte) (int, error)

func (*ReverseProxyResponse) WriteHeader added in v0.7.10

func (o *ReverseProxyResponse) WriteHeader(statusCode int)

type Router added in v0.5.3

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

func NewRouter added in v0.5.3

func NewRouter() *Router

func (Router) Branch added in v0.5.3

func (o Router) Branch(path string) *Router

func (*Router) Delete added in v0.5.3

func (o *Router) Delete(path string, onRequest OnRequest)

func (*Router) Files added in v0.5.3

func (o *Router) Files(f fs.FS)

func (*Router) Get added in v0.5.3

func (o *Router) Get(path string, onRequest OnRequest)

func (*Router) Handle added in v0.5.3

func (o *Router) Handle(method string, path string, onRequest OnRequest) error

func (*Router) IsRoot added in v0.5.3

func (o *Router) IsRoot() bool

func (*Router) Log added in v0.5.3

func (o *Router) Log() *ulog.Log

func (*Router) Options added in v0.5.3

func (o *Router) Options(path string, onRequest OnRequest)

func (*Router) Post added in v0.5.3

func (o *Router) Post(path string, onRequest OnRequest)

func (*Router) Put added in v0.5.3

func (o *Router) Put(path string, onRequest OnRequest)

func (*Router) RequestName added in v0.5.3

func (o *Router) RequestName(r *http.Request) string

func (*Router) ReverseProxy added in v0.5.9

func (o *Router) ReverseProxy(path string, proxy *ReverseProxy)

func (*Router) Router added in v0.5.3

func (o *Router) Router() *mux.Router

func (*Router) Spa added in v0.6.39

func (o *Router) Spa(fs fs.FS)

func (*Router) WebSocket added in v0.5.3

func (o *Router) WebSocket(path string, onWebsocket OnWebsocket)

func (*Router) WithLog added in v0.7.13

func (o *Router) WithLog(log *ulog.Log) *Router

func (*Router) WithWebSocketErrorLevel added in v0.5.3

func (o *Router) WithWebSocketErrorLevel(level ulog.Level) *Router

func (*Router) WithXRemoteAddress added in v0.5.3

func (o *Router) WithXRemoteAddress(s string) *Router

type Server added in v0.5.2

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

func NewServer added in v0.5.3

func NewServer() *Server

func (*Server) Close added in v0.5.2

func (o *Server) Close()

func (*Server) IsTls added in v0.5.2

func (o *Server) IsTls() bool

func (*Server) Run added in v0.5.2

func (o *Server) Run(addr string, handler http.Handler)

func (*Server) WithAutoSecret added in v0.5.2

func (o *Server) WithAutoSecret(dir string, domains ...string) *Server

func (*Server) WithLogErrors added in v0.5.2

func (o *Server) WithLogErrors(use bool) *Server

func (*Server) WithLogErrorsLevel added in v0.5.2

func (o *Server) WithLogErrorsLevel(level ulog.Level) *Server

func (*Server) WithSecret added in v0.5.2

func (o *Server) WithSecret(certFile, keyFile string) *Server

func (*Server) WithSecretDir added in v0.5.2

func (o *Server) WithSecretDir(dir string) *Server

func (*Server) WithTimeouts added in v0.7.13

func (o *Server) WithTimeouts(timeouts Timeouts) *Server

type ServerDual added in v0.7.9

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

func ServerNewDual added in v0.7.9

func ServerNewDual() *ServerDual

func (*ServerDual) Close added in v0.7.9

func (o *ServerDual) Close()

func (*ServerDual) Run added in v0.7.9

func (o *ServerDual) Run(addr string, addrTls string, handler http.Handler) error

func (*ServerDual) WithAutoSecret added in v0.7.9

func (o *ServerDual) WithAutoSecret(dir string, domains ...string) *ServerDual

func (*ServerDual) WithLogErrors added in v0.7.9

func (o *ServerDual) WithLogErrors(use bool) *ServerDual

func (*ServerDual) WithLogErrorsLevel added in v0.7.9

func (o *ServerDual) WithLogErrorsLevel(level ulog.Level) *ServerDual

func (*ServerDual) WithRedirectToTls added in v0.7.9

func (o *ServerDual) WithRedirectToTls(use string) *ServerDual

func (*ServerDual) WithSecret added in v0.7.9

func (o *ServerDual) WithSecret(certFile, keyFile string) *ServerDual

func (*ServerDual) WithSecretDir added in v0.7.9

func (o *ServerDual) WithSecretDir(dir string) *ServerDual

func (*ServerDual) WithTimeouts added in v0.7.13

func (o *ServerDual) WithTimeouts(timeouts Timeouts) *ServerDual

type SpaHandler added in v0.6.39

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

func NewSpaHandler added in v0.6.39

func NewSpaHandler(f fs.FS) *SpaHandler

func (*SpaHandler) ServeHTTP added in v0.6.39

func (o *SpaHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*SpaHandler) WithPath added in v0.6.39

func (o *SpaHandler) WithPath(path string) *SpaHandler

type Timeouts added in v0.7.13

type Timeouts struct {
	Write time.Duration
	Read  time.Duration
	Idle  time.Duration
	Close time.Duration
}

func (*Timeouts) Set added in v0.7.13

func (o *Timeouts) Set(t Timeouts)

func (Timeouts) String added in v0.7.13

func (o Timeouts) String() string

type TraceResponce added in v0.7.9

type TraceResponce interface {
	Ok() bool
	Format(Format) string
}

type Tracer

type Tracer[T TraceResponce] struct {
	// contains filtered or unexported fields
}

func NewTracer

func NewTracer[T TraceResponce](log *ulog.Log) *Tracer[T]

func (*Tracer[T]) RequireRequestBody added in v0.7.10

func (o *Tracer[T]) RequireRequestBody() bool

func (*Tracer[T]) RequireResponseBody added in v0.7.10

func (o *Tracer[T]) RequireResponseBody() bool

func (*Tracer[T]) Trace

func (o *Tracer[T]) Trace(r T)

func (*Tracer[T]) WithFilter added in v0.5.29

func (o *Tracer[T]) WithFilter(f func(T) bool) *Tracer[T]

func (*Tracer[T]) WithFormat added in v0.2.17

func (o *Tracer[T]) WithFormat(f Format) *Tracer[T]

func (*Tracer[T]) WithFormatError added in v0.2.92

func (o *Tracer[T]) WithFormatError(f Format) *Tracer[T]

func (*Tracer[T]) WithValidate added in v0.3.3

func (o *Tracer[T]) WithValidate(f func(T) bool) *Tracer[T]

Jump to

Keyboard shortcuts

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