http

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2019 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultClient denotes the client used for all default accessors.
	DefaultClient *Client
	// ErrInvalidRequest occurs when trying to create a new request using malformed parameters.
	ErrInvalidRequest = errors.New("Invalid request")
	// ErrRequestFailed occurs when sending a request or receiving a response failed.
	ErrRequestFailed = errors.New("Request failed")
)
View Source
var (
	// ErrGraceShutdown is returned when the server has been gracefully shut down.
	ErrGraceShutdown = errors.New("Server gracefully shut down")
	// ErrServeFailed occurs when an error occurs during http serving.
	ErrServeFailed = errors.New("Serving failed")
)

Functions

This section is empty.

Types

type Client

type Client struct {
	DefaultHeader Header
	// DisableSSLCheck can be set to true, to accept invalid and self-signed certificates in HTTPS connections.
	DisableSSLCheck bool
	// RequestResponder denotes the technical implementation for sending requests. Overwrite this property to inject mocked responses.
	RequestResponder func(req *Request) (*Response, errors.Error)
}

Client is used to send or mock HTTP requests.

func NewClient

func NewClient() *Client

NewClient returns a new HTTP client to send requests.

func (*Client) Do

func (client *Client) Do(method RequestMethod, url string, f func(*Request) errors.Error) (*Response, errors.Error)

Do requests the given url using the given method and returns the response. Use the callback function f to modify the request directly before sending.

type Header = http.Header

Header is an alias for the default 'net/http' Header type.

type Request

type Request = http.Request

Request is an alias for the default 'net/http' Request type.

type RequestMethod

type RequestMethod string

RequestMethod denotes a HTTP request method.

const (
	// MethodGet specifies the HTTP GET method.
	MethodGet RequestMethod = "GET"
	// MethodHead specifies the HTTP HEAD method.
	MethodHead RequestMethod = "HEAD"
	// MethodPost specifies the HTTP POST method.
	MethodPost RequestMethod = "POST"
	// MethodPut specifies the HTTP PUT method.
	MethodPut RequestMethod = "PUT"
	// MethodDelete specifies the HTTP DELETE method.
	MethodDelete RequestMethod = "DELETE"
	// MethodConnect specifies the HTTP CONNECT method.
	MethodConnect RequestMethod = "CONNECT"
	// MethodOptions specifies the HTTP OPTIONS method.
	MethodOptions RequestMethod = "OPTIONS"
	// MethodTrace specifies the HTTP TRACE method.
	MethodTrace RequestMethod = "TRACE"
)

func (RequestMethod) String

func (m RequestMethod) String() string

type Response

type Response = http.Response

Response is an alias for the default 'net/http' Response type.

func Do

func Do(method RequestMethod, url string, f func(*Request) errors.Error) (*Response, errors.Error)

Do performs a request using the default client.

type Server

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

Server contains http web server functionality with kubernetes probes and prometheus metrics. It can serve an arbitrary collection of services.

func NewServer

func NewServer(config *ServerConfig) (*Server, errors.Error)

NewServer returns a new instance of Server to handle web requests.

func (*Server) RegisterService

func (server *Server) RegisterService(name string, s Service) errors.Error

RegisterService registers a new named service in the server. The name is used to identify the server in probes.

func (*Server) Run

func (server *Server) Run() errors.Error

Run executes the server and gracefully shuts it down when a system signal is received.

func (*Server) RunAsync

func (server *Server) RunAsync(callback func(errors.Error)) errors.Error

RunAsync begins asynchronuous handling of incoming http requests. Use Shutdown() to gracefully shut down the sever.

func (*Server) Shutdown

func (server *Server) Shutdown() errors.Error

Shutdown gracefully stops the http server.

type ServerConfig

type ServerConfig struct {
	ListenAddress string `json:"listenAddress"`
	SubSystemName string `json:"subsystemName,omitempty"`
}

ServerConfig contains all web server specific configuration parameters.

type Service

type Service interface {
	RegisterRoutes(*gin.Engine)
	BeginServing()
	StopServing()
	Healthy() errors.Error
	Ready() errors.Error
}

Service defines functionality for web services that can be served.

Jump to

Keyboard shortcuts

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