http

package module
v1.99.0 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2021 License: MIT Imports: 20 Imported by: 2

Documentation

Index

Constants

View Source
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 added in v1.2.1

type Client struct {
	// contains filtered or unexported fields
}

Client provides methods for making REST requests

func NewClient added in v1.2.1

func NewClient(timeout time.Duration) Client

NewClient creates a new Client instance

func (Client) Delete added in v1.2.1

func (c Client) Delete(ctx context.Context, request HTTPRequest) (HTTPResult, error)

Delete execute a http DELETE method with application/json headers

func (Client) Get added in v1.2.1

func (c Client) Get(ctx context.Context, request HTTPRequest) (HTTPResult, error)

Get execute a http GET method

func (Client) Patch added in v1.2.1

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 added in v1.2.1

func (c Client) Post(ctx context.Context, request HTTPRequest) (HTTPResult, error)

Post execute a http POST method with application/json headers

func (Client) PostForm added in v1.2.1

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 added in v1.2.1

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 added in v1.1.0

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 added in v1.1.0

func NewErrorListResponse(ctx context.Context, errs ...error) ErrorListResponse

NewErrorListResponse creates a new ErrorListResponse object.

func (ErrorListResponse) Error added in v1.1.0

func (e ErrorListResponse) Error() string

Error returns the error message.

func (ErrorListResponse) StatusCode added in v1.1.0

func (e ErrorListResponse) StatusCode() int

StatusCode returns the HTTP status code.

func (ErrorListResponse) WithStatusCode added in v1.1.0

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 added in v1.1.0

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 added in v1.1.0

func NewErrorResponse(ctx context.Context, err error) ErrorResponse

NewErrorResponse creates a new ErrorResponse object.

func (ErrorResponse) Error added in v1.1.0

func (e ErrorResponse) Error() string

Error returns the error message.

func (ErrorResponse) StatusCode added in v1.1.0

func (e ErrorResponse) StatusCode() int

StatusCode returns the HTTP status code.

type HTTPHeaders added in v1.2.1

type HTTPHeaders map[string]string

HTTPHeaders is a map containing the relation key=value of the headers used on the http rest request.

type HTTPQueryParams added in v1.2.1

type HTTPQueryParams map[string]string

HTTPQueryParams is a map containing the relation key=value of the query params used on the http rest request

type HTTPRequest added in v1.2.2

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 added in v1.2.2

type HTTPResult struct {
	StatusCode int
	Response   []byte
}

HTTPResult are the params returned from the client HTTP request

type MessageResponse added in v1.2.0

type MessageResponse struct {
	Message string `json:"message"`
}

MessageResponse is a generic message that should be sent to a client of HTTP Server.

func NewMessageResponse added in v1.2.0

func NewMessageResponse(msg string, params ...interface{}) MessageResponse

NewMessageResponse creates a MessageResponse

type ResourceCreatedResponse added in v1.2.0

type ResourceCreatedResponse struct {
	ID      string `json:"id"`
	Message string `json:"message"`
}

ResourceCreatedResponse is is the default response sent when a new resource is created in the system.

func NewResourceCreatedResponse added in v1.2.0

func NewResourceCreatedResponse(id string) ResourceCreatedResponse

NewResourceCreatedResponse creates a new ResourceCreatedResponse.

func (ResourceCreatedResponse) WithMessage added in v1.2.0

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 NewServer

func NewServer(in ServerInput) Server

NewServer creates a new instance of Server

func (Server) Run

func (s Server) Run() error

Run listen and serves HTTP requests at the Port specified in Server construction

type ServerInput

type ServerInput struct {
	Port           int
	AllowedOrigins []string
	AllowedHeaders []string
	ExposedHeaders []string
	Handler        func(*routing.Router)
	Logger         logger
}

ServerInput encapsulates the necessary Inputs to initialize a Server

Directories

Path Synopsis
middleware

Jump to

Keyboard shortcuts

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