Documentation
¶
Overview ¶
Package engine composes Yacht for a program to run — this repository's own cmd/yacht, or an application wrapping the engine with its own identity, chrome, notifications and orchestrator.
The engine's packages are internal, which is what keeps them free to change. This package is the one public surface: the four seams, as aliases of the internal types so a wrapping application can name and implement them, and the composition that cmd/yacht used to hold, so a wrapper runs the same engine the same way with overrides rather than a copy of main.
A wrapping application does:
cfg, _ := engine.LoadConfig()
engine.Run(ctx, cfg, engine.Overrides{
Slots: myChrome{}, // brand, header tools, banner, extra nav
Identity: myOrganisations, // who a request acts as
Extra: engine.ExtraRoutes{Owner: mountBilling},
})
Everything the engine does — apps, deploys, builds, domains, certificates, storage, teams — is unchanged underneath.
Index ¶
- Constants
- Variables
- func NewLogger(debug bool) *slog.Logger
- func Run(ctx context.Context, cfg Config, ov Overrides) error
- func ServeHTTP(ctx context.Context, addr string, handler http.Handler, shutdown time.Duration, ...) error
- type Accounts
- type Apps
- type Config
- type Crumb
- type DefaultSlots
- type Engine
- type ExtraRoutes
- type IdentityProvider
- type Keeper
- type Mailer
- type Message
- type NavGroup
- type NavItem
- type Orchestrator
- type Overrides
- type Owner
- type Role
- type Server
- type SlotProvider
- type SlotProviderFunc
- type Slots
Constants ¶
const ( RoleOwner = account.RoleOwner RoleAdmin = account.RoleAdmin RoleMember = account.RoleMember // SessionCookie is the cookie the engine's sessions live in. SessionCookie = web.SessionCookie // DefaultBrandName is the engine's own name, where its chrome puts it — // what a wrapper replaces. DefaultBrandName = web.DefaultBrandName )
Variables ¶
var ( // LoadConfig reads the engine's configuration from the environment. LoadConfig = config.Load // Layout draws a page inside the engine's chrome. Layout = web.Layout // OwnerFromContext reads the Owner identity middleware resolved. OwnerFromContext = identity.FromContext // MustOwnerFromContext is OwnerFromContext for a handler that is certainly // behind the middleware. MustOwnerFromContext = identity.MustFromContext // NewSingleOwner and NewStaticToken are the engine's own providers, for a // wrapper that wants one of them in some deployments. NewSingleOwner = identity.NewSingleOwner NewStaticToken = identity.NewStaticToken )
Functions ¶
Types ¶
type Accounts ¶
Accounts is the engine's teams, people, invitations and sessions. A wrapper's organisations build on it rather than beside it.
type Crumb ¶
The seams, by their engine names. Aliases rather than copies: a value a wrapper builds against these is the same type the engine consumes.
type DefaultSlots ¶
type DefaultSlots = web.DefaultSlots
DefaultSlots is the engine's own chrome, to start from and adjust.
type Engine ¶
type Engine struct {
Config Config
Log *slog.Logger
Pool *pgxpool.Pool
Orchestrator Orchestrator
// Accounts is nil when accounts are off (no YACHT_BASE_URL).
Accounts *Accounts
Mailer Mailer
Identity IdentityProvider
// Keeper is non-nil only with YACHT_SECRET_KEY set; Keeper.Configured
// reports which, and is safe on nil.
Keeper *Keeper
Apps *Apps
Server *Server
// contains filtered or unexported fields
}
Engine is a composed, not yet running, Yacht.
func New ¶
New composes the engine: migrates and connects the database, connects the cluster, and builds every service and the dashboard. Nothing runs yet; Start or Serve does that.
func (*Engine) Close ¶
func (e *Engine) Close()
Close releases the database pool. Run does this itself.
func (*Engine) Serve ¶
Serve starts the background work and serves the dashboard on the configured address until ctx ends, then shuts down within the configured timeout.
type ExtraRoutes ¶
type ExtraRoutes = web.ExtraRoutes
ExtraRoutes are routes a wrapper mounts inside the engine's role gates.
type IdentityProvider ¶
IdentityProvider resolves a request to an Owner — seam 2.
type Message ¶
The seams, by their engine names. Aliases rather than copies: a value a wrapper builds against these is the same type the engine consumes.
type NavGroup ¶
The seams, by their engine names. Aliases rather than copies: a value a wrapper builds against these is the same type the engine consumes.
type NavItem ¶
The seams, by their engine names. Aliases rather than copies: a value a wrapper builds against these is the same type the engine consumes.
type Orchestrator ¶
type Orchestrator = orchestrator.Orchestrator
Orchestrator runs workloads — seam 1.
type Overrides ¶
type Overrides struct {
// Version is what the dashboard reports. cmd/yacht sets it at build time.
Version string
// Logger, or the engine's own text logger at the configured level.
Logger *slog.Logger
// Slots is the chrome: brand, navigation, header tools, banner.
Slots SlotProvider
// Identity resolves who a request acts as. Given the engine so it can
// build on Accounts, which exist by the time it is called.
Identity func(e *Engine) (IdentityProvider, error)
// Mailer delivers sign-in links and invitations.
Mailer Mailer
// Orchestrator runs workloads; nil connects to the configured cluster.
Orchestrator Orchestrator
// Extra is routes mounted inside the engine's role gates.
Extra ExtraRoutes
// AfterMigrate runs once the engine's schema is current, for a wrapper's
// own migrations. They share the database; a wrapper keeps its own goose
// version table so the two histories never collide.
AfterMigrate func(ctx context.Context, pool *pgxpool.Pool) error
}
Overrides are what a wrapping application supplies. Every field is optional; nil means the engine's own.
type Owner ¶
Owner is the principal a request acts as. The engine treats ID as opaque; a wrapper may make it an organisation's.
type SlotProvider ¶
type SlotProvider = web.SlotProvider
SlotProvider fills the chrome for one request.
type SlotProviderFunc ¶
type SlotProviderFunc = web.SlotProviderFunc
SlotProviderFunc is a SlotProvider from a function.