Documentation
¶
Overview ¶
Package togo is the microkernel of the togo framework. The kernel is deliberately thin: configuration, a hook/event bus, a plugin loader+registry, a database pool, and server bootstrap. Every capability — REST, GraphQL, auth, dashboard, resources — ships as a Plugin installed by the CLI and discovered here.
Index ¶
- func Register(p Plugin)
- func RegisterProvider(p Provider)
- type Config
- type HookFunc
- type Hooks
- type Kernel
- func (k *Kernel) Boot(ctx context.Context) error
- func (k *Kernel) Close()
- func (k *Kernel) Dialect() orm.Dialect
- func (k *Kernel) Plugins() []Plugin
- func (k *Kernel) ReportError(ctx context.Context, err error)
- func (k *Kernel) SQL(ctx context.Context) (*sql.DB, error)
- func (k *Kernel) Serve(ctx context.Context) error
- func (k *Kernel) T(key string) string
- func (k *Kernel) Use(p Plugin) *Kernel
- type Plugin
- type Provider
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Register ¶
func Register(p Plugin)
Register adds a plugin to the global auto-discovery registry.
func RegisterProvider ¶ added in v0.7.0
func RegisterProvider(p Provider)
RegisterProvider registers a service provider. Later registrations override earlier ones for the same capability.
Types ¶
type Config ¶
type Config struct {
Addr string
DBDriver string // database/sql driver name (default "sqlite"); providers register others
DatabaseURL string
GraphQLPath string
RESTPath string
DocsPath string
Locale string
LocaleDir string
StorageDir string
}
Config holds runtime configuration resolved from the environment, so connections/URLs/endpoints stay dynamic (togo convention: .env + hooks).
func LoadConfig ¶
func LoadConfig() *Config
LoadConfig reads configuration from environment variables with sane defaults. SQLite is the default driver — no external database needed to get started.
type Hooks ¶
type Hooks struct {
// contains filtered or unexported fields
}
Hooks is a priority-ordered event bus for lifecycle events (resource CRUD, auth, plugin load). Listeners run in ascending priority (0 first).
type Kernel ¶
type Kernel struct {
Config *Config
Router chi.Router
Hooks *Hooks
Log *slog.Logger
Cache cache.Cache
Queue queue.Queue
Storage storage.Storage
Realtime *realtime.Broker
I18n *i18n.Bundle
// contains filtered or unexported fields
}
Kernel is the shared runtime handed to every plugin and used by the app's entrypoint to mount REST/GraphQL and serve.
func New ¶
func New() *Kernel
New constructs a kernel: loads config, logger, router (with recovery + request-logging middleware) and hook bus, and seeds the plugin list from auto-discovery (blank-imported plugin packages).
func (*Kernel) Boot ¶
Boot runs Register then Boot for every plugin in priority order. Safe to call once; subsequent calls are no-ops.
func (*Kernel) ReportError ¶ added in v0.2.0
ReportError logs an error and fires the "error" hook so trackers (Sentry, GlitchTip, …) shipped as plugins can capture it. This is togo's central error reporting path — call it from anywhere with an error worth surfacing.
func (*Kernel) SQL ¶ added in v0.3.0
SQL returns a lazily-opened database/sql handle using Config.DBDriver (default "sqlite"). Driver registration is the app's responsibility (blank-import the driver, or a DB provider plugin) — SQLite is core; Postgres/MySQL/etc. are provider plugins that register their driver and set DB_DRIVER.
type Plugin ¶
type Plugin interface {
// Name uniquely identifies the plugin (e.g. "rest-huma", "auth-supabase").
Name() string
// Priority controls boot order; lower boots first. Infrastructure plugins
// (config, db) use low values; feature plugins use higher ones.
Priority() int
// Register binds services, config, and hooks. No I/O or route mounting here.
Register(k *Kernel) error
// Boot starts the plugin: mount routes, register schema, run migrations.
Boot(ctx context.Context, k *Kernel) error
}
Plugin is the contract every togo capability implements. The runtime boots plugins in ascending Priority order (0–100), mirroring laravilt's ordered service-provider lifecycle.
func Discovered ¶
func Discovered() []Plugin
Discovered returns a copy of the auto-registered plugins.
type Provider ¶ added in v0.7.0
Provider contributes a service to the kernel. The kernel core is tiny (config, router, hooks, plugin lifecycle); every other capability — log, cache, queue, storage, realtime, i18n — is a Provider. A plugin can RegisterProvider to replace a default (e.g. a Redis cache) without touching the kernel.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package cache provides a simple key/value cache abstraction.
|
Package cache provides a simple key/value cache abstraction. |
|
Package faker generates realistic fake data for factories and seeders.
|
Package faker generates realistic fake data for factories and seeders. |
|
Package i18n provides JSON-keyed translations for the backend.
|
Package i18n provides JSON-keyed translations for the backend. |
|
Package orm is a small, driver-agnostic, Eloquent-style query builder over database/sql.
|
Package orm is a small, driver-agnostic, Eloquent-style query builder over database/sql. |
|
Package queue provides a job queue abstraction.
|
Package queue provides a job queue abstraction. |
|
Package realtime provides server-push streaming.
|
Package realtime provides server-push streaming. |
|
Package storage provides a file storage abstraction.
|
Package storage provides a file storage abstraction. |