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. ...
随机推荐
- 外部类与main方法笔记
外部类 1. 外部public class只能有一个 2. 外部类只能有两种访问控制级别: public 和默认 3. 一个文件中,可以有多个public class,即外部类为public,还可以有 ...
- sql server 数据库复制实现数据同步常见问题(不定期更新)
sql server2008数据库复制实现数据同步常见问题 在原作者基础上追加 sql server2008数据库复制实现数据同步常见问题 23.发布 'xx' 的并发快照不可用,因为该快照尚未完全生 ...
- Hibernate -- 一对多的双向关联关系
示例代码: Customer.java package cn.itcast.many2onedouble; import java.util.HashSet; import java.util.Set ...
- NumPy排序、搜索和计数函数
NumPy - 排序.搜索和计数函数 NumPy中提供了各种排序相关功能. 这些排序函数实现不同的排序算法,每个排序算法的特征在于执行速度,最坏情况性能,所需的工作空间和算法的稳定性. 下表显示了三种 ...
- 缓存技术内部交流_01_Ehcache3简介
参考资料: http://www.ehcache.org/documentation/3.2/getting-started.html http://www.ehcache.org/documenta ...
- Selenium with Python 010 - unittest 框架(又称PyUnit 框架)
unittest进行python代码单元测试 calculator.py--被测试类 #!/usr/bin/env python # -*- coding: utf-8 -*- # 将要被测试的类 c ...
- 获得Ztree选择的节点
$('#save').click(function(){ if($("#roleForm").form("validate")){ var treeObj = ...
- 牛客比赛-假的字符串-Trie+拓扑
链接:https://www.nowcoder.com/acm/contest/59/B来源:牛客网 题目描述 给定n个字符串,互不相等,你可以任意指定字符之间的大小关系(即重定义字典序),求有多少个 ...
- 国外DDoS产品的一些调研—— Akamai Arbor Networks Cloudflare DOSarrest F5 Fastly Imperva Link11 Neustar Nexusguard Oracle (Dyn) Radware Verisign
Global DDoS Threat LandscapeQ4 2017 https://www.incapsula.com/ddos-report/ddos-report-q4-2017.html,D ...
- [eShopOnContainers 学习系列] - 01 - Roadmap and Milestones for future releases
https://github.com/dotnet-architecture/eShopOnContainers/wiki/01.-Roadmap-and-Milestones-for-future- ...