Documentation ¶
Index ¶
- Constants
- func AdaptativeErrorHandler(h *Handler, status int, code string, msg string, data ErrorData)
- func DefaultErrorHandler(h *Handler, status int, code string, msg string, data ErrorData)
- func JSONErrorHandler(h *Handler, status int, code string, msg string, data ErrorData)
- func LoadCertificates(certificates []string) (*x509.CertPool, error)
- func ParseAbsoluteURI(s string, schemes []string) (*url.URL, error)
- func ParseHTTPSURI(s string) (*url.URL, error)
- func ParseHTTPURI(s string) (*url.URL, error)
- func RequestAcceptsText(req *http.Request) bool
- type APIClient
- type APIClientCfg
- type Client
- type ClientCfg
- type ErrorData
- type ErrorHandler
- type Handler
- func (h *Handler) HasQueryParameter(name string) bool
- func (h *Handler) JSONRequestData(dest interface{}) error
- func (h *Handler) JSONRequestDataExt(data []byte, dest interface{}, fn func(*ejson.Validator)) error
- func (h *Handler) PathVariable(name string) string
- func (h *Handler) QueryParameter(name string) string
- func (h *Handler) Reply(status int, r io.Reader)
- func (h *Handler) ReplyChunk(r io.Reader) error
- func (h *Handler) ReplyCompactJSON(status int, value interface{})
- func (h *Handler) ReplyEmpty(status int)
- func (h *Handler) ReplyError(status int, code, format string, args ...interface{})
- func (h *Handler) ReplyErrorData(status int, code string, data ErrorData, format string, args ...interface{})
- func (h *Handler) ReplyFile(filePath string)
- func (h *Handler) ReplyInternalError(status int, format string, args ...interface{})
- func (h *Handler) ReplyJSON(status int, value interface{})
- func (h *Handler) ReplyJSONChunk(value interface{}) error
- func (h *Handler) ReplyNotImplemented(feature string)
- func (h *Handler) ReplyRedirect(status int, uri string)
- func (h *Handler) ReplyText(status int, body string)
- func (h *Handler) ReplyValidationErrors(err ejson.ValidationErrors)
- func (h *Handler) RequestData() ([]byte, error)
- func (h *Handler) SetCookie(cookie *http.Cookie)
- func (h *Handler) UUIDQueryParameter(name string) (uuid.UUID, error)
- type JSONError
- type ResponseWriter
- type RoundTripper
- type RouteFunc
- type Server
- type ServerCfg
- type TLSClientCfg
- type TLSServerCfg
- type ValidationJSONErrorData
Constants ¶
View Source
const ( DefaultClientConnectionTimeout = 30 // seconds DefaultClientRequestTimeout = 30 // seconds )
Variables ¶
This section is empty.
Functions ¶
func AdaptativeErrorHandler ¶
func DefaultErrorHandler ¶
func JSONErrorHandler ¶
func RequestAcceptsText ¶
Types ¶
type APIClient ¶
type APIClient struct { Client *http.Client BearerToken string Cookie *http.Cookie // contains filtered or unexported fields }
func NewAPIClient ¶
func NewAPIClient(cfg APIClientCfg) (*APIClient, error)
type APIClientCfg ¶
type Client ¶
type Client struct { Cfg ClientCfg Log *log.Logger Client *http.Client // contains filtered or unexported fields }
func (*Client) CloseConnections ¶
func (c *Client) CloseConnections()
func (*Client) DialTLSContext ¶
type ClientCfg ¶
type ClientCfg struct { Log *log.Logger `json:"-"` ConnectionTimeout *int `json:"connection_timeout"` // seconds RequestTimeout *int `json:"request_timeout"` // seconds LogRequests bool `json:"log_requests"` DisableRedirections bool `json:"disable_redirections"` TLS *TLSClientCfg `json:"tls"` Header http.Header `json:"-"` }
func (*ClientCfg) ValidateJSON ¶
func (cfg *ClientCfg) ValidateJSON(v *ejson.Validator)
type Handler ¶
type Handler struct { Server *Server Log *log.Logger Method string PathPattern string RouteId string // based on the method and path pattern Request *http.Request Query url.Values ResponseWriter http.ResponseWriter ClientAddress string // optional RequestId string // optional // contains filtered or unexported fields }
func (*Handler) HasQueryParameter ¶
func (*Handler) JSONRequestData ¶
func (*Handler) JSONRequestDataExt ¶
func (h *Handler) JSONRequestDataExt(data []byte, dest interface{}, fn func(*ejson.Validator)) error
The extended version of JSONRequestData is useful in specific situations:
1. JSON data must be extracted and/or transformed from the request body before decoding.
2. Extra validation steps must be performed with the same Validator object.
func (*Handler) PathVariable ¶
func (*Handler) QueryParameter ¶
func (*Handler) ReplyCompactJSON ¶
func (*Handler) ReplyEmpty ¶
func (*Handler) ReplyError ¶
func (*Handler) ReplyErrorData ¶
func (*Handler) ReplyInternalError ¶
func (*Handler) ReplyJSONChunk ¶
func (*Handler) ReplyNotImplemented ¶
func (*Handler) ReplyRedirect ¶
func (*Handler) ReplyValidationErrors ¶
func (h *Handler) ReplyValidationErrors(err ejson.ValidationErrors)
func (*Handler) RequestData ¶
func (*Handler) UUIDQueryParameter ¶
type JSONError ¶
type JSONError struct { Code string `json:"code,omitempty"` Message string `json:"message"` RawData json.RawMessage `json:"data,omitempty"` Data ErrorData `json:"-"` }
func (*JSONError) DecodeData ¶
func (*JSONError) MarshalJSON ¶
func (*JSONError) UnmarshalJSON ¶
type ResponseWriter ¶
type ResponseWriter struct { Status int // contains filtered or unexported fields }
func NewResponseWriter ¶
func NewResponseWriter(w http.ResponseWriter) *ResponseWriter
func (*ResponseWriter) Flush ¶
func (w *ResponseWriter) Flush()
func (*ResponseWriter) Header ¶
func (w *ResponseWriter) Header() http.Header
func (*ResponseWriter) Hijack ¶
func (w *ResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error)
func (*ResponseWriter) WriteHeader ¶
func (w *ResponseWriter) WriteHeader(status int)
type RoundTripper ¶
type RoundTripper struct { Cfg *ClientCfg Log *log.Logger http.RoundTripper }
func NewRoundTripper ¶
func NewRoundTripper(rt http.RoundTripper, cfg *ClientCfg) *RoundTripper
type Server ¶
type Server struct { Cfg ServerCfg Log *log.Logger // contains filtered or unexported fields }
type ServerCfg ¶
type ServerCfg struct { Log *log.Logger `json:"-"` ErrorChan chan<- error `json:"-"` InfluxClient *influx.Client `json:"-"` Name string `json:"-"` ErrorHandler ErrorHandler `json:"-"` DataDirectory string `json:"-"` Address string `json:"address"` TLS *TLSServerCfg `json:"tls"` LogSuccessfulRequests bool `json:"log_successful_requests"` HideInternalErrors bool `json:"hide_internal_errors"` MethodLessRouteIds bool `json:"method_less_route_ids"` }
func (*ServerCfg) ValidateJSON ¶
func (cfg *ServerCfg) ValidateJSON(v *ejson.Validator)
type TLSClientCfg ¶
type TLSClientCfg struct {
CACertificates []string `json:"ca_certificates"`
}
type TLSServerCfg ¶
type TLSServerCfg struct { Certificate string `json:"certificate"` PrivateKey string `json:"private_key"` }
func (*TLSServerCfg) ValidateJSON ¶
func (cfg *TLSServerCfg) ValidateJSON(v *ejson.Validator)
type ValidationJSONErrorData ¶
type ValidationJSONErrorData struct {
ValidationErrors ejson.ValidationErrors `json:"validation_errors"`
}
Click to show internal directories.
Click to hide internal directories.