Core Concepts
How go-faas stores scripts, injects input, wraps languages, and returns results.
Script Paths and Versions
- Each script is identified by a logical
pathstring (for examplemath/add). - Paths must not contain
... - Storage keys use MD5 of the path, not the raw path string.
- Each upload creates a Unix-timestamp version and updates
lateston the meta hash. POST /run/*pathwithoutversionruns the latest revision;?version=selects a specific timestamp.
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:
- Response headers become
text/event-stream. - Intermediate stdout lines are emitted as
event: log(previous line pattern — final line held as result). - Completion sends
resultorerror, then the connection is hijacked closed.
Timeouts use TIMEOUT_SCRIPT plus a fixed Redis timeout buffer for request context.