Documentation

Core Concepts

How go-faas stores scripts, injects input, wraps languages, and returns results.

Script Paths and Versions

Run vs Run-Now

Mode Endpoint Persistence Typical use
Stored run POST /run/*path Code loaded from Redis Deployed functions
Immediate POST /run-now No Redis write Trials, one-shots

Both modes share the same sandbox execution path after code is resolved.

Event Input Model

Request body field input is a JSON string. Handlers pass it to the wrapper as part of stdin payload:

{"code": "...", "input": "{"a": 1}"}

Wrappers parse input into an object and expose:

Global Meaning
event Parsed JSON object from input
input Same object (alias)

Scripts typically return a value; wrappers serialize the return as JSON on stdout.

Language Wrappers

Language Runtime Wrapper Notes
Python python3 internal/resource/wrapper.py User code wrapped in __user_main__ so top-level return works; -u for unbuffered stdout
JavaScript node internal/resource/wrapper.js event / input globals
TypeScript tsx internal/resource/wrapper.ts Linux bwrap also binds project node_modules via NODE_PATH

Unsupported languages are rejected at upload / run-now with HTTP 400.

Body Size Limit

CODE_MAX_SIZE (default 256KB) is applied via http.MaxBytesReader when binding run bodies.

Typed JSON Responses

Non-stream responses detect the last valid JSON line of stdout:

type When
string JSON string
number JSON number
json object / array
text non-JSON leftover

Noisy Node warnings are filtered in cleanOutput before type detection.

SSE Streaming

When stream: true:

  1. Response headers become text/event-stream.
  2. Intermediate stdout lines are emitted as event: log (previous line pattern — final line held as result).
  3. Completion sends result or error, then the connection is hijacked closed.

Timeouts use TIMEOUT_SCRIPT plus a fixed Redis timeout buffer for request context.

中文