add function handling (basic)

This commit is contained in:
2025-11-30 15:28:30 +02:00
parent c1e5fc90ee
commit 6aae5f9fb0
10 changed files with 215 additions and 2 deletions

25
internal/worker/run.go Normal file
View File

@@ -0,0 +1,25 @@
package worker
import (
"bytes"
"fmt"
"os/exec"
)
func RunFunction(path string, fc *FuncConfig, input []byte) ([]byte, error) {
if fc.Runtime != "exec" {
return nil, fmt.Errorf("unsupported runtime: %s", fc.Runtime)
}
cmd := exec.Command(path)
cmd.Stdin = bytes.NewReader(input)
var out bytes.Buffer
cmd.Stdout = &out
cmd.Stderr = &out
if err := cmd.Run(); err != nil {
return nil, fmt.Errorf("failed: %w\noutput: %s", err, out.String())
}
return out.Bytes(), nil
}