Added functions to MiddlewareContext interface

This commit is contained in:
Travis Reeder
2017-07-12 22:28:49 -07:00
parent 86b93e27f7
commit 667c611fac

View File

@@ -28,6 +28,18 @@ func (f MiddlewareFunc) Serve(ctx MiddlewareContext, w http.ResponseWriter, r *h
// MiddlewareContext extends context.Context for Middleware // MiddlewareContext extends context.Context for Middleware
type MiddlewareContext interface { type MiddlewareContext interface {
context.Context context.Context
// Set is used to store a new key/value pair exclusively for this context.
// This is different than WithValue(), as it does not make a copy of the context with the new value, it will be available up the chain as well.
Set(key string, value interface{})
// Get returns the value for the given key, ie: (value, true).
// If the value does not exists it returns (nil, false)
Get(key string) (value interface{}, exists bool)
// MustGet returns the value for the given key if it exists, otherwise it panics.
MustGet(key string) interface{}
// Middleware can call Next() explicitly to call the next middleware in the chain. If Next() is not called and an error is not returned, Next() will automatically be called. // Middleware can call Next() explicitly to call the next middleware in the chain. If Next() is not called and an error is not returned, Next() will automatically be called.
Next() Next()
// Index returns the index of where we're at in the chain // Index returns the index of where we're at in the chain