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. ...
随机推荐
- 二叉树、平衡二叉树、B-Tree与B+Tree
本文总结自:https://blog.csdn.net/chuixue24/article/details/80027689 二叉树(B树,binary tree) 左子树的键值 < 根的键值 ...
- bzoj 1623: [Usaco2008 Open]Cow Cars 奶牛飞车
1623: [Usaco2008 Open]Cow Cars 奶牛飞车 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 325 Solved: 223[S ...
- Metasploit – 内网连接
0x00 问题描述 在渗透测试时,metasploit往往作为后渗透工具,(因为远程溢出越来越少).我一般都是在获得一个webshell后,来使用metasploit进行信息采集,或者内网扫描等操作. ...
- python 中 正则表达式 的应用
python 中 正则表达式 的应用 最近作业中出现了正则表达式,顺便学习了一下. python比较厉害的一点就是自带对正则表达式的支持,用起来很方便 正则表达式 首先介绍一下什么是正则表达式. 正则 ...
- JavaScript中this关键字的使用比较
JavaScript中this关键字的使用比较 this关键字在JavaScript中,用的不能说比较多,而是非常多.那么熟悉this关键字的各种用法则显得非常关键. this有时候就是我们经常说的上 ...
- 多线程之wait,notify,volatile,synchronized,sleep
最近在学习多线程,现在进行总结一下吧.首先要了解一下以下几个名词. (1)wait:当线程调用wait()方法时,当前该线程会进入阻塞状态,且释放锁,使用wait方法的时候,必须配合synchroni ...
- .net 数据脱敏代码实现
方案一: DTO中处理: private string idNumber; /// <summary> /// 身份证号码 /// </summary> [Column(&qu ...
- 关于EventBus3.0使用,你看这篇就够了
作为一枚Android开发者,关于EventBus相信应该都听说过.要是用过就请忽略本文,本文讲得比较基础. 要是没用过,建议你花两分钟看看. 目前EventBus最新版本是3.0,本demo基于3. ...
- C++(二十一) — 引用概念及本质
1.引用概念 引用是别名,必须在声明的时候初始化.即:是指一个已定义变量的别名.(一个内存空间,有两个名字都可以操作) 引用:在函数调用时,是变量的别名,不可以单独存在,使用时必须要初始化: 指针: ...
- nyoj-5-kmp裸题
题目链接: http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=5 kmp统计匹配串出现次数,贼尴尬好久没做字符串题目,一开始求得是文本串的next ...