context

package
v0.0.0-...-e675dcb Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

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 TestFail

func TestFail(t *testing.T, resp *httptest.ResponseRecorder, status int, message string)

TestFail 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

func (chain *Chain) AppendChain(tail *Chain) (newChain *Chain)

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

func (ctx *Context) BadRequest(message string, params ...interface{})

BadRequest is a helper to generate http.BadRequest responses

func (*Context) CheckUserFreeSpaceForUpload

func (ctx *Context) CheckUserFreeSpaceForUpload(upload *common.Upload) error

CheckUserFreeSpaceForUpload checks if context user has enough space to add this upload

func (*Context) CheckUserTotalUploadedSize

func (ctx *Context) CheckUserTotalUploadedSize() error

CheckUserTotalUploadedSize checks if context user is over space quota

func (*Context) CreateFile

func (ctx *Context) CreateFile(upload *common.Upload, params *common.File) (file *common.File, err error)

CreateFile prepares a new file object to be persisted in DB ( create file ID, link upload ID, check name, ... )

func (*Context) CreateUpload

func (ctx *Context) CreateUpload(params *common.Upload) (upload *common.Upload, err error)

CreateUpload from params and context (check configuration and default values, generate upload and file IDs, ... )

func (*Context) Error

func (ctx *Context) Error(err error)

Error handles common.HttpError

func (*Context) Fail

func (ctx *Context) Fail(message string, err error, status int)

Fail is a helper to generate http error responses

func (*Context) Forbidden

func (ctx *Context) Forbidden(message string, params ...interface{})

Forbidden is a helper to generate http.Forbidden responses

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

func (ctx *Context) GetDataBackend() data.Backend

GetDataBackend get dataBackend from the context.

func (*Context) GetFile

func (ctx *Context) GetFile() *common.File

GetFile get file from the context.

func (*Context) GetLogger

func (ctx *Context) GetLogger() *logger.Logger

GetLogger get logger from the context.

func (*Context) GetMaxFileSize

func (ctx *Context) GetMaxFileSize() int64

GetMaxFileSize return the maximum allowed file size for the context

func (*Context) GetMetadataBackend

func (ctx *Context) GetMetadataBackend() *metadata.Backend

GetMetadataBackend get metadataBackend from the context.

func (*Context) GetMetrics

func (ctx *Context) GetMetrics() *common.PlikMetrics

GetMetrics get metrics from the context.

func (*Context) GetOriginalUser

func (ctx *Context) GetOriginalUser() (user *common.User)

GetOriginalUser get original user in the context

func (*Context) GetPagingQuery

func (ctx *Context) GetPagingQuery() *common.PagingQuery

GetPagingQuery get pagingQuery from the context.

func (*Context) GetReq

func (ctx *Context) GetReq() *http.Request

GetReq get req from the context.

func (*Context) GetResp

func (ctx *Context) GetResp() http.ResponseWriter

GetResp get resp from the context.

func (*Context) GetSourceIP

func (ctx *Context) GetSourceIP() net.IP

GetSourceIP get sourceIP from the context.

func (*Context) GetStreamBackend

func (ctx *Context) GetStreamBackend() data.Backend

GetStreamBackend get streamBackend from the context.

func (*Context) GetToken

func (ctx *Context) GetToken() *common.Token

GetToken get token from the context.

func (*Context) GetUpload

func (ctx *Context) GetUpload() *common.Upload

GetUpload get upload from the context.

func (*Context) GetUser

func (ctx *Context) GetUser() *common.User

GetUser get user from the context.

func (*Context) GetUserMaxSize

func (ctx *Context) GetUserMaxSize() int64

GetUserMaxSize return user max file size if configured or server default

func (*Context) InternalServerError

func (ctx *Context) InternalServerError(message string, err error)

InternalServerError is a helper to generate http.StatusInternalServerError responses

func (*Context) InvalidParameter

func (ctx *Context) InvalidParameter(message string, params ...interface{})

