Documentation ¶
Overview ¶
Package rest implements the HTTP server through which plugins can expose their REST APIs to the outside world.
Index ¶
Constants ¶
const (
// DefaultHTTPPort is used during HTTP server startup unless different port was configured
DefaultHTTPPort = "9191"
)
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct { // Endpoint is a address of HTTP server Endpoint string // ReadTimeout is the maximum duration for reading the entire // request, including the body. // // Because ReadTimeout does not let Handlers make per-request // decisions on each request body's acceptable deadline or // upload rate, most users will prefer to use // ReadHeaderTimeout. It is valid to use them both. ReadTimeout time.Duration // ReadHeaderTimeout is the amount of time allowed to read // request headers. The connection's read deadline is reset // after reading the headers and the Handler can decide what // is considered too slow for the body. ReadHeaderTimeout time.Duration // WriteTimeout is the maximum duration before timing out // writes of the response. It is reset whenever a new // request's header is read. Like ReadTimeout, it does not // let Handlers make decisions on a per-request basis. WriteTimeout time.Duration // IdleTimeout is the maximum amount of time to wait for the // next request when keep-alives are enabled. If IdleTimeout // is zero, the value of ReadTimeout is used. If both are // zero, there is no timeout. IdleTimeout time.Duration // MaxHeaderBytes controls the maximum number of bytes the // server will read parsing the request header's keys and // values, including the request line. It does not limit the // size of the request body. // If zero, DefaultMaxHeaderBytes is used. MaxHeaderBytes int }
Config is a configuration for HTTP server
type Deps ¶
type Deps struct { localdeps.PluginLogDeps // inject // Used to simplify if not whole config needs to be configured HTTPport string //inject optionally }
Deps is here to group injected dependencies of plugin to not mix with other plugin fields.
type HTTPHandlers ¶
type HTTPHandlers interface { // RegisterHTTPHandler propagates to Gorilla mux RegisterHTTPHandler(path string, handler func(formatter *render.Render) http.HandlerFunc, methods ...string) *mux.Route }
HTTPHandlers is an interface that is useful for other plugins that need to register HTTP Handlers. Use this interface as type for the field in terms of dependency injection.
type ListenAndServe ¶
ListenAndServe is a function that used Config & Handler to handle HTTP Requests. It return instance of io.Closer to close the HTTP Server during cleanup.
type Plugin ¶
type Plugin struct { Deps // contains filtered or unexported fields }
Plugin implements the Plugin interface.
func FromExistingServer ¶
func FromExistingServer(listenAndServe ListenAndServe) *Plugin
FromExistingServer is used mainly for testing purpose
Example:
httpmux.FromExistingServer(mock.SetHandler) mock.NewRequest("GET", "/v1/a", nil)