Documentation
¶
Index ¶
- Constants
- func ChainMiddleware(base http.Handler, middleware ...Middleware) http.Handler
- func HealthCheckHandler(healthChecks []HealthCheck) http.Handler
- func ReadConfig(filename string, config interface{}) error
- type App
- func (app *App) AddHealthCheck(healthCheck HealthCheck)
- func (app *App) AddMiddleware(middleware Middleware)
- func (app *App) Get(path string, h http.Handler)
- func (app *App) GetFunc(path string, h http.HandlerFunc)
- func (app *App) Post(path string, h http.Handler)
- func (app *App) PostFunc(path string, h http.HandlerFunc)
- func (app *App) Serve()
- type BuildFunc
- type Container
- type ContextKey
- type Handler
- type HealthCheck
- type LoggingMiddleware
- type Middleware
- type ServiceConfig
Constants ¶
const DefaultPort = "8080"
DefaultPort is the default port number to use if the PortEnvVar is not set.
const PortEnvVar = "PORT"
PortEnvVar is the name of the environment variable user to read the port value.
Variables ¶
This section is empty.
Functions ¶
func ChainMiddleware ¶
func ChainMiddleware(base http.Handler, middleware ...Middleware) http.Handler
ChainMiddleware chains a list of middleware into one http.Handler.
func HealthCheckHandler ¶
func HealthCheckHandler(healthChecks []HealthCheck) http.Handler
HealthCheckHandler returns a new http.Handler which handles health checks, using the given health checks.
func ReadConfig ¶
ReadConfig unmarshals JSON from a file to config.
Types ¶
type App ¶
type App struct { HealthChecks []HealthCheck HealthPath string // contains filtered or unexported fields }
App pulls together components of a HTTP api, such as middleware, health checks and routing.
func (*App) AddHealthCheck ¶
func (app *App) AddHealthCheck(healthCheck HealthCheck)
AddHealthCheck adds a health check to the App.
func (*App) AddMiddleware ¶
func (app *App) AddMiddleware(middleware Middleware)
AddMiddleware adds middleware to the App.
type BuildFunc ¶
type BuildFunc func(ctn *Container) interface{}
BuildFunc is a function used to build a service.
type Container ¶
type Container struct {
// contains filtered or unexported fields
}
Container is a simple dependency injection container.
func (*Container) AddService ¶
AddService adds a new service definition to the container.
func (*Container) AddSingleton ¶
AddSingleton adds a new singleton service definition to the container.
func (*Container) GetService ¶
GetService attempts to resolve a service by name.
type ContextKey ¶
type ContextKey string
ContextKey is a custom string type, used as a context value key.
type Handler ¶
type Handler struct{}
Handler is a abstract handler which provides helpers to implementing handlers.
func (*Handler) Respond ¶
func (*Handler) Respond(w http.ResponseWriter, data interface{})
Respond writes an OK status code, as well as writing data to the response as JSON.
func (*Handler) RespondError ¶
func (*Handler) RespondError(w http.ResponseWriter, err error, status int)
RespondError writes an error to the response with the given status code.
type HealthCheck ¶
HealthCheck is used to check the status of a service.
type LoggingMiddleware ¶
type LoggingMiddleware struct{}
LoggingMiddleware is middleware which logs all incoming requests.
func NewLoggingMiddleware ¶
func NewLoggingMiddleware() *LoggingMiddleware
NewLoggingMiddleware returns a new instance of LoggingMiddleware.
type Middleware ¶
Middleware is a http.Handler used as an intermediate step before handling a base handler.
type ServiceConfig ¶
ServiceConfig represents a service within the Container.
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
mock
Package mock is a generated GoMock package.
|
Package mock is a generated GoMock package. |
mock/auth
Package mock is a generated GoMock package.
|
Package mock is a generated GoMock package. |
mock/media
Package mock is a generated GoMock package.
|
Package mock is a generated GoMock package. |
mock/users
Package mock is a generated GoMock package.
|
Package mock is a generated GoMock package. |
cmd
|
|
media/mock/repository
Package repository is a generated GoMock package.
|
Package repository is a generated GoMock package. |
posts/mock/provider
Package mock is a generated GoMock package.
|
Package mock is a generated GoMock package. |
posts/mock/repository
Package mock is a generated GoMock package.
|
Package mock is a generated GoMock package. |
users/mock
Package mock is a generated GoMock package.
|
Package mock is a generated GoMock package. |
users/mock/provider
Package mock is a generated GoMock package.
|
Package mock is a generated GoMock package. |
users/mock/repository
Package repository is a generated GoMock package.
|
Package repository is a generated GoMock package. |
database
Package mock is a generated GoMock package.
|
Package mock is a generated GoMock package. |
media
Package media is a generated GoMock package.
|
Package media is a generated GoMock package. |