Documentation
¶
Overview ¶
Package localrun is the machine-local registry of running gofastr apps. Every App writes one record when its listener binds and removes it when the server stops, so a tool on the same machine (the gofastr-runs example, an agent) can list what is running, where, and how to reach its MCP server, with no port scanning.
Records live in Dir, one owner-only JSON file per run, with the run's process start value in a sidecar file beside it. A run that dies without shutting down leaves its file behind; List drops a record whose process is gone, a pid now held by a newer process included. Registration is best-effort: a run that cannot write its record serves anyway.
Index ¶
Constants ¶
const ( // EnvDir overrides the registry directory. EnvDir = "GOFASTR_RUNS_DIR" // EnvRuns set to "off" (or 0/false/no) stops this process from // registering; "on" (or 1/true/yes) makes it register wherever it // binds. Unset, the App decides (see App.Start). Listing is // unaffected. EnvRuns = "GOFASTR_RUNS" // EnvOff is EnvRuns under its older name, from when the variable // could only turn registration off. EnvOff = EnvRuns )
Variables ¶
This section is empty.
Functions ¶
func Disabled ¶
func Disabled() bool
Disabled reports whether this process must not register: EnvOff says so, or it is a test binary, or a process a test binary started, with no EnvDir (tests that start an App must not litter the real registry; a test that exercises it sets EnvDir to a temp dir).
func Forced ¶ added in v0.96.0
func Forced() bool
Forced reports whether the environment asks this process to register regardless of where it binds: EnvRuns says "on" (or 1/true/yes). EnvDir only says where the registry is. Disabled still wins.
Types ¶
type Record ¶
type Record struct {
Version int `json:"version"`
// ID names the record file: "<pid>-<8 hex>".
ID string `json:"id"`
Name string `json:"name"`
PID int `json:"pid"`
// ProcStart is the OS's start value for PID (procalive.Identity),
// so List can tell the run from a later process that got its pid.
// Zero when the OS would not say; the pid alone decides then. It is
// kept in "<id>.start" beside the record, not in the JSON: readers
// built before it decode records strictly, and an unknown field
// would make them drop every record.
ProcStart uint64 `json:"-"`
// URL is the base URL a local client dials: http://127.0.0.1:<port>
// for a wildcard bind.
URL string `json:"url"`
// MCPPath is the path the app serves MCP over HTTP on ("/mcp"),
// empty when it serves none. Under `gofastr dev` it answers on
// loopback with no credential; elsewhere the app's own auth
// applies.
MCPPath string `json:"mcp_path,omitempty"`
// MCPCommand, when set, is an argv that speaks stdio MCP to this
// run (battery/service sets `<exe> service mcp --state-dir <dir>`).
// An agent should prefer it over MCPPath: it carries its own
// credential.
MCPCommand []string `json:"mcp_command,omitempty"`
// Service is the battery/service Config.ID when the run is a
// service daemon or its dev run.
Service string `json:"service,omitempty"`
Dev bool `json:"dev,omitempty"`
Dir string `json:"dir,omitempty"`
Exe string `json:"exe,omitempty"`
Started time.Time `json:"started"`
}
Record is one running app.