handler

package
v1.0.14 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2020 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

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

Index

Constants

View Source
const LogFieldNameFunction = "function"

LogFieldNameFunction defines the field-name for structured logging of cuntions

Variables

This section is empty.

Functions

func LogFunction

func LogFunction(name string) *log.Entry

LogFunction uses the function name to perform structured logging with a field

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) HandleAppInfo

func (a *AppInfoHandler) HandleAppInfo(user security.User, w http.ResponseWriter, r *http.Request) error

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
}

Response 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
}

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

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