Documentation
¶
Overview ¶
Package hex is a Go application framework: an IoC container, service providers, event bus, and bootstrap orchestration in one opinionated module.
A typical program creates an *App, registers providers, calls Bootstrap to run their lifecycle hooks in order, does its work, and finally calls Shutdown to release resources in reverse order:
app := hex.New()
app.Register(&provider.Database{}, &provider.HTTP{})
if err := app.Bootstrap(ctx); err != nil { log.Fatal(err) }
defer app.Shutdown(ctx)
The subpackages (container, events, provider) are usable on their own, but App wires them together and satisfies provider.Application so providers can bind and resolve dependencies through it.
Index ¶
- type App
- func (a *App) Bind(name string, fn container.Factory)
- func (a *App) BootedAt() time.Time
- func (a *App) Bootstrap(ctx context.Context) error
- func (a *App) Container() *container.Container
- func (a *App) Emit(event string, data ...any) error
- func (a *App) Environment() env.Environment
- func (a *App) Events() *events.Bus
- func (a *App) Make(name string) (any, error)
- func (a *App) MustRegister(providers ...provider.Service)
- func (a *App) On(event string, fn events.Subscriber) func()
- func (a *App) Register(providers ...provider.Service) error
- func (a *App) Shutdown(ctx context.Context) error
- func (a *App) Singleton(name string, fn container.Factory)
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type App ¶
type App struct {
// contains filtered or unexported fields
}
App is the process-wide application kernel. It owns the IoC container, the provider registry, and the event bus, and exposes the surface providers interact with. Zero-value App is not usable; call New.
func New ¶
New returns a fresh App with an empty container, event bus, and provider registry. Options override the defaults.
func (*App) BootedAt ¶
BootedAt returns the time Bootstrap completed. Returns the zero Time if Bootstrap has not run.
func (*App) Bootstrap ¶
Bootstrap runs the two-phase provider lifecycle: every provider's Register runs in insertion order, then every provider's Boot runs in the same order. Bootstrap is idempotent — a second call returns nil without re-invoking hooks — so consumers can call it from a defensive main safely.
func (*App) Container ¶
Container returns the underlying IoC container. Prefer Bind, Singleton, and Make on App itself; use Container only when you need methods the App does not delegate (such as List or Count).
func (*App) Environment ¶
func (a *App) Environment() env.Environment
Environment returns the runtime environment. Set via WithEnvironment or auto-detected by env.Detect during New.
func (*App) Events ¶
Events returns the underlying event bus. Prefer On and Emit on App itself; use Events for less common operations like EmitAsync.
func (*App) MustRegister ¶
MustRegister is like Register but panics on error. Convenient in main and setup code where a Register failure means the program cannot proceed.
func (*App) On ¶
func (a *App) On(event string, fn events.Subscriber) func()
On delegates to the underlying event bus.
func (*App) Register ¶
Register appends providers to the registry. They will be registered and booted in the order supplied across all Register calls. Register may only be called before Bootstrap; calling it after returns an error.
type Option ¶
type Option func(*App)
Option configures a new App. Pass options to New.
func WithContainer ¶
WithContainer replaces the default container. Useful for tests that need to pre-seed bindings.
func WithEnvironment ¶
func WithEnvironment(e env.Environment) Option
WithEnvironment sets the runtime environment. When unset, New auto-detects via env.Detect: HEX_ENV/APP_ENV env vars, then testing.Testing() -> Test, then Development.
func WithEventBus ¶
WithEventBus replaces the default event bus. Useful for tests or for consumers that need to share a bus across multiple Apps.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package ai is a thin, opinionated wrapper around charm.land/fantasy.
|
Package ai is a thin, opinionated wrapper around charm.land/fantasy. |
|
anthropic
Package anthropic constructs a fantasy.Provider for Anthropic's language models from hex configuration.
|
Package anthropic constructs a fantasy.Provider for Anthropic's language models from hex configuration. |
|
lua
Package lua exposes hex/ai's default agent to Lua scripts via a gopher-lua module named "agent".
|
Package lua exposes hex/ai's default agent to Lua scripts via a gopher-lua module named "agent". |
|
lua/provider
Package provider is the service provider that installs the hex/ai 'agent' Lua module into the shared hex/lua environment.
|
Package provider is the service provider that installs the hex/ai 'agent' Lua module into the shared hex/lua environment. |
|
openai
Package openai constructs a fantasy.Provider for OpenAI's language models from hex configuration.
|
Package openai constructs a fantasy.Provider for OpenAI's language models from hex configuration. |
|
provider
Package provider is the default hex/ai service provider.
|
Package provider is the default hex/ai service provider. |
|
Package bdd wraps github.com/go-bdd/gobdd so hex applications can write behavior-driven tests with standard Gherkin `.feature` files.
|
Package bdd wraps github.com/go-bdd/gobdd so hex applications can write behavior-driven tests with standard Gherkin `.feature` files. |
|
Package build exposes compile-time build metadata: version, commit, branch, build time, and platform information.
|
Package build exposes compile-time build metadata: version, commit, branch, build time, and platform information. |
|
Package cache defines a driver-agnostic key-value cache with TTL semantics.
|
Package cache defines a driver-agnostic key-value cache with TTL semantics. |
|
lua
Package lua exposes hex/cache to Lua scripts as the "cache" module.
|
Package lua exposes hex/cache to Lua scripts as the "cache" module. |
|
memory
Package memory is an in-process cache backend.
|
Package memory is an in-process cache backend. |
|
provider
Package provider is the default hex/cache service provider.
|
Package provider is the default hex/cache service provider. |
|
Package cli provides Cobra scaffolding for hex applications.
|
Package cli provides Cobra scaffolding for hex applications. |
|
Package clock provides an injectable time source for testable code.
|
Package clock provides an injectable time source for testable code. |
|
cmd
|
|
|
hex
command
Command hex is the scaffolding CLI for hex applications.
|
Command hex is the scaffolding CLI for hex applications. |
|
hex/app
Package app wires the hex CLI's own service providers into the hex kernel.
|
Package app wires the hex CLI's own service providers into the hex kernel. |
|
hex/app/build
Package build re-exports hex/build metadata under the hex CLI's own namespace, the same way any scaffolded hex app does.
|
Package build re-exports hex/build metadata under the hex CLI's own namespace, the same way any scaffolded hex app does. |
|
hex/app/command
Package command holds the hex CLI's own cobra command tree — built the same way `hex init` wires one for a scaffolded app.
|
Package command holds the hex CLI's own cobra command tree — built the same way `hex init` wires one for a scaffolded app. |
|
hex/app/command/genman
Package genman implements the hidden `hex gen-man` command.
|
Package genman implements the hidden `hex gen-man` command. |
|
hex/app/command/init
Package init implements `hex init`.
|
Package init implements `hex init`. |
|
hex/app/command/make
Package make holds the `hex make` command group — one subpackage per generator (provider, domain, migration, adapter, controller, command).
|
Package make holds the `hex make` command group — one subpackage per generator (provider, domain, migration, adapter, controller, command). |
|
hex/app/command/make/adapter
Package adapter implements `hex make adapter`.
|
Package adapter implements `hex make adapter`. |
|
hex/app/command/make/command
Package command implements `hex make command`.
|
Package command implements `hex make command`. |
|
hex/app/command/make/controller
Package controller implements `hex make controller`.
|
Package controller implements `hex make controller`. |
|
hex/app/command/make/domain
Package domain implements `hex make domain`.
|
Package domain implements `hex make domain`. |
|
hex/app/command/make/migration
Package migration implements `hex make migration`.
|
Package migration implements `hex make migration`. |
|
hex/app/command/make/provider
Package provider implements `hex make provider`.
|
Package provider implements `hex make provider`. |
|
hex/app/command/publish
Package publish implements `hex publish`.
|
Package publish implements `hex publish`. |
|
hex/app/provider
Package provider holds the hex CLI's own service providers — the same role app/provider plays in any scaffolded hex app.
|
Package provider holds the hex CLI's own service providers — the same role app/provider plays in any scaffolded hex app. |
|
hex/domain/generator
Package generator is the Generator domain: it describes hex's own make generators as data (Blueprint) and records what applying one does (Action).
|
Package generator is the Generator domain: it describes hex's own make generators as data (Blueprint) and records what applying one does (Action). |
|
hex/infrastructure/embedfs
Package embedfs is the built-in adapter for domain/generator: it serves Blueprint definitions and template bytes from the CLI's own compiled-in templates/mantemplates directories.
|
Package embedfs is the built-in adapter for domain/generator: it serves Blueprint definitions and template bytes from the CLI's own compiled-in templates/mantemplates directories. |
|
Package config loads application configuration from embedded TOML files, user override files, and environment variables.
|
Package config loads application configuration from embedded TOML files, user override files, and environment variables. |
|
lua
Package lua exposes hex/config to Lua scripts as the "config" module.
|
Package lua exposes hex/config to Lua scripts as the "config" module. |
|
provider
Package provider is the default hex/config service provider.
|
Package provider is the default hex/config service provider. |
|
Package container provides a type-safe IoC dependency injection container.
|
Package container provides a type-safe IoC dependency injection container. |
|
Package cron schedules recurring jobs using cron expressions.
|
Package cron schedules recurring jobs using cron expressions. |
|
provider
Package provider is the default hex/cron service provider.
|
Package provider is the default hex/cron service provider. |
|
Package db provides driver-agnostic helpers for opening *sql.DB connections and tuning them for hex applications.
|
Package db provides driver-agnostic helpers for opening *sql.DB connections and tuning them for hex applications. |
|
lua
Package lua exposes hex/db to Lua scripts via a gopher-lua module named "db".
|
Package lua exposes hex/db to Lua scripts via a gopher-lua module named "db". |
|
postgres
Package postgres runs golang-migrate migrations against a Postgres database.
|
Package postgres runs golang-migrate migrations against a Postgres database. |
|
provider
Package provider is the default hex/db service provider.
|
Package provider is the default hex/db service provider. |
|
sqlite
Package sqlite runs golang-migrate migrations against a SQLite database.
|
Package sqlite runs golang-migrate migrations against a SQLite database. |
|
Package disk defines a driver-agnostic filesystem abstraction inspired by Laravel's Storage facade.
|
Package disk defines a driver-agnostic filesystem abstraction inspired by Laravel's Storage facade. |
|
local
Package local implements the disk.Disk interface against the host filesystem.
|
Package local implements the disk.Disk interface against the host filesystem. |
|
Package env names the runtime environment a hex application is running in and provides detection helpers.
|
Package env names the runtime environment a hex application is running in and provides detection helpers. |
|
lua
Package lua exposes hex/env to Lua scripts as the "env" module.
|
Package lua exposes hex/env to Lua scripts as the "env" module. |
|
Package errors adds typed error semantics on top of the stdlib errors package: a stable machine-readable Code, an optional HTTP status hint, and Wrap/Is/As support.
|
Package errors adds typed error semantics on top of the stdlib errors package: a stable machine-readable Code, an optional HTTP status hint, and Wrap/Is/As support. |
|
Package events provides a lightweight in-process publish/subscribe bus.
|
Package events provides a lightweight in-process publish/subscribe bus. |
|
lua
Package lua exposes hex/events to Lua scripts as the "events" module.
|
Package lua exposes hex/events to Lua scripts as the "events" module. |
|
examples
|
|
|
ai-lua
command
Command ai-lua-demo boots a minimal hex application with the AI + Lua + AI/Lua service providers wired, then executes a Lua script from stdin (or the argument given).
|
Command ai-lua-demo boots a minimal hex application with the AI + Lua + AI/Lua service providers wired, then executes a Lua script from stdin (or the argument given). |
|
Package featureflag is a thin wrapper around github.com/thomaspoignant/go-feature-flag (GOFF) that gives hex applications feature-flagging with rule-based targeting, percentage rollouts, and typed variations.
|
Package featureflag is a thin wrapper around github.com/thomaspoignant/go-feature-flag (GOFF) that gives hex applications feature-flagging with rule-based targeting, percentage rollouts, and typed variations. |
|
provider
Package provider is the default hex/featureflag service provider.
|
Package provider is the default hex/featureflag service provider. |
|
Package hash provides password hashing (argon2id) and HMAC signature helpers.
|
Package hash provides password hashing (argon2id) and HMAC signature helpers. |
|
Package hextest bootstraps a hex.App for tests: env pinned to Test, providers registered, Bootstrap run, Shutdown auto-scheduled via t.Cleanup.
|
Package hextest bootstraps a hex.App for tests: env pinned to Test, providers registered, Bootstrap run, Shutdown auto-scheduled via t.Cleanup. |
|
Package httpx is an opinionated outbound HTTP client for hex apps.
|
Package httpx is an opinionated outbound HTTP client for hex apps. |
|
Package i18n is a thin wrapper around github.com/leonelquinteros/gotext that gives hex applications GNU gettext-compatible internationalisation with PO file support.
|
Package i18n is a thin wrapper around github.com/leonelquinteros/gotext that gives hex applications GNU gettext-compatible internationalisation with PO file support. |
|
provider
Package provider is the default hex/i18n service provider.
|
Package provider is the default hex/i18n service provider. |
|
Package id generates identifiers for hex applications.
|
Package id generates identifiers for hex applications. |
|
Package log is a slog-first logger backed by charmbracelet/log's slog.Handler implementation.
|
Package log is a slog-first logger backed by charmbracelet/log's slog.Handler implementation. |
|
lua
Package lua exposes hex/log to Lua scripts as the "log" module.
|
Package lua exposes hex/log to Lua scripts as the "log" module. |
|
provider
Package provider is the default hex/log service provider.
|
Package provider is the default hex/log service provider. |
|
Package lua embeds a Lua runtime for hex applications using github.com/yuin/gopher-lua.
|
Package lua embeds a Lua runtime for hex applications using github.com/yuin/gopher-lua. |
|
fennel
Package fennel makes .fnl (Fennel) source files runnable through gopher-lua by embedding the Fennel compiler (a self-contained Lua source file distributed by the Fennel project).
|
Package fennel makes .fnl (Fennel) source files runnable through gopher-lua by embedding the Fennel compiler (a self-contained Lua source file distributed by the Fennel project). |
|
plugin
Package plugin discovers repo-local Cobra commands written in Lua, Teal, or Fennel and merges them into an existing command tree.
|
Package plugin discovers repo-local Cobra commands written in Lua, Teal, or Fennel and merges them into an existing command tree. |
|
provider
Package provider is the default hex/lua service provider.
|
Package provider is the default hex/lua service provider. |
|
repl
Package repl provides an interactive Read-Eval-Print Loop for Teal and Lua sources, wired to a caller-provided *lua.Environment.
|
Package repl provides an interactive Read-Eval-Print Loop for Teal and Lua sources, wired to a caller-provided *lua.Environment. |
|
teal
Package teal makes .tl (Teal) source files runnable through gopher-lua by embedding the Teal compiler + Lua 5.2 compatibility shims.
|
Package teal makes .tl (Teal) source files runnable through gopher-lua by embedding the Teal compiler + Lua 5.2 compatibility shims. |
|
Package policy is a thin wrapper around github.com/casbin/casbin/v2 that gives hex applications a portable authorization primitive.
|
Package policy is a thin wrapper around github.com/casbin/casbin/v2 that gives hex applications a portable authorization primitive. |
|
provider
Package provider is the default hex/policy service provider.
|
Package provider is the default hex/policy service provider. |
|
Package pool is a thin wrapper around github.com/alitto/pond/v2 that gives hex applications a worker pool primitive for bounded in-process concurrency.
|
Package pool is a thin wrapper around github.com/alitto/pond/v2 that gives hex applications a worker pool primitive for bounded in-process concurrency. |
|
Package provider defines the service provider contract and the ordered registry that drives application bootstrap.
|
Package provider defines the service provider contract and the ordered registry that drives application bootstrap. |
|
Package queue defines a driver-agnostic message queue for cross-process, asynchronous delivery.
|
Package queue defines a driver-agnostic message queue for cross-process, asynchronous delivery. |
|
jobs
Package jobs is a typed job layer on top of hex/queue.
|
Package jobs is a typed job layer on top of hex/queue. |
|
lua
Package lua exposes hex/queue to Lua scripts as the "queue" module.
|
Package lua exposes hex/queue to Lua scripts as the "queue" module. |
|
memory
Package memory is an in-process queue backend.
|
Package memory is an in-process queue backend. |
|
provider
Package provider is the default hex/queue service provider.
|
Package provider is the default hex/queue service provider. |
|
sqlite
Package sqlite is a durable, single-node queue backend built on database/sql + SQLite.
|
Package sqlite is a durable, single-node queue backend built on database/sql + SQLite. |
|
Package ratelimit is a thin wrapper around golang.org/x/time/rate.
|
Package ratelimit is a thin wrapper around golang.org/x/time/rate. |
|
Package retry provides generic exponential-backoff retry primitives.
|
Package retry provides generic exponential-backoff retry primitives. |
|
Package telemetry sets up OpenTelemetry tracing and metrics for hex applications.
|
Package telemetry sets up OpenTelemetry tracing and metrics for hex applications. |
|
provider
Package provider is the default hex/telemetry service provider.
|
Package provider is the default hex/telemetry service provider. |
|
tui
|
|
|
components/progress
Package progress renders a Bubble Tea progress bar model — a composable spinner + percentage + label component reused across hex CLIs and TUIs.
|
Package progress renders a Bubble Tea progress bar model — a composable spinner + percentage + label component reused across hex CLIs and TUIs. |
|
components/repl
Package repl is a Bubble Tea REPL component: a prompt line with arrow-key editing, up/down command history, styled output, and a caller-supplied evaluator callback.
|
Package repl is a Bubble Tea REPL component: a prompt line with arrow-key editing, up/down command history, styled output, and a caller-supplied evaluator callback. |
|
components/spinner
Package spinner is a thin wrapper around bubbles/spinner that ships hex's default spinner style.
|
Package spinner is a thin wrapper around bubbles/spinner that ships hex's default spinner style. |
|
console
Package console provides a high-level output and interaction API for CLI commands.
|
Package console provides a high-level output and interaction API for CLI commands. |
|
markup
Package markup provides inline XML-style tags for styled terminal output.
|
Package markup provides inline XML-style tags for styled terminal output. |
|
renderer
Package renderer writes structured Go values to a writer in the caller's chosen format (table, plain, json, yaml, toml, csv).
|
Package renderer writes structured Go values to a writer in the caller's chosen format (table, plain, json, yaml, toml, csv). |
|
Package validate is a hex-namespaced entrypoint for github.com/Oudwins/zog, a Zod-style schema parser + validator.
|
Package validate is a hex-namespaced entrypoint for github.com/Oudwins/zog, a Zod-style schema parser + validator. |
|
Package view renders Go html/template files for hex web apps.
|
Package view renders Go html/template files for hex web apps. |
|
jade
Package jade wires github.com/Joker/jade into hex/view as a template Preprocessor.
|
Package jade wires github.com/Joker/jade into hex/view as a template Preprocessor. |
|
md
Package md wires github.com/yuin/goldmark into hex/view as a Markdown → HTML Preprocessor.
|
Package md wires github.com/yuin/goldmark into hex/view as a Markdown → HTML Preprocessor. |
|
provider
Package provider installs a hex/view Engine as the *web.Server's echo.Renderer and binds the engine under "view" in the container.
|
Package provider installs a hex/view Engine as the *web.Server's echo.Renderer and binds the engine under "view" in the container. |
|
Package web is a hex-opinionated wrapper around labstack/echo/v4.
|
Package web is a hex-opinionated wrapper around labstack/echo/v4. |
|
provider
Package provider is the default hex/web service provider.
|
Package provider is the default hex/web service provider. |
|
Package webtest is a supertest-flavoured HTTP client + a react-testing-library-flavoured DOM query surface for testing hex web apps end-to-end.
|
Package webtest is a supertest-flavoured HTTP client + a react-testing-library-flavoured DOM query surface for testing hex web apps end-to-end. |
|
bdd
Package bdd wires the hex/webtest client into a hex/bdd suite as a set of standard Gherkin step definitions, giving apps a react-testing-library-flavoured browser-test vocabulary in .feature files:
|
Package bdd wires the hex/webtest client into a hex/bdd suite as a set of standard Gherkin step definitions, giving apps a react-testing-library-flavoured browser-test vocabulary in .feature files: |