tinyfaas

package module
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 30, 2024 License: MIT Imports: 8 Imported by: 0

README

go-tinyfaas

tinyFaaS wrapper to manage and deploy functions to a remote tinyFaaS server.

Usage

import TinyFaaS "github.com/ChaosRez/go-tinyfaas"

// set a local path of functions, e.g. tinyfaas directory
const functionsPath = "../faas/tinyfaas/" 

// initialize tinyFaaS manager instance
tf := TinyFaaS.New("localhost", "8080", functionsPath)  // management port is 8080 by default

// upload a function from local, assuming the function is in the functionsPath by default
respU, err := tf.UploadLocal("sieve", "test/fns/sieve-of-eratosthenes", "nodejs", 1)
// upload a function from local with full path, and environment variables
respU, err := tf.UploadLocal("sieve", "full-path/to/sieve-of-eratosthenes", "nodejs", 1, true, args)
// upload a function from a remote URL
respU, err := tf.UploadURL("sieve", "tinyFaaS-main/test/fns/sieve-of-eratosthenes", "nodejs", 1, "https://github.com/OpenFogStack/tinyFaas/archive/main.zip")

// Check tinyFaaS response. (incl. timeout, ok, other errors?)
if err != nil {
log.Fatalln("error when calling tinyFaaS: ", err)
}
// Print the response
log.Infof("upload success:\n%s", respU) // 200 success, 400 bad request

// delete a function
errD := tf.Delete("sieve")

// Check tinyFaaS response. (incl. timeout, ok, other errors?)
if errD != nil {
log.Fatalln("error when calling tinyFaaS: ", errD)
}

// get results log
respL, errL := tf.ResultsLog()

// Check tinyFaaS response. (incl. timeout, ok, other errors?)
if errL != nil {
log.Fatalln("error when calling tinyFaaS: ", errL)
}
// Print the response
fmt.Printf("results log: %s\n", respL) // 200 success

// list functions
respF := tf.Functions()
// Print the response
fmt.Printf("functions: %s\n", respF)

// remove all functions
tf.WipeFunctions()

// call a function by value
tf.Call("sieve", "10")

Contributing and License

Pull requests are welcome. If you inspire this project to create your own tinyFaaS wrapper in other languages, please mention this project.
This project is licensed under the MIT License - see the LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type TinyFaaS

type TinyFaaS struct {
	Host string
	Port string
	Path string
}

func New

func New(host, port, path string) *TinyFaaS

func (*TinyFaaS) Call

func (tf *TinyFaaS) Call(funcName string, data string) (string, error)

func (*TinyFaaS) Delete

func (tf *TinyFaaS) Delete(funcName string) error

func (*TinyFaaS) Functions

func (tf *TinyFaaS) Functions() (string, error)

Functions lists available functions

func (*TinyFaaS) ResultsLog

func (tf *TinyFaaS) ResultsLog() (string, error)

func (*TinyFaaS) UploadLocal

func (tf *TinyFaaS) UploadLocal(funcName string, path string, env string, threads int, isFullPath bool, args []string) (string, error)

func (*TinyFaaS) UploadURL

func (tf *TinyFaaS) UploadURL(funcName string, subPath string, env string, threads int, url string, args []string) (string, error)

func (*TinyFaaS) WipeFunctions

func (tf *TinyFaaS) WipeFunctions() error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL