Documentation ¶
Overview ¶
Package handler provides common functions needed to create API handlers as well as some utilities
Index ¶
- func ServeStaticDir(r chi.Router, public string, static http.Dir)
- func ServeStaticFile(r chi.Router, path, filepath string)
- type AppInfoHandler
- type AppInfoResponse
- type Handler
- type HealthCheck
- type HealthCheckHandler
- type HealthCheckResponse
- type HealthChecker
- type LoggerMiddleware
- type Meta
- type Status
- type TemplateHandler
- type UserInfo
- type VersionInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ServeStaticDir ¶
ServeStaticDir acts as a FileServer and serves the contents of the given dir
func ServeStaticFile ¶
ServeStaticFile acts as a FileServer for a single file and serves the specified file
Types ¶
type AppInfoHandler ¶
type AppInfoHandler struct { Handler // Version of the application using https://semver.org/ Version string // Build identifies the specific build, e.g. git-hash Build string }
AppInfoHandler is responsible to return meta-information about the application
func (*AppInfoHandler) GetHandler ¶
func (h *AppInfoHandler) GetHandler() http.Handler
GetHandler returns the appinfo handler
func (*AppInfoHandler) HandleAppInfo ¶
func (h *AppInfoHandler) HandleAppInfo(user security.User, w http.ResponseWriter, r *http.Request) error
HandleAppInfo provides information about the application swagger:operation GET /appinfo appinfo HandleAppInfo
provides information about the application
meta-data of the application including authenticated user and version
--- produces: - application/json responses:
'200': description: Meta schema: "$ref": "#/definitions/Meta" '401': description: ProblemDetail schema: "$ref": "#/definitions/ProblemDetail" '403': description: ProblemDetail schema: "$ref": "#/definitions/ProblemDetail"
type AppInfoResponse ¶
type AppInfoResponse struct {
*Meta
}
AppInfoResponse wraps the data struct into a framework response
func (AppInfoResponse) Render ¶
func (a AppInfoResponse) Render(w http.ResponseWriter, r *http.Request) error
Render the specific response
type Handler ¶
type Handler struct { // ErrRep is used to send errors according to the users accept headers ErrRep *errors.ErrorReporter // Log is the supplied log-handler Log logging.Logger }
Handler defines common handler logic
func (*Handler) Call ¶
func (h *Handler) Call(f func(w http.ResponseWriter, r *http.Request) error) http.HandlerFunc
Call wraps handlers to have a common signature
type HealthCheck ¶
type HealthCheck struct { Status Status `json:"status"` Message string `json:"message"` Version string `json:"version"` TimeStamp time.Time `json:"timestamp"` }
HealthCheck returns information about the health of a service swagger:model
type HealthCheckHandler ¶
type HealthCheckHandler struct { Handler Checker HealthChecker }
HealthCheckHandler is responsnible to return a JSON formated health-check result
func (*HealthCheckHandler) GetHandler ¶
func (h *HealthCheckHandler) GetHandler() http.Handler
GetHandler returns the health-check handler
type HealthCheckResponse ¶
type HealthCheckResponse struct {
*HealthCheck
}
HealthCheckResponse returns a JSON repsonse
func (HealthCheckResponse) Render ¶
func (a HealthCheckResponse) Render(w http.ResponseWriter, r *http.Request) error
Render the specific response
type HealthChecker ¶
type HealthChecker interface { // Check performs the service health-check Check(user security.User) (HealthCheck, error) }
HealthChecker defines an interface which is used to create HealthCheck result
type LoggerMiddleware ¶
type LoggerMiddleware struct {
// contains filtered or unexported fields
}
LoggerMiddleware is a middleware that logs the start and end of each request, along with some useful data about what was requested, what the response status was, and how long it took to return.
this implementation was derived from the go-chi middleware https://github.com/go-chi/chi/blob/master/middleware/logger.go
func NewRequestLogger ¶
func NewRequestLogger(logger logging.Logger) *LoggerMiddleware
NewRequestLogger instantiats a new middleware to log requests
func (*LoggerMiddleware) LoggerContext ¶
func (l *LoggerMiddleware) LoggerContext(next http.Handler) http.Handler
LoggerContext performs the middleware action
type Meta ¶
type Meta struct { UserInfo UserInfo `json:"userInfo"` Version VersionInfo `json:"versionInfo"` }
Meta specifies application metadata swagger:model
type TemplateHandler ¶
type TemplateHandler struct { Handler CookieSettings cookies.Settings Version string Build string AppName string TemplateDir string }
TemplateHandler is used to display errors using HTML templates
func (*TemplateHandler) HandleError ¶
func (h *TemplateHandler) HandleError(w http.ResponseWriter, r *http.Request) error
HandleError returns a HTML template showing errors
type UserInfo ¶
type UserInfo struct { DisplayName string `json:"displayName"` UserID string `json:"userId"` UserName string `json:"userName"` Email string `json:"email"` Roles []string `json:"roles"` }
UserInfo provides information about the currently logged-in user swagger:model
type VersionInfo ¶
VersionInfo is used to provide version and build swagger:model