目前支持的扩展方式
 
  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. 20145201《Java程序设计》第五次实验报告

    实验五 Java网络编程及安全 实验内容 1.掌握Socket程序的编写: 2.掌握密码技术的使用: 3.设计安全传输系统. 我负责客户端 组队队员:鄢曼君20145227负责服务器 博客地址:htt ...

  2. C3p0的参数

    C3p0的参数设置:ComboPooledDataSource和BasicDataSource一样提供了一个用于关闭数据源的close()方法,这样我们就可以保证Spring容器关闭时数据源能够成功释 ...

  3. CA认证_demo

    CA认证,即电子认证服务 [1]  ,是指为电子签名相关各方提供真实性.可靠性验证的活动. 证书颁发机构(CA, Certificate Authority)即颁发数字证书的机构.是负责发放和管理数字 ...

  4. 使用MyCat分表分库原理分析

    Mycat可以实现 读写分离 分表分库 主从复制是MySQL自带的哈~ 关于分片取模算法:  根据id进行取模  根据数据库集群的数量(或者说是表数量,mycat里面一个表对应一个库) 使用MyCat ...

  5. 堆与堆排序、Top k 问题

     堆排序与快速排序,归并排序一样都是时间复杂度为O(N*logN)的几种常见排序方法.学习堆排序前,先讲解下什么是数据结构中的二叉堆. 二叉堆的定义 二叉堆是完全二叉树或者是近似完全二叉树. 二叉堆满 ...

  6. scala学习手记34 - trait方法的延迟绑定

    trait的方法的延迟绑定就是先混入的trait的方法会后调用.这一点从上一节的实例中也可以看出来. 下面再来看一个类似的例子: abstract class Writer { def write(m ...

  7. MySQL主从配置实现

    //////////////////////MySQL主从配置//////////////////////////// 首先,两边都要安装MySQL,启动两边的MySQL 接着,配置主从,要保证主从数 ...

  8. Node.js基础知识普及

    Node.js只支持单线程,故不会产生死锁,采用非阻塞I/O机制和事件环机制.非常适合与开发需要处理大量并发的输入/输出的应用程序.   一. Node.js的核心模块有很多,这里先写几个比较常用的( ...

  9. spring3: Bean的作用域

    3.4  Bean的作用域 什么是作用域呢?即“scope”,在面向对象程序设计中一般指对象或变量之间的可见范围.而在Spring容器中是指其创建的Bean对象相对于其他Bean对象的请求可见范围. ...

  10. Nginx优化思路

    对于高性能网站 ,请求量大,如何支撑? 1方面,要减少请求 对于开发人员----合并css, 背景图片, 减少mysql查询等. 2: 对于运维 nginx的expires ,利用浏览器缓存等,减少查 ...