python julia go_一键把你的 Java ,Go, PHP , Node/JavaScript, Python , Ruby, Julia 函数变成一个服务...

fx

Poor man's function as a service.

Introduction

fx is a tool to help you do Function as a Service on your own server. fx can make your stateless function a service in seconds. The most exciting thing is that you can write your functions with most programming languages.

Language

Status

Contributor

Go

Supported

fx

Node

Supported

fx

Python

Supported

fx

Ruby

Supported

fx

Java

Supported

fx

PHP

Supported

Julia

Supported

Scala

Working on

Perl

Working on

.Net

Working on

Rust

Working on

Welcome to tweet me or Buy me a coffee

Installation

MacOS

brew tap metrue/homebrew-fx

brew install fx

Linux/Unix

To install fx, you can use the install script using cURL:

curl -o- https://raw.githubusercontent.com/metrue/fx/master/bin/install.sh | bash

or Wget:

wget -qO- https://raw.githubusercontent.com/metrue/fx/master/bin/install.sh | bash

fx will be installed into /usr/local/bin, if fx not found after installation, you may need to checkout if /usr/local/bin/fx exists.

sometimes you may need source ~/.zshrc or source ~/.bashrc to make fx available on $PAHT.

Window

You can go the release page to download fx manually;

Usage

Make sure Docker installed and running on your server first.

start server

fx serve

now you can make a function to service in a second.

fx up ./examples/functions/func.js

the function defined in examples/functions/func.js is quite simple, it calculates the sum of two numbers then returns:

module.exports = (input) => {

return parseInt(input.a, 10) + parseInt(input.b, 10)

}

then you can test your service:

curl -X POST -H "Content-Type: application/json" -d '{"a": 1, "b": 1}'

of course you can do more.

Usage:

$ fx serve start f(x) server

$ fx up func1.js func2.py func3.go ... deploy a function or a group of functions

$ fx down [service ID] ... destroy a function or a group of functions

$ fx list list deployed services

$ fx --version show current version of f(x)

How to write your function

functions example with Go, Ruby, Python, Node, PHP, Java, Julia.

Go

package main

type Input struct {

A int32

B int32

}

type Output struct {

Sum int32

}

func Fx(input *Input) (output *Output) {

output = &Output{

Sum: input.A + input.B,

}

return

}

Ruby

def fx(input)

return input['a'] + input['b']

end

Java

package fx;

import org.json.JSONObject;

public class Fx {

public int handle(JSONObject input) {

String a = input.get("a").toString();

String b = input.get("b").toString();

return Integer.parseInt(a) + Integer.parseInt(b);

}

}

Python

def fx(input):

return input['a'] + input['b']

Node

module.exports = (input) => {

return parseInt(input.a, 10) + parseInt(input.b, 10)

}

PHP

function Fx($input) {

return $input["a"]+$input["b"];

}

Julia

struct Input

a::Number

b::Number

end

fx = function(input::Input)

return input.a + input.b

end

Contributing

Requirements

Docker: make sure Docker installed and running on your server.

dep: fx project uses dep to do the golang dependency management.

Build and Run

$ git clone https://github.com/metrue/fx.git

$ cd fx

$ make install-deps && make build

$ ./build/fx serve # start your fx server

$ ./build/fx up func.js # deploy a function

Thank you to all the people who already contributed to fx!

LICENSE

MIT

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值