Documentation ¶
Index ¶
- Variables
- func Bearer(token string) string
- func DiscardResponseBody(resp *http.Response)
- func DumpRequest(r *http.Request) string
- func ErrorResponse(w http.ResponseWriter, code int, err error)
- func Is1xx(code int) bool
- func Is2xx(code int) bool
- func Is3xx(code int) bool
- func Is4xx(code int) bool
- func Is5xx(code int) bool
- func MarshalResponse(w http.ResponseWriter, status int, response interface{})
- func MustGetRequest(ctx context.Context, url string) *http.Request
- func MustNewRequest(ctx context.Context, method, url string, body io.Reader) *http.Request
- func MustPostRequest(ctx context.Context, url string, body io.Reader) *http.Request
- func MustPutRequest(ctx context.Context, url string, body io.Reader) *http.Request
- func NewClient() *http.Client
- func NewConnectRequest(ctx context.Context, url string, body io.Reader) (*http.Request, error)
- func NewDeleteRequest(ctx context.Context, url string, body io.Reader) (*http.Request, error)
- func NewGetRequest(ctx context.Context, url string) (*http.Request, error)
- func NewHeadRequest(ctx context.Context, url string) (*http.Request, error)
- func NewOptionsRequest(ctx context.Context, url string, body io.Reader) (*http.Request, error)
- func NewPatchRequest(ctx context.Context, url string, body io.Reader) (*http.Request, error)
- func NewPostRequest(ctx context.Context, url string, body io.Reader) (*http.Request, error)
- func NewPutRequest(ctx context.Context, url string, body io.Reader) (*http.Request, error)
- func NewRequest(ctx context.Context, method, url string, body io.Reader) (*http.Request, error)
- func NewTraceRequest(ctx context.Context, url string, body io.Reader) (*http.Request, error)
- func NoopHandler(http.ResponseWriter, *http.Request)
- func ReturnBadRequest(w http.ResponseWriter, err error)
- func ReturnNotFound(w http.ResponseWriter)
- func ReturnOK(w http.ResponseWriter)
- func ReturnOKJSON(w http.ResponseWriter, data interface{})
- func ReturnRedirect(w http.ResponseWriter)
- func UnmarshalRequest(w http.ResponseWriter, r *http.Request, data interface{}) (code int, err error)
- type Doer
- type Error
- type Server
- type ServerConfig
Constants ¶
This section is empty.
Variables ¶
var NoBody = http.NoBody
Functions ¶
func DiscardResponseBody ¶ added in v0.4.3
DiscardResponseBody reads and closes http.Response.Body.
func DumpRequest ¶ added in v0.4.5
func ErrorResponse ¶ added in v0.1.2
func ErrorResponse(w http.ResponseWriter, code int, err error)
ErrorResponse return and error wrapped into JSON. If the err is httpx.Error, code parameter is ignoted and httpx.Error.Code is used. If the err is nil just status code is returned.
func MarshalResponse ¶
func MarshalResponse(w http.ResponseWriter, status int, response interface{})
MarshalResponse writes an object to the http.ResponseWriter or a fallback error.
func MustGetRequest ¶ added in v0.4.2
MustGetRequest returns a new http.Request with GET method or panics on error.
func MustNewRequest ¶
MustNewRequest returns a new http.Request or panics on error.
func MustPostRequest ¶ added in v0.4.2
MustPostRequest returns a new http.Request with POST method or panics on error.
func MustPutRequest ¶ added in v0.4.4
MustPutRequest returns a new http.Request with PUT method or panics on error.
func NewConnectRequest ¶ added in v0.4.2
NewConnectRequest returns a new http.Request with CONNECT method.
func NewDeleteRequest ¶ added in v0.4.2
NewDeleteRequest returns a new http.Request with DELETE method.
func NewGetRequest ¶ added in v0.2.0
NewGetRequest returns a new http.Request with GET method.
func NewHeadRequest ¶ added in v0.4.2
NewHeadRequest returns a new http.Request with HEAD method.
func NewOptionsRequest ¶ added in v0.4.2
NewOptionsRequest returns a new http.Request with OPTIONS method.
func NewPatchRequest ¶ added in v0.4.2
NewPatchRequest returns a new http.Request with PATCH method.
func NewPostRequest ¶ added in v0.2.0
NewPostRequest returns a new http.Request with POST method.
func NewPutRequest ¶ added in v0.4.2
NewPutRequest returns a new http.Request with PUT method.
func NewRequest ¶
NewRequest returns a new http.Request.
func NewTraceRequest ¶ added in v0.4.2
NewTraceRequest returns a new http.Request with TRACE method.
func NoopHandler ¶ added in v0.4.5
func NoopHandler(http.ResponseWriter, *http.Request)
NoopHandler just return 200 OK. Useful for prototyping.
func ReturnBadRequest ¶ added in v0.2.0
func ReturnBadRequest(w http.ResponseWriter, err error)
func ReturnNotFound ¶ added in v0.2.0
func ReturnNotFound(w http.ResponseWriter)
func ReturnOK ¶ added in v0.2.0
func ReturnOK(w http.ResponseWriter)
func ReturnOKJSON ¶ added in v0.3.3
func ReturnOKJSON(w http.ResponseWriter, data interface{})
func ReturnRedirect ¶ added in v0.2.0
func ReturnRedirect(w http.ResponseWriter)
func UnmarshalRequest ¶
func UnmarshalRequest(w http.ResponseWriter, r *http.Request, data interface{}) (code int, err error)
UnmarshalRequest as JSON with well defined error handling.
Types ¶
type Error ¶ added in v0.1.3
type Error struct { Code int `json:"code,omitempty"` Type string `json:"type,omitempty"` Message string `json:"msg,omitempty"` }
Error for a request.
type Server ¶ added in v0.1.4
type Server struct {
// contains filtered or unexported fields
}
Server for HTTP protocol.
func NewServer ¶ added in v0.1.4
func NewServer(config *ServerConfig) (*Server, error)
NewServer returns a new Server.
type ServerConfig ¶ added in v0.1.4
type ServerConfig struct { Addr string Handler http.Handler NoHTTP2 bool TLSConfig *tls.Config // TODO: enable option HeartbeatPath string HeartbeatHandler http.HandlerFunc ReadTimeout time.Duration ReadHeaderTimeout time.Duration WriteTimeout time.Duration IdleTimeout time.Duration MaxHeaderBytes int }
ServerConfig configures Server.
func (*ServerConfig) Validate ¶ added in v0.1.4
func (c *ServerConfig) Validate() error
Validate the config.