server

package
v0.0.0-...-3b3107d Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ContentType     = "content-type"
	ContentTypeJson = "application/json"
)

Variables

This section is empty.

Functions

func GetMux

func GetMux(actx *AppContext) http.Handler

GetMux returns a handler configured to process all required operations. Sub-handlers require server context to be configured properly.

func HandlerCapture

func HandlerCapture(w http.ResponseWriter, r *http.Request, actx *AppContext) error

func HandlerGetAll

func HandlerGetAll(w http.ResponseWriter, r *http.Request, actx *AppContext) error

Types

type ApiError

type ApiError struct {
	Message string
}

ApiError is the error model for all API responses.

func (ApiError) WriteToResponse

func (e ApiError) WriteToResponse(log *logrus.Entry, w http.ResponseWriter, statusCode int)

WriteToResponse write status code and error content to the response.

type AppContext

type AppContext struct {
	Log  *logrus.Entry
	Repo storage.Repo
}

AppContext stores runtime dependencies for server's handlers Not protected from changes, so just do not change it's content in handlers please. But you can copy it instead.

type AppHandler

type AppHandler func(http.ResponseWriter, *http.Request, *AppContext) error

AppHandler is a http.Handler enriched with application context. In case of error it should return go error instead of using Writer.

Jump to

Keyboard shortcuts

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