Documentation ¶
Overview ¶
Package restserver provides building blocks to implement a mocked version of out-of-process components Ubuntu Pro for WSL depend on that talk REST, such as MS Store API and the Contracts Server backend DO NOT USE IN PRODUCTION
Package restserver provides building blocks to implement a mocked version of out-of-process components Ubuntu Pro for WSL depend on that talk REST, such as MS Store API and the Contracts Server backend DO NOT USE IN PRODUCTION
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type App ¶
type App struct { // Name of the application as shown in the help messages. Name string // Description fo the application as shown in the long help messages. Description string // The default settings that the application will pass to the server instance. DefaultSettings Settings // A function capable of translating from the Settings interface into the concrete implementation a particular server will need to run. ServerFactory func(Settings) Server }
App encapsulates creating and managing the CLI and lifecycle.
type Endpoint ¶
type Endpoint struct { // OnSuccess is the response returned in the happy path. OnSuccess Response // Disabled disables the endpoint. Disabled bool // Blocked means that a response will not be sent back, instead it'll block until the server is stopped. Blocked bool }
Endpoint contains settings for an API endpoint behaviour. Can be modified for testing purposes.
func NewEndpoint ¶
func NewEndpoint() Endpoint
NewEndpoint returns a minimal endpoint configured for success.
type Response ¶
Response contains settings for an API endpoint response behaviour. Can be modified for testing purposes.
type Server ¶
type Server interface { Stop() error Serve(ctx context.Context, addr string) error Address() string }
Server is the minimal interface mock REST servers must provide to the Application.
type ServerBase ¶
ServerBase is the core building block of configurable mock REST servers.
func (*ServerBase) Address ¶
func (s *ServerBase) Address() string
Address returns the server network address configured during Serve. Empty string is returned when called before Serve.
func (*ServerBase) Serve ¶
func (s *ServerBase) Serve(ctx context.Context, address string) error
Serve starts a new HTTP server listening on address with responses defined according to Server Settings. Use Stop to Stop the server and release resources.
func (*ServerBase) ValidateRequest ¶
func (s *ServerBase) ValidateRequest(w http.ResponseWriter, r *http.Request, wantMethod string, endpoint Endpoint) (err error)
ValidateRequest extracts common boilerplate used to validate the request from endpoints.