functions

package
v0.9.3 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2023 License: MIT Imports: 7 Imported by: 3

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Call

func Call(value string) basic.Op

func Channel

func Channel(value string) basic.Op

func Command

func Command(value string) basic.Op

func Description

func Description(value string) basic.Op

func Domains

func Domains(value []string) basic.Op

func Id

func Id(value string) basic.Op

func Local

func Local(value bool) basic.Op

func Memory

func Memory(value string) basic.Op

func Method

func Method(value string) basic.Op

func Paths

func Paths(value []string) basic.Op

func Protocol

func Protocol(value string) basic.Op

func SmartOps

func SmartOps(value []string) basic.Op

func Source

func Source(value string) basic.Op

func Tags

func Tags(value []string) basic.Op

func Timeout

func Timeout(value string) basic.Op

func Type

func Type(value string) basic.Op

Types

type Function

type Function interface {
	Get() Getter
	common.Resource[*structureSpec.Function]
}
Example
package main

import (
	"fmt"

	"github.com/spf13/afero"
	"github.com/taubyte/go-project-schema/functions"
	"github.com/taubyte/go-project-schema/project"
)

func main() {
	// Create a new file system in memory
	fs := afero.NewMemMapFs()

	// Open a new project with a virtual file system
	project, err := project.Open(project.VirtualFS(fs, "/"))
	if err != nil {
		return
	}

	// Create or open an function
	fun, err := project.Function("test_func", "")
	if err != nil {
		return
	}

	// Set and write function fields
	err = fun.Set(true,
		functions.Id("QmaEBKzOyrYL1D6gtqD86Nyr2hvXAxWHcMCu9ffxLaByMc"),
		functions.Description("a basic function"),
		functions.Tags([]string{"tag1", "tag2"}),
		functions.Type("https"),
		functions.Timeout("15s"),
		functions.Memory("64MB"),
		functions.Call("ping"),
		functions.Source("."),
		functions.Method("GET"),
		functions.Paths([]string{"/"}),
		functions.Domains([]string{"test_domain_1"}),
	)
	if err != nil {
		return
	}

	// Display the Description
	fmt.Println(fun.Get().Description())

	// Open the config.yaml of the function
	config, err := afero.ReadFile(fs, "/functions/test_func.yaml")
	if err != nil {
		return
	}

	// Print config.yaml
	fmt.Println(string(config))

}
Output:

a basic function
id: QmaEBKzOyrYL1D6gtqD86Nyr2hvXAxWHcMCu9ffxLaByMc
description: a basic function
tags:
    - tag1
    - tag2
trigger:
    type: https
    method: GET
    paths:
        - /
execution:
    timeout: 15s
    memory: 64MB
    call: ping
source: .
domains:
    - test_domain_1

func Open

func Open(seer *seer.Seer, name, application string) (Function, error)

type Getter

type Getter interface {
	basic.ResourceGetter[*structureSpec.Function]
	Type() string
	Method() string
	Paths() []string
	Local() bool
	Command() string
	Channel() string
	Source() string
	Domains() []string
	Timeout() string
	Memory() string
	Call() string
	Protocol() string
}

func Yaml

func Yaml(name, application string, yamlData []byte) (Getter, error)

Jump to

Keyboard shortcuts

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