Files
m3o-go/examples/function/README.md
2021-11-17 16:55:33 +00:00

2.5 KiB
Executable File

Function

An m3o.com API. For example usage see m3o.com/Function/api.

Endpoints:

List

List all the deployed functions

https://m3o.com/function/api#List

package example

import(
	"fmt"
	"os"

	"go.m3o.com/function"
)

// List all the deployed functions
func ListFunctions() {
	functionService := function.NewFunctionService(os.Getenv("M3O_API_TOKEN"))
	rsp, err := functionService.List(&function.ListRequest{
		
	})
	fmt.Println(rsp, err)
	
}

Delete

Delete a function by name

https://m3o.com/function/api#Delete

package example

import(
	"fmt"
	"os"

	"go.m3o.com/function"
)

// Delete a function by name
func DeleteAfunction() {
	functionService := function.NewFunctionService(os.Getenv("M3O_API_TOKEN"))
	rsp, err := functionService.Delete(&function.DeleteRequest{
		Name: "my-first-func",
Project: "tests",

	})
	fmt.Println(rsp, err)
	
}

Describe

Get the info for a deployed function

https://m3o.com/function/api#Describe

package example

import(
	"fmt"
	"os"

	"go.m3o.com/function"
)

// Get the info for a deployed function
func DescribeFunctionStatus() {
	functionService := function.NewFunctionService(os.Getenv("M3O_API_TOKEN"))
	rsp, err := functionService.Describe(&function.DescribeRequest{
		Name: "my-first-func",
Project: "tests",

	})
	fmt.Println(rsp, err)
	
}

Deploy

Deploy a group of functions

https://m3o.com/function/api#Deploy

package example

import(
	"fmt"
	"os"

	"go.m3o.com/function"
)

// Deploy a group of functions
func DeployAfunction() {
	functionService := function.NewFunctionService(os.Getenv("M3O_API_TOKEN"))
	rsp, err := functionService.Deploy(&function.DeployRequest{
		Entrypoint: "helloworld",
Name: "my-first-func",
Project: "tests",
Repo: "github.com/m3o/nodejs-function-example",
Runtime: "nodejs14",

	})
	fmt.Println(rsp, err)
	
}

Call

Call a function by name

https://m3o.com/function/api#Call

package example

import(
	"fmt"
	"os"

	"go.m3o.com/function"
)

// Call a function by name
func CallAfunction() {
	functionService := function.NewFunctionService(os.Getenv("M3O_API_TOKEN"))
	rsp, err := functionService.Call(&function.CallRequest{
		Name: "my-first-func",
Request: map[string]interface{}{
},

	})
	fmt.Println(rsp, err)
	
}