Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct { Version Version `yaml:"version" validate:"required,gte=1"` // Version indicates version of the config (may bee ommitted for current version) ListenAddr string `yaml:"listen_addr" validate:"required,hostname_port"` // ListenAddr is the address for webserver to listen in form "host:port" (like "127.0.0.1:8080 or somehost:80") or simply port :8080 to accept connections on any interface. MagicEndpoint string `yaml:"magic_endpoint"` // path to use for magic endpoint Endpoints Endpoints `yaml:"endpoints" validate:"required"` // Endpoints tell Quickstub how to configure stub handlers. }
Config is used to initialize Quickstub, http.Server of http.ServeMux with this package with specific request handlers.
func ParseConfig ¶
type Endpoints ¶
Endpoints keys must be populated with Patterns. Corresponding Response values tell server what to respond when a Pattern matches.
type Pattern ¶
type Pattern string
Pattern must take a form of either request method followed by path as in "POST /post/path" or just the path is in "/some/endpoint". See https://pkg.go.dev/net/http#ServeMux for description of acceptable patterns.
type QuickStub ¶
type QuickStub interface { ListenAndServe() error ListenAndServeTLS(certFile string, keyFile string) error Shutdown(ctx context.Context) error }
QuickStub is the main app interface under the hood it initializes http.Server accepting requests on endpoints provided in the Config and sets up the "magic endpoint" for on the fly reconfiguration of the server.
func NewQuickStub ¶
type Response ¶
type Response struct { Code int `yaml:"code"` // HTTP response code to be returned. Headers map[string]string `yaml:"headers"` // HTTP response headers. Body string `yaml:"body"` // HTTP response body. If string in this field is prefixed with "@" symbol it is considered a path to file to read contents from. }