Documentation ¶
Overview ¶
Package http provides a much simplified API for both the HTTP client and server. It is meant for use in conjunction with ContainerSSH and should not be used for other purposes as the implementation is very ContainerSSH-specific.
Index ¶
- Constants
- func NewServerHandler(requestHandler RequestHandler, logger log.Logger) goHttp.Handler
- func NewServerHandlerNegotiate(requestHandler RequestHandler, logger log.Logger) goHttp.Handler
- type Client
- type RequestEncoding
- type RequestHandler
- type Server
- type ServerRequest
- type ServerResponse
- type TextMarshallable
Constants ¶
const RequestEncodingDefault = ""
RequestEncodingDefault is the default encoding and encodes the body to JSON.
const RequestEncodingJSON = "JSON"
RequestEncodingJSON encodes the body to JSON.
const RequestEncodingWWWURLEncoded = "WWW-URLENCODED"
RequestEncodingWWWURLEncoded encodes the body via www-urlencoded.
Variables ¶
This section is empty.
Functions ¶
func NewServerHandler ¶
func NewServerHandler( requestHandler RequestHandler, logger log.Logger, ) goHttp.Handler
NewServerHandler creates a new simplified HTTP handler that decodes JSON requests and encodes JSON responses.
func NewServerHandlerNegotiate ¶
func NewServerHandlerNegotiate( requestHandler RequestHandler, logger log.Logger, ) goHttp.Handler
NewServerHandlerNegotiate creates a simplified HTTP handler that supports content negotiation for responses.
Types ¶
type Client ¶
type Client interface { // Request queries the specified path on the configured endpoint with the specified method. Request( method string, path string, requestBody interface{}, responseBody interface{}, ) (statusCode int, err error) // RequestURL requests a URL irrespective of the endpoint configured on the client. RequestURL( method string, url string, requestBody interface{}, responseBody interface{}, ) (statusCode int, err error) // Get queries the configured endpoint with the path providing the response in the responseBody structure. It // returns the HTTP status code and any potential errors. Get( path string, responseBody interface{}, ) (statusCode int, err error) // Post queries the configured endpoint with the path, sending the requestBody and providing the // response in the responseBody structure. It returns the HTTP status code and any potential errors. Post( path string, requestBody interface{}, responseBody interface{}, ) (statusCode int, err error) // Put queries the configured endpoint with the path, sending the requestBody and providing the // response in the responseBody structure. It returns the HTTP status code and any potential errors. Put( path string, requestBody interface{}, responseBody interface{}, ) (statusCode int, err error) // Patch queries the configured endpoint with the path, sending the requestBody and providing the // response in the responseBody structure. It returns the HTTP status code and any potential errors. Patch( path string, requestBody interface{}, responseBody interface{}, ) (statusCode int, err error) // Delete queries the configured endpoint with the path, sending the requestBody and providing the // response in the responseBody structure. It returns the HTTP status code and any potential errors. Delete( path string, requestBody interface{}, responseBody interface{}, ) (statusCode int, err error) }
Client is a simplified HTTP interface that ensures that a struct is transported to a remote endpoint properly encoded, and the response is decoded into the response struct.
type RequestEncoding ¶
type RequestEncoding string
RequestEncoding is the method by which the response is encoded.
func (RequestEncoding) Validate ¶
func (r RequestEncoding) Validate() error
Validate validates the RequestEncoding
type RequestHandler ¶
type RequestHandler interface { // OnRequest is a method receiving a request and is able to respond. OnRequest(request ServerRequest, response ServerResponse) error }
RequestHandler is an interface containing a simple controller receiving a request and providing a response.
type ServerRequest ¶
type ServerRequest interface { // Decode decodes the raw request into the provided target from a JSON format. It provides an // error if the decoding failed, which should be passed back through the request handler. Decode(target interface{}) error }
ServerRequest is a testdata structure providing decoding from the raw request.
type ServerResponse ¶
type ServerResponse interface { // SetStatus sets the HTTP status code SetStatus(statusCode uint16) // SetBody sets the object of the response which will be encoded as JSON. SetBody(interface{}) }
ServerResponse is a response structure that can be used by the RequestHandler to set the response details.
type TextMarshallable ¶
type TextMarshallable interface { // MarshalText converts the object to a text representation safe to output on the web interface. MarshalText() string }
TextMarshallable is an interface that lets an object be converted to user-facing text.