Go integration
hclapi embeds into an existing Go application as a library. It mounts native HTTP handlers alongside declarative routes and supports calling back into native Go functions from pipeline steps.
Embedding
hclapi.Engine implements the standard http.Handler interface. It mounts directly onto any http.ServeMux, middleware stack, or third-party router.
Basic setup
Registering steps
Register a Go function that an HCL go step can invoke.
Signature
ctx: Standard Gocontext.Contextcarrying request cancellation, timeouts, and tracing spans. Pass this directly to outbound HTTP requests, database queries, and cache calls.step: The step execution handle carrying evaluated inputs (step.Args), request metadata (step.Request), and outputs of prior steps (step.Steps).
Step data access
*hclapi.Step provides thread-safe access to execution data:
Working with arguments (step.Args)
step.Args uses generic methods for type coercion, handling HCL integers (int64), floating-point values, and dynamic lists:
Example: Outbound HTTP Call
1. In your Go application:
2. In your HCL manifest:
Error handling and custom status codes
- Standard Go errors: Returning a standard Go error (e.g.
errors.New("db failure")) automatically returns an HTTP 500 with problem typeurn:hclapi:error:pipeline-execution-failed. - Custom HTTP status codes: Return
step.Problem(status, detail)or ahclapi.Problemstruct to emit custom status codes (such as 401, 403, 404, or 429) directly to the client. - Panics: Any panic inside a
StepHandleris automatically recovered by the runtime, logged with the step's name and stack trace, and returned as an HTTP 500. The server process continues running uninterrupted.