api

package
v0.0.0-...-a9a37cd Latest Latest
Warning

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

Go to latest
Published: May 7, 2021 License: MIT Imports: 14 Imported by: 0

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

View Source
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

func IdleTimeout(d time.Duration) Option

IdleTimeout sets the server's IdleTimeout value to the given duration.

func ListenAddress

func ListenAddress(addr string) Option

ListenAddress specifies the server's listen address.

func ReadHeaderTimeout

func ReadHeaderTimeout(d time.Duration) Option

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

func (s *Server) ListenAndServe() error

ListenAndServe binds the server to its address and serves incoming requests.

func (*Server) ListenAndServeTLS

func (s *Server) ListenAndServeTLS(cert, pkey string) error

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.

Jump to

Keyboard shortcuts

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