Make any Go function into a API (FaaS)

Overview

faas

Make any (Go) function into an API with one HTTP request.

This is a FaaS: functions as a service. But, in actuality, its more of a FaaSSS: functions as a stupidly simple service. Imagine iron.io/functions, or zeit/now or openfaas or apex or sky-island but more simple and more stupid.

Unlike others, this FaaS requires no coding, no init-ing, no pushing, no updating, and no bumping. You Just make one HTTP request with the name of the package, the name of the function, and any input. Right now it only works for Go. It can easily be extended to Python (WIP).

The codebase is only about 600 lines of code in total. Basically a request tells the server to fetch the function, determine the inputs/outputs and write a wrapper function that is served from a Docker container.

Examples

Try it right now with my instance at https://faas.schollz.com.

You can make (almost) any exported Go function into a API!

Run Md5Sum to get a md5 hash of "hello, world":

$ curl https://faas.schollz.com/?import=github.com/schollz/utils&func=Md5Sum(%22hello,%20world%22)
e4d7f1b4ed2e42d15898f4b27b019da4

Run IngredientsFromURL to get the ingredients from any website:

$ curl https://faas.schollz.com/?import=github.com/schollz/ingredients&func=IngredientsFromURL(%22https://cooking.nytimes.com/recipes/12320-apple-pie%22)
{"ingredients": [{"name":"butter","comment":"unsalted","measure":{"amount":2,"name":"tablespoons","cups":0.25}},{"name":"apples","measure":{"amount":2.5,"name":"pounds","cups":14.901182654402104}},{"name":"allspice","comment":"ground","measure":{"amount":0.25,"name":"teaspoon","cups":0.0104165}},{"name":"cinnamon","comment":"ground","measure":{"amount":0.5,"name":"teaspoon","cups":0.020833}},{"name":"salt","comment":"kosher","measure":{"amount":0.25,"name":"teaspoon","cups":0.0104165}},{"name":"sugar","comment":"plus 1 tablespoon","measure":{"amount":0.75,"name":"cup","cups":1.5}},{"name":"flour","comment":"all purpose","measure":{"amount":2,"name":"tablespoons","cups":0.25}},{"name":"cornstarch","measure":{"amount":2,"name":"teaspoons","cups":0.083332}},{"name":"apple cider vinegar","measure":{"amount":1,"name":"tablespoon","cups":0.125}},{"name":"pie dough","measure":{"amount":1,"name":"whole","cups":0}},{"name":"egg","measure":{"amount":1,"name":"whole","cups":0}}],"err": null

Run MarkdownToHTML from a Go playground:

$ curl -d '{"markdown":"*hello*,**world**"}' \
 	-H "Content-Type: application/json" -X POST \
 	https://faas.schollz.com/?import=https://play.golang.org/p/9xzE8Ivwupk.go&func=MarkdownToHTML
<p><em>hello</em>,<strong>world</strong></p>

Usage

You can use GET or POST to submit jobs.

For the GET requests the syntax is

/?import=IMPORTPATH&func=FUNCNAME(param1,param2...)

The IMPORTPATH is the import path (e.g. github.com/x/y) or a URL containing the file with the function. The FUNCNAME is the name of the function. Note, you do need to URL encode the strings so that FUNCNAME("hello, world") -> FUNCNAME(%22hello,%20world%22)

For the POST requests the syntax is:

/?import=IMPORTPATH&func=FUNCNAME

with the body with the inputs {"param":"value"}.

That's it! The first time you run it will take ~1 minute while the Docker image is built.

How does it work?

When you make a POST/GET request to the faas server it will locate the given function and given package and it will generate a Docker container that accepts a JSON input with the parameters and outputs a JSON containing the output variables. This Docker container automatically shuts down after some time of inactivity. Subsequent requests then will load the previously built container for use.

Host yourself

You need to install Docker, and make sure gzip is installed.

Then build faas with Go:

git clone https://github.com/schollz/faas
cd faas
go generate
go build -v

Now you can run:

./faas --debug

Now you can try it out:

curl http://localhost:8090/?import=github.com/schollz/utils&func=Md5Sum(%22hello,%20world%22)

OR post data:

curl -d '{"s":"hello, world"}' -H "Content-Type: application/json" -X POST http://localhost:8090/?import=github.com/schollz/utils&func=Md5Sum

Note that the JSON "s" comes from the function Md5Sum itself.

License

MIT

Releases(v0.1.0)
Owner
Zack
Tinkerer
Zack
Cli tool to translate text from any language into german

GERMAN A cli tool for converting text into German. Build Locally $> go build $> go install Dependencies To execute successfully, a free tier DEEPL API

Kieran O'Sullivan 3 Jan 24, 2022
Pack a Go workflow/function as a Unix-style pipeline command

tpack Pack a Go workflow/function as a Unix-style pipeline command. Wiki In Unix-like computer operating systems, a pipeline is a mechanism for inter-

Eugene R. 56 Jun 1, 2022
go-shellcommand is the package providing the function System like the one of the programming language C.

go-shellcommand go-shellcommand is the package providing the function System like the one of the programming language C. process, err := shellcommand.

zetamatta 1 Oct 17, 2021
Build command for lambda function

Build command for lambda function GOOS=linux GOARCH=amd64 go build -o main main.go logger.go get_csv.go DynamoDBCreateItem.go #Local Development sam l

David Davila 0 Nov 15, 2021
Free5GC Network Function (NF) Command Line Interface (CLI)

NFCLI free5GC Network Function (NF) Command Line Interface (CLI) based on Thrift Thrift Installation Steps Donwload Thrift 0.15.0 ./bootstrap.sh ./con

Muthuraman Elangovan 0 Jan 11, 2022
A client for managing authzed or any API-compatible system from your command line.

zed A client for managing authzed or any API-compatible system from your command line. Installation zed is currently packaged by as a head-only Homebr

authzed 40 Jun 28, 2022
JOB, make your short-term command as a long-term job. 将命令行规划成任务的工具

job make your short-term command as a long-term job Install Shell Install (Linux & MacOS) # binary will be $(go env GOPATH)/bin/job $: curl -sfL https

JayL 115 Jun 24, 2022
An easy to use menu structure for cli applications that prompts users to make choices.

WMenu Package wmenu creates menus for cli programs. It uses wlog for its interface with the command line. It uses os.Stdin, os.Stdout, and os.Stderr w

Will Dixon 163 Jun 18, 2022
Make Highly Customized Boxes for your CLI

Box CLI Maker ?? Box CLI Maker is a Highly Customized Terminal Box Creator. Features Make Terminal Box in 8️⃣ inbuilt different styles 16 Inbuilt Colo

Swastik Baranwal 211 Jun 17, 2022
Go package to make lightweight ASCII line graph ╭┈╯ in command line apps with no other dependencies.

asciigraph Go package to make lightweight ASCII line graphs ╭┈╯. Installation go get github.com/guptarohit/asciigraph Usage Basic graph package main

Rohit Gupta 2k Jun 23, 2022
An attempt to make a cli for dev.to in Go

Devto a cli for dev.to This is a work in progress so don't a expect a full support for Dev API(beta). Table of contents Devto a cli for dev.to Table o

Gealber Morales 5 Mar 13, 2022
Minutes is a CLI tool for synchronizing work logs between multiple time trackers, invoicing, and bookkeeping software to make entrepreneurs' daily work easier.

Minutes is a CLI tool for synchronizing work logs between multiple time trackers, invoicing, and bookkeeping software to make entrepreneurs' daily work easier.

Gábor Boros 19 Jun 19, 2022
Make Link with Markdown Format

ml -- Make Link with Markdown Format This package is required Go 1.16 or later. Build and Install $ go install github.com/spiegel-im-spiegel/[email protected]

Spiegel 3 Mar 20, 2022
This repository contains utility functions that do not make sense in other packages.

Installation go get github.com/IQ-tech/go-utils Executing code before process exits AtInterruption receives a function that will be called once befor

IQ Tech 0 Dec 9, 2021
This package to make it easy to work with env

Go Env This package to make it easy to work with env Example usage package main

Sergey A. 3 Jan 30, 2022
Bofin - A command line tool that can be used by to make Weblink development more productive

Bofin A command line tool that can be used by to make Weblink development more p

Gavin Bannerman 0 Jan 13, 2022
A daemon to make your keyboard backlight smart.

keyboard-backlight-daemon A daemon to make your keyboard backlight smart. Features Light up keyboard backlight based on user interaction (keyboard, mo

Markus Ressel 0 Jan 17, 2022
Marshallable - Make generic data types marshallable

Marshallable Make generic data types marshallable! Features Implement methods: S

null 3 Feb 15, 2022
It‘s a cmd-line tool like `make` and `task`, supporting nested args and alias using `cobra`

It‘s a cmd-line tool like `make` and `task`, supporting nested args and alias using `cobra`. It's a makefile alternative and a shell wrapper.

null 2 Apr 14, 2022