InvalidParameter is a helper to generate http.BadRequest responses

func (*Context) IsAdmin

func (ctx *Context) IsAdmin() bool

IsAdmin get context user admin status

func (*Context) IsQuick

func (ctx *Context) IsQuick() bool

IsQuick get isQuick from the context.

func (*Context) IsRedirectOnFailure

func (ctx *Context) IsRedirectOnFailure() bool

IsRedirectOnFailure get isRedirectOnFailure from the context.

func (*Context) IsWhitelisted

func (ctx *Context) IsWhitelisted() bool

IsWhitelisted get isWhitelisted from the context.

func (*Context) MissingParameter

func (ctx *Context) MissingParameter(message string, params ...interface{})

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) NotFound

func (ctx *Context) NotFound(message string, params ...interface{})

NotFound is a helper to generate http.NotFound responses

func (*Context) Recover

func (ctx *Context) Recover()

Recover is a helper to generate http.InternalServerError responses if a panic occurs

func (*Context) SaveOriginalUser

func (ctx *Context) SaveOriginalUser()

SaveOriginalUser save the current user in the context

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

func (ctx *Context) SetDataBackend(dataBackend data.Backend)

SetDataBackend set dataBackend in the context

func (*Context) SetFile

func (ctx *Context) SetFile(file *common.File)

SetFile set file in the context

func (*Context) SetLogger

func (ctx *Context) SetLogger(logger *logger.Logger)

SetLogger set logger in the context

func (*Context) SetMetadataBackend

func (ctx *Context) SetMetadataBackend(metadataBackend *metadata.Backend)

SetMetadataBackend set metadataBackend in the context

func (*Context) SetMetrics

func (ctx *Context) SetMetrics(metrics *common.PlikMetrics)

SetMetrics set metrics in the context

func (*Context) SetPagingQuery

func (ctx *Context) SetPagingQuery(pagingQuery *common.PagingQuery)

SetPagingQuery set pagingQuery in the context

func (*Context) SetQuick

func (ctx *Context) SetQuick(isQuick bool)

SetQuick set isQuick in the context

func (*Context) SetRedirectOnFailure

func (ctx *Context) SetRedirectOnFailure(isRedirectOnFailure bool)

SetRedirectOnFailure set isRedirectOnFailure in the context

func (*Context) SetReq

func (ctx *Context) SetReq(req *http.Request)

SetReq set req in the context

func (*Context) SetResp

func (ctx *Context) SetResp(resp http.ResponseWriter)

SetResp set resp in the context

func (*Context) SetSourceIP

func (ctx *Context) SetSourceIP(sourceIP net.IP)

SetSourceIP set sourceIP in the context

func (*Context) SetStreamBackend

func (ctx *Context) SetStreamBackend(streamBackend data.Backend)

SetStreamBackend set streamBackend in the context

func (*Context) SetToken

func (ctx *Context) SetToken(token *common.Token)

SetToken set token in the context

func (*Context) SetUpload

func (ctx *Context) SetUpload(upload *common.Upload)

SetUpload set upload in the context

func (*Context) SetUser

func (ctx *Context) SetUser(user *common.User)

SetUser set user in the context

func (*Context) SetWhitelisted

func (ctx *Context) SetWhitelisted(isWhitelisted bool)

SetWhitelisted set isWhitelisted in the context

func (*Context) Unauthorized

func (ctx *Context) Unauthorized(message string, params ...interface{})

Unauthorized is a helper to generate http.Unauthorized responses

type Handler

type Handler func(ctx *Context) http.Handler

Handler is a constructor to close a Context into a http.Handler

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

type Middleware

type Middleware func(ctx *Context, next http.Handler) http.Handler

Middleware is a constructor to close a Context into a middleware

func Adapt

func Adapt(fn func(http.Handler) http.Handler) Middleware

Adapt add context to a middleware so it can be added to the chain.

Jump to

Keyboard shortcuts

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