Documentation ¶
Overview ¶
Package api provides a HTTP(S) server that serves a REST API that serves financial data for a subset of stock symbols.
In the absence of additional middleware to handle details such as compression, this server assumes those transport details are handled by a reverse proxy.
Index ¶
Constants ¶
const ( // DefaultIdleTimeout represents the duration the server will allow clients // to remain idle. DefaultIdleTimeout = time.Minute // DefaultListenAddress is the default host:port on which the API server // will listen for client connections. DefaultListenAddress = ":18081" // DefaultReadHeaderTimeout is the default duration during which the API // server will wait for the client to send request headers. DefaultReadHeaderTimeout = 30 * time.Second )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option func(*Server)
func DisableInstrumentation ¶
func DisableInstrumentation() Option
DisableInstrumentation turns off server instrumentation.
func IdleTimeout ¶
IdleTimeout sets the server's IdleTimeout value to the given duration.
func ListenAddress ¶
ListenAddress specifies the server's listen address.
func ReadHeaderTimeout ¶
ReadHeaderTimeout sets the server's ReadHeaderTimeout value to the given duration.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is a web server that serves up the REST API for this application. Currently, it allows clients to request the latest stock quotes for a given set of stocks.
func New ¶
func New(ctx context.Context, p history.Provider, log *zap.SugaredLogger, options ...Option) ( *Server, error)
New returns a pointer to an API Server.
Defaults:
IdleTimeout = time.Minute ListenAddress = ":18081" ReadHeaderTimeout = 30 * time.Second
func (*Server) ListenAndServe ¶
ListenAndServe binds the server to its address and serves incoming requests.
func (*Server) ListenAndServeTLS ¶
ListenAndServeTLS binds the server to its address and serves incoming requests over TLS.
Note: This is best handled by a reverse proxy like Nginx or Caddy, particularly one that speaks the ACME protocol and can make TLS integration virtually effortless.