目前支持的扩展方式
 
  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. 《Pro Git》第3章 分支

    1.分支简介 git保存的不是文件的差异,而是不同时刻的文件快照 git仓库中的对象: commit对象:包含指向前一个commit的指针的所有提交信息 树对象:记录目录结构和blob对象索引 blo ...

  2. [BZOJ1257]余数之和

    Description 给出正整数n和k,计算j(n, k)=k mod 1 + k mod 2 + k mod 3 + … + k mod n的值 其中k mod i表示k除以i的余数. 例如j(5 ...

  3. [nowcoder]因数个数和

    链接:https://www.nowcoder.com/acm/contest/158/A 考虑每个数对答案的贡献,所以答案就是$\sum_{i=1}^{n}{\lfloor\frac{n}{i}\r ...

  4. 并发-ThreadLocal源码分析

    ThreadLocal源码分析 参考: http://www.cnblogs.com/dolphin0520/p/3920407.html https://www.cnblogs.com/coshah ...

  5. Effective C++ 条款01:视C++为一个语言联邦

    四个次语言 C Object-Oriented C++ Template C++ STL

  6. Java Collections Framework Java集合框架概览

    Java SE documents -- The Collections Framework http://docs.oracle.com/javase/8/docs/technotes/guides ...

  7. JSON和GSON的使用

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

  8. Python StringIO实现内存缓冲区中读写数据

    StringIO的行为与file对象非常像,但它不是磁盘上文件,而是一个内存里的“文件”,我们可以像操作磁盘文件那样来操作StringIO.这篇文章主要介绍了Python StringIO模块,此模块 ...

  9. python fire库的使用

    一. 介绍 fire是python中用于生成命令行界面(Command Line Interfaces, CLIs)的工具,不需要做任何额外的工作,只需要从主模块中调用fire.Fire(),它会自动 ...

  10. python中sorted()函数的用法

    一. 定义 sorted()函数对所有可迭代的对象进行排序操作 二. 语法 sorted(iterable [, key[, reverse]]]) iterable:可迭代对象 key:主要是用来进 ...