mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Update listener docs (#398)
* add listener docs * removed TODO and added more listener info * removing invalid route from appupdatelistener
This commit is contained in:
@@ -6,13 +6,69 @@ IronFunctions is extensible so you can add custom functionality and extend the p
|
||||
|
||||
Listeners are the main way to extend IronFunctions.
|
||||
|
||||
To add listeners, copy `main.go` into your own repo and add your own listener implementations. When ready,
|
||||
compile your main package to create your extended version of IronFunctions.
|
||||
You can easily use listeners basically creating a struct with [valid methods](#Listener Requirements) and adding it to the `IronFunctions API`.
|
||||
|
||||
### AppListener
|
||||
Example:
|
||||
|
||||
Implement `ifaces/AppListener` interface, then add it using:
|
||||
|
||||
```go
|
||||
server.AddAppListener(myAppListener)
|
||||
```
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/iron-io/functions/api/server"
|
||||
"github.com/iron-io/functions/api/models"
|
||||
)
|
||||
|
||||
type myCustomListener struct{}
|
||||
|
||||
func (c *myCustomListener) BeforeAppCreate(ctx context.Context, app *models.App) error { return nil }
|
||||
func (c *myCustomListener) AfterAppCreate(ctx context.Context, app *models.App) error { return nil }
|
||||
|
||||
func (c *myCustomListener) BeforeAppUpdate(ctx context.Context, app *models.App) error { return nil }
|
||||
func (c *myCustomListener) AfterAppUpdate(ctx context.Context, app *models.App) error { return nil }
|
||||
|
||||
func (c *myCustomListener) BeforeAppDelete(ctx context.Context, appName string) error { return nil }
|
||||
func (c *myCustomListener) BeforeAppDelete(ctx context.Context, appName string) error { return nil }
|
||||
|
||||
function main () {
|
||||
srv := server.New(/* Here all required parameters to initialize the server */)
|
||||
|
||||
srv.AddAppCreateListener(myCustomListener)
|
||||
srv.AddAppUpdateListener(myCustomListener)
|
||||
srv.AddAppDeleteListener(myCustomListener)
|
||||
|
||||
srv.Run()
|
||||
}
|
||||
```
|
||||
|
||||
#### Listener Requirements
|
||||
|
||||
To be a valid listener your struct should respect interfaces combined or alone found in the file [listeners.go](/iron-io/functions/blob/master/api/ifaces/listeners.go)
|
||||
|
||||
These are all available listeners:
|
||||
|
||||
##### AppCreateListener
|
||||
|
||||
_Triggers before and after every app creation that happens in the API_
|
||||
|
||||
Triggered on requests to the following routes:
|
||||
|
||||
- POST /v1/apps
|
||||
- POST /v1/apps/:app/routes
|
||||
|
||||
##### AppUpdateListener
|
||||
|
||||
_Triggers before and after every app updates that happens in the API_
|
||||
|
||||
Triggered during requests to the following routes:
|
||||
|
||||
- PUT /v1/apps
|
||||
|
||||
##### AppDeleteListener
|
||||
|
||||
_Triggers before and after every app deletion that happens in the API_
|
||||
|
||||
Triggered during requests to the following routes:
|
||||
|
||||
- DELETE /v1/apps/app
|
||||
Reference in New Issue
Block a user