orama/sdk/fn/fn.go
anonpenguin23 106c2df4d2 feat: implement wallet-based SSH authentication using Ed25519 keys
- Added documentation for wallet-based SSH authentication in WALLET_SSH_AUTH.md.
- Introduced SSH key derivation and management in rootwallet core and CLI.
- Created commands for generating, loading, and unloading SSH keys in the CLI.
- Updated Orama network to support SSH key authentication.
- Added migration steps for nodes to transition from password-based to key-based authentication.

feat: add serverless function management commands

- Implemented function command structure in CLI for managing serverless functions.
- Added commands for initializing, building, deploying, invoking, deleting, and listing functions.
- Created helper functions for handling function configuration and API requests.
- Integrated TinyGo for building functions to WASM.
- Added logging and version management for deployed functions.
2026-02-19 10:51:03 +02:00

67 lines
1.8 KiB
Go

// Package fn provides a tiny, TinyGo-compatible SDK for writing Orama serverless functions.
//
// A function is a Go program that reads JSON input from stdin and writes JSON output to stdout.
// This package handles the boilerplate so you only write your handler logic.
//
// Example:
//
// package main
//
// import "github.com/DeBrosOfficial/network/sdk/fn"
//
// func main() {
// fn.Run(func(input []byte) ([]byte, error) {
// var req struct{ Name string `json:"name"` }
// fn.ParseJSON(input, &req)
// if req.Name == "" { req.Name = "World" }
// return fn.JSON(map[string]string{"greeting": "Hello, " + req.Name + "!"})
// })
// }
package fn
import (
"encoding/json"
"fmt"
"io"
"os"
)
// HandlerFunc is the signature for a serverless function handler.
// It receives the raw JSON input bytes and returns raw JSON output bytes.
type HandlerFunc func(input []byte) (output []byte, err error)
// Run reads input from stdin, calls the handler, and writes the output to stdout.
// If the handler returns an error, it writes a JSON error response to stdout and exits with code 1.
func Run(handler HandlerFunc) {
input, err := io.ReadAll(os.Stdin)
if err != nil {
writeError(fmt.Sprintf("failed to read input: %v", err))
os.Exit(1)
}
output, err := handler(input)
if err != nil {
writeError(err.Error())
os.Exit(1)
}
if output != nil {
os.Stdout.Write(output)
}
}
// JSON marshals a value to JSON bytes. Convenience wrapper around json.Marshal.
func JSON(v interface{}) ([]byte, error) {
return json.Marshal(v)
}
// ParseJSON unmarshals JSON bytes into a value. Convenience wrapper around json.Unmarshal.
func ParseJSON(data []byte, v interface{}) error {
return json.Unmarshal(data, v)
}
func writeError(msg string) {
resp, _ := json.Marshal(map[string]string{"error": msg})
os.Stdout.Write(resp)
}