handler

package
v0.0.0-...-c32710b Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2020 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package handler provides common functions needed to create API handlers as well as some utilities

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ServeStaticDir

func ServeStaticDir(r chi.Router, public string, static http.Dir)

ServeStaticDir acts as a FileServer and serves the contents of the given dir

func ServeStaticFile

func ServeStaticFile(r chi.Router, path, filepath string)

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

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

func (*Handler) Secure

func (h *Handler) Secure(f func(user security.User, w http.ResponseWriter, r *http.Request) error) http.HandlerFunc

Secure wraps handlers to have a common signature a User is retrieved from the context and a possible error from the handler function is processed

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

func (HealthCheck) String

func (h HealthCheck) String() string

String prints the request

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

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 Status

type Status string

Status enumerates the available states swagger:enum Status

const (
	// OK indicates all is good
	OK Status = "Ok"
	// Error indicates an error
	Error Status = "Error"
)

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

type VersionInfo struct {
	Version string `json:"version"`
	Build   string `json:"buildNumber"`
}

VersionInfo is used to provide version and build swagger:model

Jump to

Keyboard shortcuts

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