目前支持的扩展方式
 
  1. Listeners - listen to API events such as a route getting updated and react accordingly.
  2. Middleware - a chain of middleware is executed before an API handler is called.
  3. 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 扩展的更多相关文章

  1. jQuery $.fn 方法扩展~

    //以下代码紧跟在引进的jquery.js代码后面 <script type="Text/JavaScript"> $(function (){ //扩展myName方 ...

  2. jQuery.extend()、jQuery.fn.extend()扩展方法示例详解

    jQuery自定义了jQuery.extend()和jQuery.fn.extend()方法.其中jQuery.extend()方法能够创建全局函数或者选择器,而jQuery.fn.extend()方 ...

  3. jQuery.extend()、jQuery.fn.extend()扩展方法具体解释

    版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/dreamsunday/article/details/25193459 jQuery自己定义了jQu ...

  4. fn project 试用之后的几个问题的解答

    今天试用fnproject  之后自己有些思考,后面继续解决   1. 目前测试是强依赖 dockerhub 的,实际可能不是很方便 2. 如何与k8s .mesos.docker swarm  集成 ...

  5. fn project 生产环境使用

    此为官方的参考说明   Running Fn in Production The QuickStart guide is intended to quickly get started and kic ...

  6. fn project 对象模型

    Applications At the root of everything are applications. In fn, an application is essentially a grou ...

  7. fn project AWS Lambda 格式 functions

      Creating Lambda Functions Creating Lambda functions is not much different than using regular funct ...

  8. fn project 打包Function

      Option 1 (recommended): Use the fn cli tool We recommend using the fn cli tool which will handle a ...

  9. fn project Function files 说明

    主要是文件 func.yaml func.json 详细说明如下: An example of a function file: name: fnproject/hello version: 0.0. ...

随机推荐

  1. 20145219 《Java程序设计》第16周课程总结

    20145219 <Java程序设计>第16周课程总结 每周读书笔记(即学习总结)链接汇总 第0周问卷调查 第1周读书笔记 第2周读书笔记 第3周读书笔记 第4周读书笔记 第5周读书笔记 ...

  2. 关于ARM指令中位置无关和位置相关代码的认识【转】

    本文转载自:https://blog.csdn.net/talent_CYJ/article/details/50533153 今天在一个问题上折腾了又是半天.就是在学JZ2440串口通信的时候,在s ...

  3. Java中遍历map的四种方法 - 转载

    在Java中如何遍历Map对象 How to Iterate Over a Map in Java 在java中遍历Map有不少的方法.我们看一下最常用的方法及其优缺点. 既然java中的所有map都 ...

  4. eclipse中使用adb连接小米2调试程序的问题.

    http://jingyan.baidu.com/article/8065f87fcbec19233124983e.html eclipse连接小米2调试程序的问题. | 浏览:5494 | 更新:2 ...

  5. MyEclipse 为xml添加本地的dtd文件

    在使用Eclipse或MyEclipse编辑XML文件的时候经常会碰到编辑器不提示的现象,这常常是因为其xml文件需要参考的DTD文件找不到,还有因为网络的问题不能及时提示而产生的.Eclipse/M ...

  6. Text Justification,文本对齐

    问题描述:把一个集合的单词按照每行L个字符放,每行要两端对齐,如果空格不能均匀分布在所有间隔中,那么左边的空格要多于右边的空格,最后一行靠左对齐. words: ["This", ...

  7. JSON和GSON的使用

    JSONObject 处理问题 相关博客参考:https://www.cnblogs.com/free-dom/p/5801866.html json-lib 和google gson 的使用 Tor ...

  8. 二维码(QR code)基本结构及生成原理

    什么是二维码 二维码 (2-dimensional bar code),是用某种特定的几何图形按一定规律在平面(二维方向上)分布的黑白相间的图形记录数据符号信息的. 在许多种类的二维条码中,常用的码制 ...

  9. HYSBZ - 2301 莫比乌斯反演

    链接 题解:直接用公式算,用容斥来减掉重复计算的部分 但是我犯了一个非常sb的错误,直接把abcd除k了,这样算a-1的时候就错了,然后举的例子刚好还没问题= = ,结果wa了好几发 //#pragm ...

  10. oepnstack笔记

    openstack简介: 组件:Nova 提供计算资源池neutron 网络资源管理horizon 基于openstack API借口使用django开发的web管理 组件:Nova 提供计算资源池n ...