Documentation ¶
Index ¶
- func TestBadRequest(t *testing.T, resp *httptest.ResponseRecorder, message string)
- func TestFail(t *testing.T, resp *httptest.ResponseRecorder, status int, message string)
- func TestForbidden(t *testing.T, resp *httptest.ResponseRecorder, message string)
- func TestInternalServerError(t *testing.T, resp *httptest.ResponseRecorder, message string)
- func TestInvalidParameter(t *testing.T, resp *httptest.ResponseRecorder, parameter string)
- func TestMissingParameter(t *testing.T, resp *httptest.ResponseRecorder, parameter string)
- func TestNotFound(t *testing.T, resp *httptest.ResponseRecorder, message string)
- func TestOK(t *testing.T, resp *httptest.ResponseRecorder)
- func TestPanic(t *testing.T, resp *httptest.ResponseRecorder, message string, handler func())
- func TestUnauthorized(t *testing.T, resp *httptest.ResponseRecorder, message string)
- type Chain
- func (chain *Chain) Append(cms ...Middleware) (newChain *Chain)
- func (chain *Chain) AppendChain(tail *Chain) (newChain *Chain)
- func (chain *Chain) Then(fn HandlerFunc) (ch *ChainHandler)
- func (chain *Chain) ThenHandler(handler http.Handler) (ch *ChainHandler)
- func (chain *Chain) ThenHandlerFunc(fn http.HandlerFunc) (ch *ChainHandler)
- type ChainHandler
- type Context
- func (ctx *Context) BadRequest(message string, params ...interface{})
- func (ctx *Context) ConfigureUploadFromContext(upload *common.Upload)
- func (ctx *Context) Fail(message string, err error, status int)
- func (ctx *Context) Forbidden(message string, params ...interface{})
- func (ctx *Context) GetAuthenticator() *common.SessionAuthenticator
- func (ctx *Context) GetConfig() *common.Configuration
- func (ctx *Context) GetDataBackend() data.Backend
- func (ctx *Context) GetFile() *common.File
- func (ctx *Context) GetLogger() *logger.Logger
- func (ctx *Context) GetMetadataBackend() *metadata.Backend
- func (ctx *Context) GetPagingQuery() *common.PagingQuery
- func (ctx *Context) GetReq() *http.Request
- func (ctx *Context) GetResp() http.ResponseWriter
- func (ctx *Context) GetSourceIP() net.IP
- func (ctx *Context) GetStreamBackend() data.Backend
- func (ctx *Context) GetToken() *common.Token
- func (ctx *Context) GetUpload() *common.Upload
- func (ctx *Context) GetUser() *common.User
- func (ctx *Context) InternalServerError(message string, err error)
- func (ctx *Context) InvalidParameter(message string, params ...interface{})
- func (ctx *Context) IsAdmin() bool
- func (ctx *Context) IsQuick() bool
- func (ctx *Context) IsRedirectOnFailure() bool
- func (ctx *Context) IsUploadAdmin() bool
- func (ctx *Context) IsWhitelisted() bool
- func (ctx *Context) MissingParameter(message string, params ...interface{})
- func (ctx *Context) NewRecorder(req *http.Request) *httptest.ResponseRecorder
- func (ctx *Context) NotFound(message string, params ...interface{})
- func (ctx *Context) Recover()
- func (ctx *Context) SetAuthenticator(authenticator *common.SessionAuthenticator)
- func (ctx *Context) SetConfig(config *common.Configuration)
- func (ctx *Context) SetDataBackend(dataBackend data.Backend)
- func (ctx *Context) SetFile(file *common.File)
- func (ctx *Context) SetLogger(logger *logger.Logger)
- func (ctx *Context) SetMetadataBackend(metadataBackend *metadata.Backend)
- func (ctx *Context) SetPagingQuery(pagingQuery *common.PagingQuery)
- func (ctx *Context) SetQuick(isQuick bool)
- func (ctx *Context) SetRedirectOnFailure(isRedirectOnFailure bool)
- func (ctx *Context) SetReq(req *http.Request)
- func (ctx *Context) SetResp(resp http.ResponseWriter)
- func (ctx *Context) SetSourceIP(sourceIP net.IP)
- func (ctx *Context) SetStreamBackend(streamBackend data.Backend)
- func (ctx *Context) SetToken(token *common.Token)
- func (ctx *Context) SetUpload(upload *common.Upload)
- func (ctx *Context) SetUploadAdmin(isUploadAdmin bool)
- func (ctx *Context) SetUser(user *common.User)
- func (ctx *Context) SetWhitelisted(isWhitelisted bool)
- func (ctx *Context) Unauthorized(message string, params ...interface{})
- type Handler
- type HandlerFunc
- type Middleware
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func TestBadRequest ¶
func TestBadRequest(t *testing.T, resp *httptest.ResponseRecorder, message string)
TestBadRequest is a helper to test a httptest.ResponseRecorder status
func TestForbidden ¶
func TestForbidden(t *testing.T, resp *httptest.ResponseRecorder, message string)
TestForbidden is a helper to test a httptest.ResponseRecorder status
func TestInternalServerError ¶
func TestInternalServerError(t *testing.T, resp *httptest.ResponseRecorder, message string)
TestInternalServerError is a helper to test a httptest.ResponseRecorder status
func TestInvalidParameter ¶
func TestInvalidParameter(t *testing.T, resp *httptest.ResponseRecorder, parameter string)
TestInvalidParameter is a helper to test a httptest.ResponseRecorder status
func TestMissingParameter ¶
func TestMissingParameter(t *testing.T, resp *httptest.ResponseRecorder, parameter string)
TestMissingParameter is a helper to test a httptest.ResponseRecorder status
func TestNotFound ¶
func TestNotFound(t *testing.T, resp *httptest.ResponseRecorder, message string)
TestNotFound is a helper to test a httptest.ResponseRecorder status
func TestOK ¶
func TestOK(t *testing.T, resp *httptest.ResponseRecorder)
TestOK is a helper to test a httptest.ResponseRecorder status
func TestPanic ¶
func TestPanic(t *testing.T, resp *httptest.ResponseRecorder, message string, handler func())
TestPanic is a helper to test a httptest.ResponseRecorder status
func TestUnauthorized ¶
func TestUnauthorized(t *testing.T, resp *httptest.ResponseRecorder, message string)
TestUnauthorized is a helper to test a httptest.ResponseRecorder status
Types ¶
type Chain ¶
type Chain struct {
// contains filtered or unexported fields
}
Chain link context middleware to each other. Chain are immutable and any operation on them returns a new Chain object.
func NewChain ¶
func NewChain(cms ...Middleware) (chain *Chain)
NewChain creates a new contextMiddleware chain.
func (*Chain) Append ¶
func (chain *Chain) Append(cms ...Middleware) (newChain *Chain)
Append add contextMiddleware(s) to the chain.
func (*Chain) AppendChain ¶
AppendChain duplicates a chain and links it to the current chain.
func (*Chain) Then ¶
func (chain *Chain) Then(fn HandlerFunc) (ch *ChainHandler)
Then add a HandlerFunc to the end of the chain and returns a http.Handler compliant Handler
func (*Chain) ThenHandler ¶
func (chain *Chain) ThenHandler(handler http.Handler) (ch *ChainHandler)
ThenHandler add a http.Handler to the end of the chain and returns a http.Handler compliant Handler
func (*Chain) ThenHandlerFunc ¶
func (chain *Chain) ThenHandlerFunc(fn http.HandlerFunc) (ch *ChainHandler)
ThenHandlerFunc add a http.HandlerFunc to the end of the chain and returns a http.Handler compliant Handler
type ChainHandler ¶
type ChainHandler struct {
// contains filtered or unexported fields
}
ChainHandler holds a chain and a final handler. It satisfy the http.Handler interface and can be served directly by a net/http server.
func (*ChainHandler) ServeHTTP ¶
func (ch *ChainHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request)
ServeHTTP builds the chain of handlers in order, closing the context along the way and executes it.
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context to be propagated throughout the middleware chain
func (*Context) BadRequest ¶
BadRequest is a helper to generate http.BadRequest responses
func (*Context) ConfigureUploadFromContext ¶
ConfigureUploadFromContext assign context values to upload
func (*Context) GetAuthenticator ¶
func (ctx *Context) GetAuthenticator() *common.SessionAuthenticator
GetAuthenticator get authenticator from the context.
func (*Context) GetConfig ¶
func (ctx *Context) GetConfig() *common.Configuration
GetConfig get config from the context.
func (*Context) GetDataBackend ¶
GetDataBackend get dataBackend from the context.
func (*Context) GetMetadataBackend ¶
GetMetadataBackend get metadataBackend from the context.
func (*Context) GetPagingQuery ¶
func (ctx *Context) GetPagingQuery() *common.PagingQuery
GetPagingQuery get pagingQuery from the context.
func (*Context) GetResp ¶
func (ctx *Context) GetResp() http.ResponseWriter
GetResp get resp from the context.
func (*Context) GetSourceIP ¶
GetSourceIP get sourceIP from the context.
func (*Context) GetStreamBackend ¶
GetStreamBackend get streamBackend from the context.
func (*Context) InternalServerError ¶
InternalServerError is a helper to generate http.StatusInternalServerError responses
func (*Context) InvalidParameter ¶
InvalidParameter is a helper to generate http.BadRequest responses
func (*Context) IsRedirectOnFailure ¶
IsRedirectOnFailure get isRedirectOnFailure from the context.
func (*Context) IsUploadAdmin ¶
IsUploadAdmin get isUploadAdmin from the context.
func (*Context) IsWhitelisted ¶
IsWhitelisted get isWhitelisted from the context.
func (*Context) MissingParameter ¶
MissingParameter is a helper to generate http.BadRequest responses
func (*Context) NewRecorder ¶
func (ctx *Context) NewRecorder(req *http.Request) *httptest.ResponseRecorder
NewRecorder create a new response recorder for testing
func (*Context) Recover ¶
func (ctx *Context) Recover()
Recover is a helper to generate http.InternalServerError responses if a panic occurs
func (*Context) SetAuthenticator ¶
func (ctx *Context) SetAuthenticator(authenticator *common.SessionAuthenticator)
SetAuthenticator set authenticator in the context
func (*Context) SetConfig ¶
func (ctx *Context) SetConfig(config *common.Configuration)
SetConfig set config in the context
func (*Context) SetDataBackend ¶
SetDataBackend set dataBackend in the context
func (*Context) SetMetadataBackend ¶
SetMetadataBackend set metadataBackend in the context
func (*Context) SetPagingQuery ¶
func (ctx *Context) SetPagingQuery(pagingQuery *common.PagingQuery)
SetPagingQuery set pagingQuery in the context
func (*Context) SetRedirectOnFailure ¶
SetRedirectOnFailure set isRedirectOnFailure in the context
func (*Context) SetResp ¶
func (ctx *Context) SetResp(resp http.ResponseWriter)
SetResp set resp in the context
func (*Context) SetSourceIP ¶
SetSourceIP set sourceIP in the context
func (*Context) SetStreamBackend ¶
SetStreamBackend set streamBackend in the context
func (*Context) SetUploadAdmin ¶
SetUploadAdmin set isUploadAdmin in the context
func (*Context) SetWhitelisted ¶
SetWhitelisted set isWhitelisted in the context
func (*Context) Unauthorized ¶
Unauthorized is a helper to generate http.Unauthorized responses
type HandlerFunc ¶
type HandlerFunc func(ctx *Context, resp http.ResponseWriter, req *http.Request)
HandlerFunc is a constructor to close a Context into a http.HandlerFunc