Documentation ¶
Index ¶
- Constants
- Variables
- func GetMuxVars(r *http.Request) map[string]string
- func RegisterHandleFunc(path string, handleFunc func(http.ResponseWriter, *http.Request)) *mux.Route
- func RegisterHandler(path string, handler http.Handler) *mux.Route
- func RegisterMiddleware(middleware Middleware)
- func RequestLogger(next http.Handler) http.Handler
- func Serve()
- func SetAuthenticator(fn Authenticator) error
- func SetDefaultAPIListenAddress(address string)
- type Authenticator
- type DatabaseAPI
- type LoggingResponseWriter
- type Middleware
Constants ¶
const (
CfgDefaultListenAddressKey = "api/listenAddress"
)
Config Keys
Variables ¶
var (
ErrAuthenticationAlreadySet = errors.New("the authentication function has already been set")
)
API Errors
Functions ¶
func GetMuxVars ¶ added in v0.3.0
GetMuxVars wraps github.com/gorilla/mux.Vars in order to mitigate context key issues in multi-repo projects.
func RegisterHandleFunc ¶
func RegisterHandleFunc(path string, handleFunc func(http.ResponseWriter, *http.Request)) *mux.Route
RegisterHandleFunc registers a handle function with the API endoint.
func RegisterHandler ¶ added in v0.3.0
RegisterHandler registers a handler with the API endoint.
func RegisterMiddleware ¶ added in v0.3.0
func RegisterMiddleware(middleware Middleware)
RegisterMiddleware registers a middle function with the API endoint.
func RequestLogger ¶
RequestLogger is a logging middleware
func SetAuthenticator ¶ added in v0.3.0
func SetAuthenticator(fn Authenticator) error
SetAuthenticator sets an authenticator function for the API endpoint. If none is set, all requests will be allowed.
func SetDefaultAPIListenAddress ¶
func SetDefaultAPIListenAddress(address string)
SetDefaultAPIListenAddress sets the default listen address for the API.
Types ¶
type Authenticator ¶ added in v0.3.0
Authenticator is a function that can be set as the authenticator for the API endpoint. If none is set, all requests will be allowed.
type DatabaseAPI ¶
type DatabaseAPI struct {
// contains filtered or unexported fields
}
DatabaseAPI is a database API instance.
type LoggingResponseWriter ¶ added in v0.3.0
type LoggingResponseWriter struct { ResponseWriter http.ResponseWriter Request *http.Request Status int }
LoggingResponseWriter is a wrapper for http.ResponseWriter for better request logging.
func NewLoggingResponseWriter ¶ added in v0.3.0
func NewLoggingResponseWriter(w http.ResponseWriter, r *http.Request) *LoggingResponseWriter
NewLoggingResponseWriter wraps a http.ResponseWriter.
func (*LoggingResponseWriter) Header ¶ added in v0.3.0
func (lrw *LoggingResponseWriter) Header() http.Header
Header wraps the original Header method.
func (*LoggingResponseWriter) Hijack ¶ added in v0.3.0
func (lrw *LoggingResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error)
Hijack wraps the original Hijack method, if available.
func (*LoggingResponseWriter) Write ¶ added in v0.3.0
func (lrw *LoggingResponseWriter) Write(b []byte) (int, error)
Write wraps the original Write method.
func (*LoggingResponseWriter) WriteHeader ¶ added in v0.3.0
func (lrw *LoggingResponseWriter) WriteHeader(code int)
WriteHeader wraps the original WriteHeader method to extract information.