Documentation
¶
Overview ¶
ruby.go — locate a usable host Ruby.
Drift's promise for Ruby is "write Ruby, have Ruby, go" — no Docker, no version pin. The only wrinkle is macOS: Apple ships an ancient system Ruby (2.6) whose bundler can't even install modern git gems. So instead of blindly trusting `ruby` on PATH, we find a Ruby >= 3.0 — checking PATH first, then Homebrew, then rbenv — and use that one for both `bundle install` (deploy) and running functions locally (`drift atomic run`).
sdk.go — the one piece of SDK knowledge the CLI can't avoid.
The CLI does NOT pin an SDK version anywhere. But the Go builder must name the SDK's ROOT module path when it runs `go get …@latest`, because the repo's early history contained a nested `github.com/ondrift/sdk/go` module. Its pseudo-versions still live on the Go proxy (immutable), so a bare `go mod tidy` on a function that imports `…/sdk/go` resolves one of those STALE commits instead of the current root module. Naming the root module disambiguates and pulls the latest real tag.
This is a path, not a version — `@latest` means new SDK tags are picked up automatically with no CLI change... EXCEPT across a Go major version. Go's own semantic import versioning bakes the major into the module path itself (v2+ is "github.com/ondrift/sdk/v2", not a bare version bump), so a future SDK major bump requires a matching CLI change here AND in the generated-wrapper templates (cmd/atomic/cmd/deploy/default/ server_{post,get}_native.txt, which hardcode the same import path) — not something `@latest` alone can carry across for Go specifically.
sdk_manifest.go — pre-deploy guard for a common footgun: a function that uses the Drift SDK but ships no dependency manifest to declare it. Without the manifest the build installs nothing, the artifact has no SDK, and the function fails at runtime with a cryptic "No module named 'drift'" (or the per-language equivalent). This turns that into a clear message at deploy time. Go and Rust auto-provision the SDK at build, so they aren't checked.
Index ¶
Constants ¶
const DriftGoModule = "github.com/ondrift/sdk/v2"
DriftGoModule is the root module path of the published Drift SDK.
Variables ¶
This section is empty.
Functions ¶
func DetectLanguage ¶
DetectLanguage scans dir for the file containing the @atomic annotation and returns the language ("native", "python", "node", "ruby", "php", "rust") and the filename (not full path).
func FuncNameForLanguage ¶
FuncNameForLanguage returns the expected handler function name given the @atomic method+name and the target language. Route patterns with path parameters (e.g., "users/:id") are normalized first: colons are stripped and slashes become hyphens, so "users/:id" → "users-id" before casing.
func LanguageFromExt ¶ added in v1.8.0
LanguageFromExt reports the Drift language key for a file extension (e.g. ".py" → "python"), or "" if the extension isn't a supported source file. Exported so element discovery can pick out source files per language.
func VerifySDKManifest ¶
VerifySDKManifest returns an actionable error when a function's source uses the Drift SDK but the language's dependency manifest is missing. Languages that auto-provision the SDK (Go, Rust) return nil.
Types ¶
type AtomicMeta ¶
type AtomicMeta struct {
// Trigger is "http", "queue", or "cron".
Trigger string
// Method carries the trigger-specific value:
// http → HTTP verb ("get", "post", "put", "delete", "patch")
// queue → queue name
// cron → cron expression (e.g. "0 * * * *")
Method string
// Path is the route path, populated only for http triggers.
Path string
// Auth is the platform-level auth gate ("none", "apikey", or "").
Auth string
// Stream is the response shape ("", "sse", or "ws").
Stream string
// Secrets is the allowlist of backbone secrets the runner injects
// as DRIFT_SECRET_<NAME> env vars at invocation time.
Secrets []string
// SentinelName is the name of the source-level callable (function
// or method name) the annotation sits directly above. Populated by
// ParseAllAtomicMetadata; left empty by ParseAtomicMetadata.
SentinelName string
// Language is the source language detected for the file the
// annotation came from ("go", "python", "node", "ruby", "php",
// "rust"). Populated by ParseAllAtomicMetadata.
Language string
}
AtomicMeta is everything a single `@atomic` annotation declares.
One annotation per callable sentinel. The trigger is exactly one of `http`, `queue`, or `cron`; auth, stream, and secrets are optional inline keywords on the same line.
@atomic http=post:foo/bar auth=none secrets=KEY1,KEY2 @atomic queue=validate auth=none secrets=KEY1 @atomic cron="0 * * * *" auth=none
func ParseAllAtomicMetadata ¶
func ParseAllAtomicMetadata(filename string) ([]AtomicMeta, error)
ParseAllAtomicMetadata reads filename and returns one AtomicMeta per decorated callable in the file. Returns an empty slice if the file has no decorated callables. Returns an error if any callable has more than one `@atomic` line stacked above it.
func ParseAllAtomicMetadataFromDir ¶
func ParseAllAtomicMetadataFromDir(dir string) ([]AtomicMeta, error)
ParseAllAtomicMetadataFromDir walks every source file in dir, runs ParseAllAtomicMetadata on each, and returns the concatenated list.
func ParseAtomicMetadata ¶
func ParseAtomicMetadata(filename string) (AtomicMeta, error)
ParseAtomicMetadata reads filename, finds the first `@atomic` line, and parses it into an AtomicMeta. Returns an error if the file doesn't contain a valid annotation.
func ParseAtomicMetadataFromDir ¶
func ParseAtomicMetadataFromDir(dir string) (AtomicMeta, error)
ParseAtomicMetadataFromDir scans every file in dir for an `@atomic` annotation and returns the first one found.
type RubyToolchain ¶
type RubyToolchain struct {
Ruby string // absolute path to the ruby binary
Bundle string // absolute path to the matching bundle binary
BinDir string // directory holding both (prepend to PATH for child procs)
Version string // e.g. "4.0.2"
}
RubyToolchain is a discovered host Ruby >= 3.0 and its matching bundler.
func FindRuby ¶
func FindRuby() (RubyToolchain, error)
FindRuby returns the best host Ruby >= 3.0. It prefers a Ruby already on PATH, then well-known Homebrew prefixes, then rbenv. Apple's system Ruby (2.6) is skipped by the version gate. No version is ever pinned.