Documentation
¶
Overview ¶
TODO: it would be nice to move these into the top level folder so people can use these with the "functions" package, eg: functions.ApiHandler
TODO: it would be nice to move these into the top level folder so people can use these with the "functions" package, eg: functions.AddMiddleware(...)
Index ¶
- Constants
- Variables
- func DefaultEnqueue(ctx context.Context, mq models.MessageQueue, task *models.Task) (*models.Task, error)
- type ApiAppHandler
- type ApiAppHandlerFunc
- type ApiHandler
- type ApiHandlerFunc
- type AppListener
- type Handle
- type HandlerContext
- type Middleware
- type MiddlewareContext
- type MiddlewareFunc
- type Param
- type Params
- type RunnerListener
- type Server
- func (s *Server) AddAppEndpoint(method, path string, handler ApiAppHandler)
- func (s *Server) AddAppEndpointFunc(method, path string, ...)
- func (s *Server) AddAppListener(listener AppListener)
- func (s *Server) AddEndpoint(method, path string, handler ApiHandler)
- func (s *Server) AddEndpointFunc(method, path string, handler func(w http.ResponseWriter, r *http.Request))
- func (s *Server) AddMiddleware(m Middleware)
- func (s *Server) AddMiddlewareFunc(...)
- func (s *Server) AddRunnerListener(listener RunnerListener)
- func (s *Server) AddSpecialHandler(handler SpecialHandler)
- func (s *Server) FireAfterAppCreate(ctx context.Context, app *models.App) error
- func (s *Server) FireAfterAppDelete(ctx context.Context, app *models.App) error
- func (s *Server) FireAfterAppUpdate(ctx context.Context, app *models.App) error
- func (s *Server) FireAfterDispatch(ctx context.Context, route *models.Route) error
- func (s *Server) FireBeforeAppCreate(ctx context.Context, app *models.App) error
- func (s *Server) FireBeforeAppDelete(ctx context.Context, app *models.App) error
- func (s *Server) FireBeforeAppUpdate(ctx context.Context, app *models.App) error
- func (s *Server) FireBeforeDispatch(ctx context.Context, route *models.Route) error
- func (s *Server) Start(ctx context.Context)
- func (s *Server) UseSpecialHandlers(ctx context.Context, req *http.Request, resp http.ResponseWriter) (context.Context, error)
- type ServerOption
- type SpecialHandler
- type SpecialHandlerContext
Constants ¶
const ( EnvLogLevel = "log_level" EnvMQURL = "mq_url" EnvDBURL = "db_url" EnvPort = "port" // be careful, Gin expects this variable to be "port" EnvAPIURL = "api_url" )
Variables ¶
var ErrInternalServerError = errors.New("Something unexpected happened on the server")
var ErrNoSpecialHandlerFound = errors.New("Path not found")
Functions ¶
Types ¶
type ApiAppHandler ¶
type ApiAppHandlerFunc ¶
func (ApiAppHandlerFunc) ServeHTTP ¶
func (f ApiAppHandlerFunc) ServeHTTP(w http.ResponseWriter, r *http.Request, app *models.App)
ServeHTTP calls f(w, r).
type ApiHandler ¶
type ApiHandler interface {
// Handle(ctx context.Context)
ServeHTTP(w http.ResponseWriter, r *http.Request)
}
type ApiHandlerFunc ¶
type ApiHandlerFunc func(w http.ResponseWriter, r *http.Request)
func (ApiHandlerFunc) ServeHTTP ¶
func (f ApiHandlerFunc) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP calls f(w, r).
type AppListener ¶
type AppListener interface {
// BeforeAppCreate called right before creating App in the database
BeforeAppCreate(ctx context.Context, app *models.App) error
// AfterAppCreate called after creating App in the database
AfterAppCreate(ctx context.Context, app *models.App) error
// BeforeAppUpdate called right before updating App in the database
BeforeAppUpdate(ctx context.Context, app *models.App) error
// AfterAppUpdate called after updating App in the database
AfterAppUpdate(ctx context.Context, app *models.App) error
// BeforeAppDelete called right before deleting App in the database
BeforeAppDelete(ctx context.Context, app *models.App) error
// AfterAppDelete called after deleting App in the database
AfterAppDelete(ctx context.Context, app *models.App) error
}
type HandlerContext ¶
type HandlerContext interface {
// Context return the context object
Context() context.Context
// Request returns the underlying http.Request object
Request() *http.Request
// Response returns the http.ResponseWriter
Response() http.ResponseWriter
// Overwrite value in the context
Set(key string, value interface{})
}
Each handler can modify the context here so when it gets passed along, it will use the new info.
type Middleware ¶
type Middleware interface {
// Serve is what the Middleware must implement. Can modify the request, write output, etc.
// todo: should we abstract the HTTP out of this? In case we want to support other protocols.
Serve(ctx MiddlewareContext, w http.ResponseWriter, r *http.Request, app *models.App) error
}
Middleware is the interface required for implementing functions middlewar
type MiddlewareContext ¶
type MiddlewareContext interface {
context.Context
// 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()
// Index returns the index of where we're at in the chain
Index() int
}
MiddlewareContext extends context.Context for Middleware
type MiddlewareFunc ¶
type MiddlewareFunc func(ctx MiddlewareContext, w http.ResponseWriter, r *http.Request, app *models.App) error
MiddlewareFunc func form of Middleware
func (MiddlewareFunc) Serve ¶
func (f MiddlewareFunc) Serve(ctx MiddlewareContext, w http.ResponseWriter, r *http.Request, app *models.App) error
Serve wrapper
type RunnerListener ¶
type Server ¶
type Server struct {
Datastore models.Datastore
Runner *runner.Runner
Router *gin.Engine
MQ models.MessageQueue
Enqueue models.Enqueue
// contains filtered or unexported fields
}
func New ¶
func New(ctx context.Context, ds models.Datastore, mq models.MessageQueue, apiURL string, opts ...ServerOption) *Server
New creates a new IronFunctions server with the passed in datastore, message queue and API URL
func NewFromEnv ¶
NewFromEnv creates a new IronFunctions server based on env vars.
func (*Server) AddAppEndpoint ¶
func (s *Server) AddAppEndpoint(method, path string, handler ApiAppHandler)
AddAppEndpoint adds an endpoints to /v1/apps/:app/x
func (*Server) AddAppEndpointFunc ¶
func (s *Server) AddAppEndpointFunc(method, path string, handler func(w http.ResponseWriter, r *http.Request, app *models.App))
AddAppEndpoint adds an endpoints to /v1/apps/:app/x
func (*Server) AddAppListener ¶
func (s *Server) AddAppListener(listener AppListener)
AddAppCreateListener adds a listener that will be notified on App created.
func (*Server) AddEndpoint ¶
func (s *Server) AddEndpoint(method, path string, handler ApiHandler)
AddEndpoint adds an endpoint to /v1/x
func (*Server) AddEndpointFunc ¶
func (s *Server) AddEndpointFunc(method, path string, handler func(w http.ResponseWriter, r *http.Request))
AddEndpoint adds an endpoint to /v1/x
func (*Server) AddMiddleware ¶
func (s *Server) AddMiddleware(m Middleware)
AddAppEndpoint adds an endpoints to /v1/apps/:app/x
func (*Server) AddMiddlewareFunc ¶
func (s *Server) AddMiddlewareFunc(m func(ctx MiddlewareContext, w http.ResponseWriter, r *http.Request, app *models.App) error)
AddAppEndpoint adds an endpoints to /v1/apps/:app/x
func (*Server) AddRunnerListener ¶
func (s *Server) AddRunnerListener(listener RunnerListener)
AddRunListeners adds a listener that will be fired before and after a function run.
func (*Server) AddSpecialHandler ¶
func (s *Server) AddSpecialHandler(handler SpecialHandler)
func (*Server) FireAfterAppCreate ¶
func (*Server) FireAfterAppDelete ¶
func (*Server) FireAfterAppUpdate ¶
func (*Server) FireAfterDispatch ¶
func (*Server) FireBeforeAppCreate ¶
func (*Server) FireBeforeAppDelete ¶
func (*Server) FireBeforeAppUpdate ¶
func (*Server) FireBeforeDispatch ¶
type ServerOption ¶
type ServerOption func(*Server)
func EnableShutdownEndpoint ¶
func EnableShutdownEndpoint(halt context.CancelFunc) ServerOption
type SpecialHandler ¶
type SpecialHandler interface {
Handle(c HandlerContext) error
}
type SpecialHandlerContext ¶
type SpecialHandlerContext struct {
// contains filtered or unexported fields
}
func (*SpecialHandlerContext) Context ¶
func (c *SpecialHandlerContext) Context() context.Context
func (*SpecialHandlerContext) Request ¶
func (c *SpecialHandlerContext) Request() *http.Request
func (*SpecialHandlerContext) Response ¶
func (c *SpecialHandlerContext) Response() http.ResponseWriter
func (*SpecialHandlerContext) Set ¶
func (c *SpecialHandlerContext) Set(key string, value interface{})
Source Files
¶
- app_listeners.go
- apps_create.go
- apps_delete.go
- apps_get.go
- apps_list.go
- apps_update.go
- error_response.go
- extension_points.go
- init.go
- middleware.go
- ping.go
- routes_create.go
- routes_delete.go
- routes_get.go
- routes_list.go
- routes_update.go
- runner.go
- runner_listeners.go
- server.go
- server_options.go
- shutdown.go
- singleflight.go
- special_handler.go
- stats.go
- tree.go
- version.go
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
routecache
Package routecache is meant to assist in resolving the most used routes at an application.
|
Package routecache is meant to assist in resolving the most used routes at an application. |