Documentation ¶
Index ¶
- Constants
- type Client
- func (c Client) Delete(ctx context.Context, request HTTPRequest) (HTTPResult, error)
- func (c Client) Get(ctx context.Context, request HTTPRequest) (HTTPResult, error)
- func (c Client) Patch(ctx context.Context, request HTTPRequest) (rst HTTPResult, err error)
- func (c Client) Post(ctx context.Context, request HTTPRequest) (HTTPResult, error)
- func (c Client) PostForm(ctx context.Context, request HTTPRequest) (HTTPResult, error)
- func (c Client) Put(ctx context.Context, request HTTPRequest) (rst HTTPResult, err error)
- type ErrorListResponse
- type ErrorResponse
- type HTTPHeaders
- type HTTPQueryParams
- type HTTPRequest
- type HTTPResult
- type MessageResponse
- type ResourceCreatedResponse
- type Server
- type ServerInput
Constants ¶
const ContextKeyRequestIPAddress string = "request_ip"
ContextKeyRequestIPAddress is the key of RequestIP information injected into the request context
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client provides methods for making REST requests
func (Client) Delete ¶
func (c Client) Delete(ctx context.Context, request HTTPRequest) (HTTPResult, error)
Delete execute a http DELETE method with application/json headers
func (Client) Get ¶
func (c Client) Get(ctx context.Context, request HTTPRequest) (HTTPResult, error)
Get execute a http GET method
func (Client) Patch ¶
func (c Client) Patch(ctx context.Context, request HTTPRequest) (rst HTTPResult, err error)
Patch execute a http PATCH method with application/json headers
func (Client) Post ¶
func (c Client) Post(ctx context.Context, request HTTPRequest) (HTTPResult, error)
Post execute a http POST method with application/json headers
func (Client) PostForm ¶
func (c Client) PostForm(ctx context.Context, request HTTPRequest) (HTTPResult, error)
PostForm execute a http POST method with "application/x-www-form-urlencoded" headers
func (Client) Put ¶
func (c Client) Put(ctx context.Context, request HTTPRequest) (rst HTTPResult, err error)
Put execute a http PUT method with application/json headers
type ErrorListResponse ¶
type ErrorListResponse struct { TraceID string `json:"trace_id,omitempty"` Errs []errorPayload `json:"errors"` // contains filtered or unexported fields }
ErrorListResponse defines how list of errors should be presented to clients of HTTPServer. It implements fasthttp's HTTPError contract (https://github.com/jackwhelpton/fasthttp-routing/blob/master/error.go#L12), so it keeps its error handling behaviour.
func NewErrorListResponse ¶
func NewErrorListResponse(ctx context.Context, errs ...error) ErrorListResponse
NewErrorListResponse creates a new ErrorListResponse object.
func (ErrorListResponse) Error ¶
func (e ErrorListResponse) Error() string
Error returns the error message.
func (ErrorListResponse) StatusCode ¶
func (e ErrorListResponse) StatusCode() int
StatusCode returns the HTTP status code.
func (ErrorListResponse) WithStatusCode ¶
func (e ErrorListResponse) WithStatusCode(status int) ErrorListResponse
WithStatusCode is a way to explicitly define the desired StatusCode to be sent to the client with an ErrorListResponse.
type ErrorResponse ¶
type ErrorResponse struct { TraceID string `json:"trace_id,omitempty"` Err errorPayload `json:"error"` // contains filtered or unexported fields }
ErrorResponse defines how errors should be presented to clients of HTTPServer. It implements fasthttp's HTTPError contract (https://github.com/jackwhelpton/fasthttp-routing/blob/master/error.go#L12), so it keeps its error handling behaviour.
func NewErrorResponse ¶
func NewErrorResponse(ctx context.Context, err error) ErrorResponse
NewErrorResponse creates a new ErrorResponse object.
func (ErrorResponse) StatusCode ¶
func (e ErrorResponse) StatusCode() int
StatusCode returns the HTTP status code.
type HTTPHeaders ¶
HTTPHeaders is a map containing the relation key=value of the headers used on the http rest request.
type HTTPQueryParams ¶
HTTPQueryParams is a map containing the relation key=value of the query params used on the http rest request
type HTTPRequest ¶
type HTTPRequest struct { URL string Body []byte Headers HTTPHeaders QueryParams HTTPQueryParams }
HTTPRequest are the params used to build a new http rest request
type HTTPResult ¶
HTTPResult are the params returned from the client HTTP request
type MessageResponse ¶
type MessageResponse struct {
Message string `json:"message"`
}
MessageResponse is a generic message that should be sent to a client of HTTP Server.
func NewMessageResponse ¶
func NewMessageResponse(msg string, params ...interface{}) MessageResponse
NewMessageResponse creates a MessageResponse
type ResourceCreatedResponse ¶
ResourceCreatedResponse is is the default response sent when a new resource is created in the system.
func NewResourceCreatedResponse ¶
func NewResourceCreatedResponse(id string) ResourceCreatedResponse
NewResourceCreatedResponse creates a new ResourceCreatedResponse.
func (ResourceCreatedResponse) WithMessage ¶
func (r ResourceCreatedResponse) WithMessage(msg string, params ...interface{}) ResourceCreatedResponse
WithMessage overrides the default message.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is an HTTPServer object that can serve HTTP requests It is based on httpfast implementation
func (Server) HandleRequestInMemory ¶ added in v1.2.0
Handle a request in memory using the server router
Directories ¶
Path | Synopsis |
---|---|
middleware
|
|
Package mocks is a generated GoMock package.
|
Package mocks is a generated GoMock package. |