Documentation ¶
Index ¶
- type ApiSpecification
- type Postgres
- type Server
- func (e *Server) DocsHandler(w http.ResponseWriter, _ *http.Request)
- func (e *Server) HealthCheckHandler(w http.ResponseWriter, r *http.Request)
- func (e *Server) ShortenHandler(w http.ResponseWriter, r *http.Request)
- func (e *Server) Shutdown(timeout time.Duration) error
- func (e *Server) Start(listenAddress string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ApiSpecification ¶
type ApiSpecification struct { // RedirectorUriScheme refers to where you intend to host your publicly available redirects when // a user enters the shorten URL into their browser. // This API does not handle the redirects as it's conforming to the architectural // constraints of REST while allowing flexibility for any client that chooses to // use this API RedirectorUriScheme string `required:"true" split_words:"true"` // RedirectorUriHost refers to where you intend to host your publicly available redirects when // a user enters the shorten URL into their browser. // This API does not handle the redirects as it's conforming to the architectural // constraints of REST while allowing flexibility for any client that chooses to // use this API RedirectorUriHost string `required:"true" split_words:"true"` DbUrl string `required:"true" split_words:"true"` ListenAddress string `default:":8080" split_words:"true"` AlphaNumericBase string `default:"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" split_words:"true"` }
ApiSpecification defines the env vars required to run the API.
func NewApiSpecification ¶
func NewApiSpecification() (*ApiSpecification, error)
NewApiSpecification provides a convenient constructor for mapping the env vars needed for the API to ApiSpecification.
type Postgres ¶
Postgres embeds the postgres connection and allows the storage.Storage to be satisfied
func NewPostgres ¶
NewPostgres connects to a postgres instance using the provided connection string and then constructs a fresh Postgres The underlying Postgres.Conn field is a pool so can be reused and is concurrent safe.
type Server ¶
type Server struct { Config *shortener.Config Logger *zap.SugaredLogger // contains filtered or unexported fields }
Server acts as our HTTP server along the dependencies required to operate the server. Via Server, we can register the routing for all our HTTP handlers.
func (*Server) DocsHandler ¶
func (e *Server) DocsHandler(w http.ResponseWriter, _ *http.Request)
func (*Server) HealthCheckHandler ¶
func (e *Server) HealthCheckHandler(w http.ResponseWriter, r *http.Request)
HealthCheckHandler basically just does a simple check to establish if the database connection is available
func (*Server) ShortenHandler ¶
func (e *Server) ShortenHandler(w http.ResponseWriter, r *http.Request)
ShortenHandler takes the URL provided by the client, passing it to the shortener, and returns the result as JSON. For POST methods it'll try to shorten the URL and return it, and for GET methods it'll retrieve the non-shorten URL based on the provided shorten URL in the request param "?url="
func (*Server) Shutdown ¶
Shutdown can be utilised to gracefully shut down the http server in Server as well as giving the option to provide a timeout, so we aren't waiting too long on any long-running operations
Directories ¶
Path | Synopsis |
---|---|
Package bijective implements a basic way to get obtain a slice of integers from a seed that can be inverted back to the original seed
|
Package bijective implements a basic way to get obtain a slice of integers from a seed that can be inverted back to the original seed |