Documentation
¶
Index ¶
- Constants
- Variables
- type BasicAuth
- type Client
- type ClientConfig
- type Request
- func (r *Request) AddCookie(cookie *http.Cookie)
- func (r *Request) AddHeader(key, value string)
- func (r *Request) Build(ctx context.Context) (*http.Request, error)
- func (r *Request) SetBody(contentType string, body []byte)
- func (r *Request) SetFormBody(values url.Values)
- func (r *Request) SetHeader(key, value string)
- func (r *Request) SetJSONBody(value any) error
- type RequestSnapshot
- type Response
- type Server
- type ServerConfig
Constants ¶
View Source
const ( ContentTypeJSON = "application/json" ContentTypeFormURLEncoded = "application/x-www-form-urlencoded" ContentTypeTextPlain = "text/plain; charset=utf-8" ContentTypeOctetStream = "application/octet-stream" )
View Source
const ( MethodGet = http.MethodGet MethodHead = http.MethodHead MethodPost = http.MethodPost MethodPut = http.MethodPut MethodPatch = http.MethodPatch MethodDelete = http.MethodDelete MethodConnect = http.MethodConnect MethodOptions = http.MethodOptions MethodTrace = http.MethodTrace )
Variables ¶
View Source
var ( ErrContextRequired = errors.New("httpx: context is required") ErrNilRequest = errors.New("httpx: request is required") ErrRequestMethodRequired = errors.New("httpx: request method is required") ErrRequestURLRequired = errors.New("httpx: request url is required") ErrRequestAbsoluteURLRequired = errors.New("httpx: request url must be absolute") ErrNilResponse = errors.New("httpx: response is nil") ErrNilHandler = errors.New("httpx: handler is required") ErrNilListener = errors.New("httpx: listener is required") ErrServerAddrRequired = errors.New("httpx: server addr or listener is required") ErrServerAlreadyRunning = errors.New("httpx: server already running") )
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client interface {
Do(context.Context, *Request) (*Response, error)
HTTPClient() *http.Client
CloseIdleConnections()
}
func NewClient ¶ added in v1.2.2
func NewClient(conf *ClientConfig) Client
type ClientConfig ¶ added in v1.2.2
type ClientConfig struct {
Logger *logger.Logger
EnableLogger bool
Trace bool
Timeout time.Duration
HTTPClient *http.Client
Transport *http.Transport
CheckRedirect func(*http.Request, []*http.Request) error
Jar http.CookieJar
MaxIdleConns int
MaxIdleConnsPerHost int
MaxConnsPerHost int
IdleConnTimeout time.Duration
TLSHandshakeTimeout time.Duration
ResponseHeaderTimeout time.Duration
ExpectContinueTimeout time.Duration
// ObservabilitySkipPaths skips metrics, tracing, and access logging for
// matching request paths. Client side defaults to none.
ObservabilitySkipPaths []string
MetricsRegisterer prometheus.Registerer
DisableMetrics bool
}
type Request ¶
type Request struct {
Method string
URL string
Query url.Values
Header http.Header
Body io.Reader
Cookies []*http.Cookie
BasicAuth *BasicAuth
Host string
}
func (*Request) SetFormBody ¶ added in v1.2.2
func (*Request) SetJSONBody ¶ added in v1.2.2
type RequestSnapshot ¶ added in v1.2.2
type Response ¶
type Response struct {
StatusCode int
Status string
Header http.Header
Cookies []*http.Cookie
Body []byte
Duration time.Duration
Request *RequestSnapshot
}
func (*Response) DecodeJSON ¶ added in v1.2.2
type Server ¶ added in v1.0.7
type Server interface {
Start(context.Context, http.Handler) error
Serve(context.Context, net.Listener, http.Handler) error
Shutdown(context.Context) error
Close() error
HTTPServer() *http.Server
}
func NewServer ¶ added in v1.0.7
func NewServer(conf *ServerConfig) Server
type ServerConfig ¶ added in v1.2.2
type ServerConfig struct {
Addr string
Listener net.Listener
Logger *logger.Logger
EnableLogger bool
Trace bool
ReadTimeout time.Duration
ReadHeaderTimeout time.Duration
WriteTimeout time.Duration
IdleTimeout time.Duration
ShutdownTimeout time.Duration
// ObservabilitySkipPaths skips metrics, tracing, and access logging for
// matching request paths. /metrics is always skipped; the default health
// path is skipped only when the framework-managed health endpoint is enabled.
ObservabilitySkipPaths []string
MetricsRegisterer prometheus.Registerer
DisableMetrics bool
DisableHealthEndpoint bool
HealthPath string
HealthHandler http.Handler
}
Click to show internal directories.
Click to hide internal directories.