Added support for hooks to customize behavior.

This commit is contained in:
Travis Reeder
2016-08-09 22:34:28 -07:00
parent 72a6d3aa5b
commit 8558d13f07
23 changed files with 324 additions and 42 deletions

25
api/ifaces/handlers.go Normal file
View File

@@ -0,0 +1,25 @@
package ifaces
import (
"net/http"
"github.com/iron-io/functions/api/models"
)
type SpecialHandler interface {
Handle(c HandlerContext) error
}
// Each handler can modify the context here so when it gets passed along, it will use the new info.
// Not using Gin's Context so we don't lock ourselves into Gin, this is a subset of the Gin context.
type HandlerContext interface {
// Request returns the underlying http.Request object
Request() *http.Request
// Datastore returns the models.Datastore object. Not that this has arbitrary key value store methods that can be used to store extra data
Datastore() models.Datastore
// Set and Get values on the context, this can be useful to change behavior for the rest of the request
Set(key string, value interface{})
Get(key string) (value interface{}, exists bool)
}