Documentation
¶
Overview ¶
Package app provides a preconfigured HTTP server.
Index ¶
- func NewMuxRouter() *mux.Router
- type AccessTokenConverter
- type Authorizer
- type CreateMovieService
- type DeleteMovieService
- type Driver
- type FindMovieService
- type LoggerService
- type PingService
- type Server
- func (s *Server) AccessTokenHandler(h http.Handler) http.Handler
- func (s *Server) AuthorizeUserHandler(h http.Handler) http.Handler
- func (s *Server) ConvertAccessTokenHandler(h http.Handler) http.Handler
- func (s *Server) CtxWithUserChain() alice.Chain
- func (s *Server) DefaultRealmHandler(h http.Handler) http.Handler
- func (s *Server) JSONContentTypeResponseHandler(h http.Handler) http.Handler
- func (s *Server) ListenAndServe() error
- func (s *Server) LoggerChain() alice.Chain
- func (s *Server) Shutdown(ctx context.Context) error
- type ServerParams
- type UpdateMovieService
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewMuxRouter ¶ added in v0.34.0
NewMuxRouter initializes a gorilla/mux router and adds the /api subroute to it
Types ¶
type AccessTokenConverter ¶ added in v0.34.0
type AccessTokenConverter interface {
Convert(ctx context.Context, token auth.AccessToken) (user.User, error)
}
AccessTokenConverter interface converts an access token to a User
type Authorizer ¶ added in v0.34.0
type Authorizer interface {
Authorize(lgr zerolog.Logger, sub user.User, obj string, act string) error
}
Authorizer interface authorizes access to a resource given a user and action
type CreateMovieService ¶ added in v0.34.0
type CreateMovieService interface {
Create(ctx context.Context, r *service.CreateMovieRequest, u user.User) (service.MovieResponse, error)
}
CreateMovieService creates a Movie
type DeleteMovieService ¶ added in v0.34.0
type DeleteMovieService interface {
Delete(ctx context.Context, extlID string) (service.DeleteMovieResponse, error)
}
DeleteMovieService is a service for deleting a Movie
type Driver ¶ added in v0.34.0
Driver implements the driver.Server interface. The zero value is a valid http.Server.
func NewDriver ¶ added in v0.34.0
func NewDriver() *Driver
NewDriver creates a Driver with an http.Server with default timeouts.
func (*Driver) ListenAndServe ¶ added in v0.34.0
ListenAndServe sets the address and handler on Driver's http.Server, then calls ListenAndServe on it.
type FindMovieService ¶ added in v0.34.0
type FindMovieService interface { FindMovieByID(ctx context.Context, extlID string) (service.MovieResponse, error) FindAllMovies(ctx context.Context) ([]service.MovieResponse, error) }
FindMovieService interface reads a Movie form the database
type LoggerService ¶ added in v0.34.0
type LoggerService interface { Read() service.LoggerResponse Update(r *service.LoggerRequest) (service.LoggerResponse, error) }
LoggerService reads and updates the logger state
type PingService ¶ added in v0.34.0
type PingService interface {
Ping(ctx context.Context, logger zerolog.Logger) service.PingResponse
}
PingService pings the database and responds whether it is up or down
type Server ¶ added in v0.34.0
type Server struct { // Addr optionally specifies the TCP address for the server to listen on, // in the form "host:port". If empty, ":http" (port 80) is used. // The service names are defined in RFC 6335 and assigned by IANA. // See net.Dial for details of the address format. Addr string // Authorization AccessTokenConverter AccessTokenConverter Authorizer Authorizer // Services used by the various HTTP routes. PingService PingService LoggerService LoggerService CreateMovieService CreateMovieService UpdateMovieService UpdateMovieService DeleteMovieService DeleteMovieService FindMovieService FindMovieService // contains filtered or unexported fields }
Server represents an HTTP server.
func NewServer ¶ added in v0.34.0
func NewServer(r *mux.Router, params *ServerParams) (*Server, error)
NewServer initializes a new Server and registers routes to the given router
func (*Server) AccessTokenHandler ¶ added in v0.34.0
AccessTokenHandler middleware is used to pull the Bearer token from the Authorization header and set it to the request context as an auth.AccessToken
func (*Server) AuthorizeUserHandler ¶ added in v0.34.0
AuthorizeUserHandler middleware is used authorize a User for a request path and http method
func (*Server) ConvertAccessTokenHandler ¶ added in v0.34.0
ConvertAccessTokenHandler middleware is used to convert an AccessToken to a User and store the User to the request context
func (*Server) CtxWithUserChain ¶ added in v0.34.0
CtxWithUserChain chains handlers together to set the Realm, Access Token and User to the Context
func (*Server) DefaultRealmHandler ¶ added in v0.34.0
DefaultRealmHandler middleware is used to set a default Realm to the request context
func (*Server) JSONContentTypeResponseHandler ¶ added in v0.34.0
JSONContentTypeResponseHandler middleware is used to add the application/json Content-Type Header for responses
func (*Server) ListenAndServe ¶ added in v0.34.0
ListenAndServe is a wrapper to use wherever http.ListenAndServe is used.
func (*Server) LoggerChain ¶ added in v0.34.0
LoggerChain returns a middleware chain (via alice.Chain) initialized with all the standard middleware handlers for logging. The logger will be added to the request context for subsequent use with pre-populated fields, including the request method, url, status, size, duration, remote IP, user agent, referer. A unique Request ID is also added to the logger, context and response headers.
type ServerParams ¶ added in v0.34.0
type ServerParams struct { // Logger is used for app logging Logger zerolog.Logger // Driver serves HTTP requests. Driver driver.Server }
ServerParams is the set of configuration parameters for a Server
func NewServerParams ¶ added in v0.34.0
func NewServerParams(lgr zerolog.Logger, d driver.Server) *ServerParams
NewServerParams is an initializer for ServerParams
type UpdateMovieService ¶ added in v0.34.0
type UpdateMovieService interface {
Update(ctx context.Context, r *service.UpdateMovieRequest, u user.User) (service.MovieResponse, error)
}
UpdateMovieService is a service for updating a Movie