api

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2020 License: GPL-3.0 Imports: 23 Imported by: 9

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAuthenticationAlreadySet = errors.New("the authentication function has already been set")
)

API Errors

Functions

func GetMuxVars added in v0.3.0

func GetMuxVars(r *http.Request) map[string]string

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

func RegisterHandler(path string, handler http.Handler) *mux.Route

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

func RequestLogger(next http.Handler) http.Handler

RequestLogger is a logging middleware

func Serve

func Serve()

Serve starts serving the API endpoint.

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

type Authenticator func(s *http.Server, r *http.Request) (grantAccess bool, err error)

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.

type Middleware added in v0.3.0

type Middleware func(next http.Handler) http.Handler

Middleware is a function that can be added as a middleware to the API endpoint.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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