functions_sdk_go

package module
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

README

Functions SDK for Go

Static Badge Static Badge

This small library is meant to be used inside a function and provides helpers to use the injected functions and read the input.

Install

Dependencies

Usage

When developing a function in Go (function in the sense of Functions-api), you can access the input like this:

package main

import (
	sdk "bitbucket.org/amotus/functions-sdk-go"
	"fmt"
	"os"
)

func main() {
	input, err := sdk.ReadInput(os.Stdin)
	if err != nil {
		_, _ = os.Stderr.Write([]byte("failed reading input: " + err.Error()))
		return
	}

	fmt.Println("Input: ")
	fmt.Println(input.Input)
	fmt.Println("Function ID: ")
	fmt.Println(input.Context.FunctionID)
	fmt.Println("Project ID: ")
	fmt.Println(input.Context.ProjectID)
	fmt.Println("Metadata: ")
	fmt.Println(input.Metadata)
}

To access the injected function to send a message, see https://bitbucket.org/amotus/functions-api/src/develop/test/wasirunner/go/sdk/produce/

Development

Build
just build
Test

Since the code uses wasm features for go, tests must be ran through wasmtime. Thus wasmtime must be installed. Then the test command below will take care of running those tests correctly:

just test

The injected functions are tested through this Functions-api sample

Releasing a new version

Please use the manual pipeline release-version that creates a new tag. The pipeline will ask for a version, follow the vMAJOR.MINOR.PATCH format, possibly with a suffix if needed.

The next PR on this repository will update the changelog, so that the top version of the changelog is un-released (in development). The manual changelog is just a simple list of features that were added or removed between each version.

Maintainers

Contributing

Readme convention

Repository convention

Language convention

Licence

Licensed under Apache License, Version 2.0 LICENSE.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get added in v0.0.5

func Get(token string) func(route string) (map[string]any, error)

Get returns a function that retrieves data from a specified route using the provided token.

func ProduceMessage

func ProduceMessage(topic string, msg string)

func ProduceMessageWithHeaders added in v0.0.6

func ProduceMessageWithHeaders(topic string, msg string, headers map[string]string)

Types

type Buffer

type Buffer uint64

A Buffer is a pointer into our (WASM) memory and a size, allowing us to safely pass data to the host (the functions service).

func NewBuffer

func NewBuffer[T any](ptr *T, size int) Buffer

func (Buffer) Bytes

func (b Buffer) Bytes() []byte

func (Buffer) Length

func (b Buffer) Length() uint32

func (Buffer) Pointer

func (b Buffer) Pointer() unsafe.Pointer

func (Buffer) String

func (b Buffer) String() string

func (Buffer) UnmarshalJSON

func (b Buffer) UnmarshalJSON(v any) error

type FunctionContext

type FunctionContext = struct {
	FunctionID string `json:"function_id"`
	ProjectID  int64  `json:"project_id"`
}

type FunctionInput

type FunctionInput = struct {
	Input    []byte            `json:"input"`
	Context  FunctionContext   `json:"context"`
	Metadata map[string][]byte `json:"metadata"`
}

func ReadInput

func ReadInput(r io.Reader) (FunctionInput, error)

type Response added in v0.0.5

type Response struct {
	Body map[string]any
	Err  string
}

Jump to

Keyboard shortcuts

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