Documentation
¶
Overview ¶
Package run exposes the complete GoModel gateway lifecycle as an importable entry point. External modules build custom gateway binaries by registering extensions (see the ext package) and calling Run:
func main() {
ext.RegisterRewriter(myRewriter{})
err := run.Run(context.Background(), run.Options{ProductName: "my-gateway"})
if code := run.ExitCode(err); code != 0 {
os.Exit(code)
}
}
Index ¶
Constants ¶
const ( // AppCore is the open-source gateway; its checks read core.txt. AppCore = version.AppCore // AppPro is GoModel Pro; its checks read pro.txt. AppPro = version.AppPro )
Distribution names for Options.AppName. They decide which release manifest the daily update check reads and what the X-GoModel-App header carries.
Variables ¶
This section is empty.
Functions ¶
func ExitCode ¶
ExitCode maps a Run error to a process exit code: nil is 0, CLI usage errors are 2, everything else is 1.
func Run ¶
Run executes the full gateway lifecycle: CLI parsing, --version, --health/--ready probe and --reload signalling modes, dotenv loading, logging setup, config loading, provider registration, application construction (including registered extensions), signal handling, and start with graceful shutdown.
Cancelling ctx triggers the same graceful shutdown as SIGINT/SIGTERM. A reload signal (SIGHUP, what `gomodel --reload` sends) instead re-reads the environment file and the configuration and replaces the running application with one built from them, without giving up the listening socket.
Types ¶
type Options ¶
type Options struct {
// ProductName names the binary in CLI usage output, the startup log line,
// --version output, and the default OpenTelemetry service.name. Default:
// "gomodel".
ProductName string
// AppName names the distribution in the X-GoModel-App header and decides
// which release manifest the update check reads ("core.txt" or
// "pro.txt"). Custom distributions set AppPro or their own name.
//
// Empty leaves version.App as the build stamped it, so a distribution can
// choose either mechanism: this field, or -ldflags on version.App the way
// the Pro image already stamps version.Version. Setting it here wins.
// Default: version.AppCore ("GoModel").
AppName string
// Extensions is the extension registry snapshotted at server
// construction. Default: ext.Default.
Extensions *ext.Registry
// Args are the CLI arguments (without the program name). Default: os.Args[1:].
Args []string
// Stdout and Stderr default to os.Stdout and os.Stderr.
Stdout io.Writer
Stderr io.Writer
// ConfigureSwaggerDocs receives the configured server base path so the
// caller's generated swagger docs package can be aligned with it. The
// gomodel binary passes its build-tagged implementation. Default: no-op.
ConfigureSwaggerDocs func(basePath string)
// Setup, when set, runs once the process is committed to starting the
// gateway — after CLI parsing, --version/--health/--ready
// short-circuits, dotenv loading, and logging configuration, but before
// config loading. Register extensions here so operator tooling modes
// stay silent. A returned error aborts startup.
Setup func(ctx context.Context) error
// SetupConfig runs once after the initial configuration has been loaded and
// before the application is constructed. It lets custom distributions
// decode their opaque extensions: configuration and register corresponding
// extensions. Configuration registered here is startup-only; reloads reuse
// the resulting extension instances.
SetupConfig func(ctx context.Context, result *config.LoadResult) error
// ReloadConfig runs for every configuration generation after the first,
// once a reload has re-read the configuration and before the replacement
// application is built. It lets a distribution apply to the reloaded
// configuration the same policy SetupConfig applied at startup, such as
// disabling a setting or rejecting an endpoint. A returned error rejects
// the reload; the serving generation keeps running.
ReloadConfig func(ctx context.Context, result *config.LoadResult) error
}
Options configures a gateway run. The zero value runs the standard gomodel gateway on os.Args.