dhttp

package
v0.0.0-...-800adf3 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2022 License: ISC Imports: 24 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadCertificates

func LoadCertificates(certificates []string) (*x509.CertPool, error)

Types

type APIClient

type APIClient struct {
	*Client
}

func NewAPIClient

func NewAPIClient(c *Client) *APIClient

func (*APIClient) SendJSONRequest

func (c *APIClient) SendJSONRequest(method string, uri *url.URL, header map[string]string, value interface{}) (*http.Response, error)

func (*APIClient) SendRequest

func (c *APIClient) SendRequest(method string, uri *url.URL, header map[string]string, body io.Reader) (*http.Response, error)

type APIError

type APIError struct {
	Message string       `json:"error"`
	Code    string       `json:"code,omitempty"`
	Data    APIErrorData `json:"data,omitempty"`
}

type APIErrorData

type APIErrorData map[string]interface{}

type APIRequestError

type APIRequestError struct {
	Status   int
	APIError *APIError
	Message  string
}

func (APIRequestError) Error

func (err APIRequestError) Error() string

type Client

type Client struct {
	Cfg ClientCfg
	Log *dlog.Logger

	Client *http.Client
	// contains filtered or unexported fields
}

func NewClient

func NewClient(cfg ClientCfg) (*Client, error)

func (*Client) DialTLSContext

func (c *Client) DialTLSContext(ctx context.Context, network, address string) (net.Conn, error)

func (*Client) Do

func (c *Client) Do(req *http.Request) (*http.Response, error)

func (*Client) SendRequest

func (c *Client) SendRequest(method string, uri *url.URL, header map[string]string, body io.Reader) (*http.Response, error)

func (*Client) Terminate

func (c *Client) Terminate()

type ClientCfg

type ClientCfg struct {
	Log *dlog.Logger `json:"-"`

	LogRequests bool `json:"log_requests"`

	TLS *TLSClientCfg `json:"tls"`

	Header http.Header `json:"-"`
}

func (*ClientCfg) Check

func (cfg *ClientCfg) Check(c *check.Checker)

type ErrorHandler

type ErrorHandler func(*Handler, int, string, string, APIErrorData)

type Handler

type Handler struct {
	Server *Server
	Log    *dlog.Logger

	ClientAddress string
	RequestId     string

	Pattern string
	Method  string
	RouteId string
	Query   url.Values

	Request        *http.Request
	ResponseWriter http.ResponseWriter

	StartTime time.Time
	// contains filtered or unexported fields
}

func (*Handler) HasQueryParameter

func (h *Handler) HasQueryParameter(name string) bool

func (*Handler) JSONRequestData

func (h *Handler) JSONRequestData(dest interface{}) error

func (*Handler) JSONRequestObject

func (h *Handler) JSONRequestObject(obj check.Object) error

func (*Handler) JSONRequestObject2

func (h *Handler) JSONRequestObject2(obj check.Object, fn func(*check.Checker)) error

func (*Handler) QueryParameter

func (h *Handler) QueryParameter(name string) string

func (*Handler) Reply

func (h *Handler) Reply(status int, r io.Reader)

func (*Handler) ReplyCompactJSON

func (h *Handler) ReplyCompactJSON(status int, value interface{})

func (*Handler) ReplyEmpty

func (h *Handler) ReplyEmpty(status int)

func (*Handler) ReplyError

func (h *Handler) ReplyError(status int, code, format string, args ...interface{})

func (*Handler) ReplyErrorData

func (h *Handler) ReplyErrorData(status int, code string, data APIErrorData, format string, args ...interface{})

func (*Handler) ReplyInternalError

func (h *Handler) ReplyInternalError(status int, format string, args ...interface{})

func (*Handler) ReplyJSON

func (h *Handler) ReplyJSON(status int, value interface{})

func (*Handler) ReplyNotImplemented

func (h *Handler) ReplyNotImplemented(feature string)

func (*Handler) ReplyRedirect

func (h *Handler) ReplyRedirect(status int, uri string)

func (*Handler) ReplyRequestBodyValidationErrors

func (h *Handler) ReplyRequestBodyValidationErrors(err check.ValidationErrors)

func (*Handler) RequestData

func (h *Handler) RequestData() ([]byte, error)

func (*Handler) RouteVariable

func (h *Handler) RouteVariable(name string) string

type InvalidQueryParameterError

type InvalidQueryParameterError struct {
	Name    string
	Message string
}

func NewInvalidQueryParameterError

func NewInvalidQueryParameterError(name, format string, args ...interface{}) *InvalidQueryParameterError

func (InvalidQueryParameterError) Error

func (err InvalidQueryParameterError) Error() string

type ResponseWriter

type ResponseWriter struct {
	Status           int
	ResponseBodySize int
	// contains filtered or unexported fields
}

func NewResponseWriter

func NewResponseWriter(w http.ResponseWriter) *ResponseWriter

func (*ResponseWriter) Header

func (w *ResponseWriter) Header() http.Header

func (*ResponseWriter) Write

func (w *ResponseWriter) Write(data []byte) (int, error)

func (*ResponseWriter) WriteHeader

func (w *ResponseWriter) WriteHeader(status int)

type RoundTripper

type RoundTripper struct {
	Cfg *ClientCfg
	Log *dlog.Logger

	http.RoundTripper
}

func NewRoundTripper

func NewRoundTripper(rt http.RoundTripper, cfg *ClientCfg) *RoundTripper

func (*RoundTripper) RoundTrip

func (rt *RoundTripper) RoundTrip(req *http.Request) (*http.Response, error)

type RouteFunc

type RouteFunc func(*Handler)

type Server

type Server struct {
	Cfg ServerCfg
	Log *dlog.Logger

	Router *chi.Mux
	// contains filtered or unexported fields
}

func NewServer

func NewServer(cfg ServerCfg) (*Server, error)

func (*Server) Route

func (s *Server) Route(pattern, method string, routeFunc RouteFunc)

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, req *http.Request)

func (*Server) Start

func (s *Server) Start() error

func (*Server) Stop

func (s *Server) Stop()

func (*Server) Terminate

func (s *Server) Terminate()

type ServerCfg

type ServerCfg struct {
	Log       *dlog.Logger `json:"-"`
	ErrorChan chan<- error `json:"-"`

	ErrorHandler ErrorHandler `json:"-"`

	Address string `json:"address"`

	TLS *TLSServerCfg `json:"tls,omitempty"`

	HideInternalErrors     bool `json:"hide_internal_errors"`
	HideSuccessfulRequests bool `json:"hide_successful_requests"`
}

func (*ServerCfg) Check

func (cfg *ServerCfg) Check(c *check.Checker)

type TLSClientCfg

type TLSClientCfg struct {
	CACertificates []string            `json:"ca_certificates"`
	PublicKeyPins  map[string][]string `json:"public_key_pins"`
}

func (*TLSClientCfg) Check

func (cfg *TLSClientCfg) Check(c *check.Checker)

type TLSServerCfg

type TLSServerCfg struct {
	Certificate string `json:"certificate"`
	PrivateKey  string `json:"private_key"`
}

func (*TLSServerCfg) Check

func (cfg *TLSServerCfg) Check(c *check.Checker)

Jump to

Keyboard shortcuts

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