fn project 扩展
- Listeners - listen to API events such as a route getting updated and react accordingly.
- Middleware - a chain of middleware is executed before an API handler is called.
- Add API Endpoints - extend the default Fn API.
Listeners
Listeners are the main way to extend Fn.
The following listener types are supported:
Creating a Listener
You can easily use app and runner listeners by creating a struct with valid methods satisfying the interface for the respective listener and adding it to the Fn API
Example:
package main
import (
"context"
"github.com/fnproject/functions/api/server"
"github.com/fnproject/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, app *models.App) error { return nil }
func (c *myCustomListener) BeforeAppDelete(ctx context.Context, app *models.App) error { return nil }
function main () {
srv := server.New(/* Here all required parameters to initialize the server */)
srv.AddAppListener(myCustomListener)
srv.Run()
}
Middleware
Middleware enables you to add functionality to every API request. For every request, the chain of Middleware will be called in order, allowing you to modify or reject requests, as well as write output and cancel the chain.
NOTES:
- middleware is responsible for writing output if it's going to cancel the chain.
- cancel the chain by returning an error from your Middleware's Serve method.
See examples of this in examples/middleware/main.go.
Adding API Endpoints
You can add API endpoints to the Fn server by using the AddEndpoint
and AddEndpointFunc
methods.
See examples of this in examples/extensions/main.go.
fn project 扩展的更多相关文章
- jQuery $.fn 方法扩展~
//以下代码紧跟在引进的jquery.js代码后面 <script type="Text/JavaScript"> $(function (){ //扩展myName方 ...
- jQuery.extend()、jQuery.fn.extend()扩展方法示例详解
jQuery自定义了jQuery.extend()和jQuery.fn.extend()方法.其中jQuery.extend()方法能够创建全局函数或者选择器,而jQuery.fn.extend()方 ...
- jQuery.extend()、jQuery.fn.extend()扩展方法具体解释
版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/dreamsunday/article/details/25193459 jQuery自己定义了jQu ...
- fn project 试用之后的几个问题的解答
今天试用fnproject 之后自己有些思考,后面继续解决 1. 目前测试是强依赖 dockerhub 的,实际可能不是很方便 2. 如何与k8s .mesos.docker swarm 集成 ...
- fn project 生产环境使用
此为官方的参考说明 Running Fn in Production The QuickStart guide is intended to quickly get started and kic ...
- fn project 对象模型
Applications At the root of everything are applications. In fn, an application is essentially a grou ...
- fn project AWS Lambda 格式 functions
Creating Lambda Functions Creating Lambda functions is not much different than using regular funct ...
- fn project 打包Function
Option 1 (recommended): Use the fn cli tool We recommend using the fn cli tool which will handle a ...
- fn project Function files 说明
主要是文件 func.yaml func.json 详细说明如下: An example of a function file: name: fnproject/hello version: 0.0. ...
随机推荐
- 2062326 齐力锋 实验四《Java面向对象程序设计Android开发》实验报告
北京电子科技学院(BESTI) 实 验 报 告 课程: 程序设计与数据结构 班级: 1623 姓名: 齐力锋 学号: 20162326 成绩: 指导教师: 娄嘉鹏/王志强 实验日期: 2017年5 ...
- react-native navigation的学习与使用
在很久之前,RN中文网说推荐用react-navigation替代navigator作为新的导航库,从RN 0.43版本开始,官方就已经停止维护Navigator了,所以强烈建议大家迁移到新的reac ...
- dedecms 织梦利用arcpagelist标签实现首页arclist分页
DedeCMS首页arclist分页可以利用arcpagelist标签来实现,这里说一下调用方法:首先必须在首页的<head></head>标签里面引入如下js代码: < ...
- Hibernate -- 项目结构模型改造, 加 Utils 和 Dao层
示例代码: App.java 模拟客户端 /** * 模拟客户端 */ public class App { @Test public void saveCustomer(){ CustomerDao ...
- 修改Tomcat默认端口号,避免与IDEA冲突
修改Tomcat默认端口号,避免与IDEA冲突 APT安装默认位置如下 /var/lib/tomcat8/conf 修改server.xml中的8080端口为8088或其他. 重启服务,试试看效果. ...
- BZOJ 4726 [POI2017]Sabota?:树形dp
传送门 题意 某个公司有 $ n $ 个人,上下级关系构成了一个有根树.其中有个人是叛徒(这个人不知道是谁).对于一个人, 如果他下属(直接或者间接, 不包括他自己)中叛徒占的比例超过 $ x $ , ...
- yii2:多表查询
啥都不说了,上代码: $list = static::find() ->leftJoin('book', 'book.RID = prices.RID')->select('prices. ...
- 为Visual Studio添加快捷工具
添加额外工具: Tools -> External Tools... 1. 添加Git Console Title: Git Console Command: C:\Program Files\ ...
- python 超时异常处理
异常处理具体见:[循序渐进学Python]9.异常处理 环境平台:Python2.7.9 + Win8.1 本篇记录一下自己写爬虫的遇到的问题,程序中批量获取图片地址,然后批量保存.由于没有设置网址打 ...
- Redis 安装,配置,简介,数据类型(一)
Redis 安装 Window 下安装 下载地址:https://github.com/MSOpenTech/redis/releases. Redis 支持 32 位和 64 位.这个需要根据你 ...