Documentation
¶
Index ¶
- Variables
- func Check(config Config) error
- func DispatchFlags(config Config, sqlDB *sql.DB, dialect db.Dialect, ...) (bool, error)
- func DumpModels(config Config) ([]migration.Model, error)
- func LoadDBDSNFromEnv() string
- func LoadDBDialectFromEnv() (db.Dialect, error)
- func LoadEnvFile(path string) error
- func Serve(config Config, sqlDB *sql.DB, dialect db.Dialect) error
- type App
- type AppCheck
- type Checker
- type Config
- type Context
- func (c *Context) Bind(dst any) error
- func (c *Context) Context() context.Context
- func (c *Context) HTML(status int, tmpl *template.Template, name string, data any) error
- func (c *Context) JSON(status int, payload any) error
- func (c *Context) Param(name string) string
- func (c *Context) Query(name string) string
- func (c *Context) Redirect(url string) error
- func (c *Context) Request() *http.Request
- func (c *Context) ResponseWriter() http.ResponseWriter
- type IncludeOption
- type Middleware
- type Params
- type ProjectStatus
- type Registry
- func (r *Registry) Admin() *adminregistry.Registry
- func (r *Registry) Checks() []AppCheck
- func (r *Registry) Models() *model.Registry
- func (r *Registry) Register(app App) error
- func (r *Registry) Routes() *RouteRegistry
- func (r *Registry) RunRegistration() error
- func (r *Registry) SetStore(store *db.Store)
- func (r *Registry) Store() (*db.Store, bool)
- type Reverser
- type Route
- type RouteOption
- type RouteRegistry
- func (rr *RouteRegistry) Handler() (http.Handler, error)
- func (rr *RouteRegistry) Include(prefix string, routes []Route, opts ...IncludeOption) error
- func (rr *RouteRegistry) IncludedNames() []string
- func (rr *RouteRegistry) IncludedPatterns() []string
- func (rr *RouteRegistry) Reverser() (Reverser, error)
- type URLs
- type View
Constants ¶
This section is empty.
Variables ¶
var ErrDuplicateApp = errors.New("tango: duplicate app name")
ErrDuplicateApp is returned by Registry.Register when an app with the same Name() has already been registered.
var ErrDuplicateRouteName = errors.New("tango: duplicate route name")
ErrDuplicateRouteName is returned when two routes resolve to the same fully-qualified name.
var ErrMalformedPattern = errors.New("tango: malformed route pattern")
ErrMalformedPattern is returned when a route pattern has unbalanced parameter placeholders (e.g. an unclosed "{").
var ErrMissingParam = errors.New("tango: missing route param")
ErrMissingParam is returned by Reverse when a pattern's placeholder has no corresponding entry in params.
var ErrRegistrationNotComplete = errors.New("tango: registration not complete")
ErrRegistrationNotComplete is returned by Handler and Reverser when Registry.RunRegistration has not yet completed.
var ErrUnknownRouteName = errors.New("tango: unknown route name")
ErrUnknownRouteName is returned by Reverse for a route name that was never registered.
Functions ¶
func Check ¶
Check validates that the configured app registry can boot, compile routes, and pass every AppCheck contributed by installed apps.
func DispatchFlags ¶
func DispatchFlags(config Config, sqlDB *sql.DB, dialect db.Dialect, migrations []migration.Migration) (bool, error)
DispatchFlags handles tanGO's app-side CLI flags. It returns handled=true when a flag path ran and the caller should exit after checking err.
func DumpModels ¶
DumpModels boots config's registry and returns its registered models in the dialect-agnostic shape `tango makemigrations` diffs against. This is the documented convention behind the "-tango-dump-models" flag: an app's main.go handling that flag calls DumpModels, JSON-encodes the result to stdout, and exits — mirroring the "-check" flag convention from Milestone 6.
func LoadDBDSNFromEnv ¶
func LoadDBDSNFromEnv() string
LoadDBDSNFromEnv returns TANGO_DB_DSN, or an empty string when unset.
func LoadDBDialectFromEnv ¶
LoadDBDialectFromEnv returns the DB dialect selected by TANGO_DB_DIALECT. It defaults to SQLite when unset.
func LoadEnvFile ¶
LoadEnvFile loads simple KEY=VALUE lines from path into the process environment without overriding variables that are already set.
Types ¶
type App ¶
App is the narrow contract every tanGO application unit satisfies. This interface is stable: no breaking changes are planned, and apps are not expected to implement it by hand (use NewApp).
A distributable third-party app package should expose one exported App value or constructor at its package root, e.g.:
var App = tango.NewApp("widgets", registerWidgets)
or, if the app needs configuration:
func New(cfg Config) tango.App { ... }
Importers then reference it directly: InstalledApps: []tango.App{widgets.App} or InstalledApps: []tango.App{widgets.New(cfg)}. No other framework integration is required.
An App may optionally also implement Checker to contribute advisory checks; it is never required to.
An app that ships its own templates or static assets embeds and mounts them itself, via its own embed.FS and a route registered through Include/Routes() inside its Register callback — the same pattern the admin package uses. There is no separate framework-level mechanism for this.
type AppCheck ¶
AppCheck is one advisory finding contributed by an App. A nil Err means the check passed. Named AppCheck (not Check) to avoid colliding with the existing package-level Check(Config) error function from Milestone 6.
type Checker ¶
type Checker interface {
Checks() []AppCheck
}
Checker is an optional capability an App may implement to contribute advisory checks surfaced by Registry.Checks (and, in turn, `tango check`). Implementing Checker is never required.
type Config ¶
type Config struct {
InstalledApps []App
Addr string
Middleware []Middleware
}
Config is the minimal application configuration for v0.1.
func LoadConfigFromEnv ¶
func LoadConfigFromEnv() Config
LoadConfigFromEnv returns a Config populated from environment variables.
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context wraps an HTTP request/response pair with high-value helpers. Escape hatches (Request, ResponseWriter) are available when the helpers below aren't enough.
func (*Context) Context ¶
Context returns the wrapped request's standard context.Context. Context does not itself implement context.Context.
func (*Context) HTML ¶
HTML renders the named template within tmpl (via tmpl.ExecuteTemplate) against data, writing it as an HTML response with the given status code. The render is buffered: nothing is written to the response until execution fully succeeds, so a template error is returned like any other view error (a clean framework-generated 500) instead of a response that already committed status and headers followed by a truncated or malformed body. tmpl must already be parsed; HTML has no opinion on template parsing, caching, or file layout.
func (*Context) ResponseWriter ¶
func (c *Context) ResponseWriter() http.ResponseWriter
ResponseWriter returns the wrapped http.ResponseWriter.
type IncludeOption ¶
type IncludeOption func(*includeConfig)
IncludeOption customizes one Include call.
func WithMiddleware ¶
func WithMiddleware(middleware ...Middleware) IncludeOption
WithMiddleware attaches Middleware to every Route mounted by one Include call. Middleware runs before *Context is constructed; the first middleware passed is outermost.
type Middleware ¶
Middleware wraps a raw net/http handler before a *tango.Context exists. Use it for cross-cutting HTTP concerns such as recovery, logging, request IDs, CORS, or compression. Context-aware behavior such as auth redirects belongs in a View wrapper instead.
func Recoverer ¶
func Recoverer() Middleware
Recoverer returns middleware that converts downstream panics into the same generic JSON 500 response tanGO uses for Views that return errors.
type ProjectStatus ¶
type ProjectStatus struct {
RegistrationOK bool `json:"registrationOk"`
RegistrationError string `json:"registrationError,omitempty"`
DatabaseReachable bool `json:"databaseReachable"`
DatabaseError string `json:"databaseError,omitempty"`
MigrationsTotal int `json:"migrationsTotal"`
MigrationsApplied int `json:"migrationsApplied"`
MigrationsPending int `json:"migrationsPending"`
}
ProjectStatus is a snapshot of a project's registration, database, and migration state, produced by Status. It is the payload behind the documented "-tango-status" flag convention (see Milestone 8.3).
func Status ¶
func Status(ctx context.Context, config Config, sqlDB *sql.DB, dialect db.Dialect, migrations []migration.Migration) ProjectStatus
Status reports config's registration status, sqlDB's reachability, and migrations' applied/pending counts, without writing to the database or filesystem. This is the documented convention behind the "-tango-status" flag: an app's main.go handling that flag calls Status, JSON-encodes the result to stdout, and exits — mirroring "-check" and "-tango-dump-models".
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry is the shared structure apps register into during boot.
func BuildRegistry ¶
BuildRegistry registers Config.InstalledApps into a new Registry.
func NewRegistry ¶
func NewRegistry() *Registry
NewRegistry returns an empty, ready-to-use Registry.
func (*Registry) Admin ¶
func (r *Registry) Admin() *adminregistry.Registry
Admin returns the admin sub-registry, creating it on first use.
func (*Registry) Checks ¶
Checks returns every advisory AppCheck contributed by installed apps that implement Checker, in InstalledApps order. Apps that do not implement Checker are skipped without error. Checks is only meaningful after RunRegistration has completed.
func (*Registry) Register ¶
Register adds app to the registry. It returns an error wrapping ErrDuplicateApp if an app with the same Name() has already been registered, without invoking any app's Register callback.
func (*Registry) Routes ¶
func (r *Registry) Routes() *RouteRegistry
Routes returns the route sub-registry, creating it on first use.
func (*Registry) RunRegistration ¶
RunRegistration invokes each registered app's Register callback exactly once, in the order the apps were added, passing this Registry to each. It stops and returns the first error encountered, and does not invoke any subsequent app's callback.
func (*Registry) SetStore ¶
SetStore stores the persistence store for apps that need database access. It also wires this Registry's model registry into store (store.UseModels), so Delete cascades across every registered model's foreign keys with no extra call needed by app code — see db.Store.UseModels.
type Route ¶
type Route struct {
// contains filtered or unexported fields
}
Route declares how an HTTP method and path pattern map to a View.
func Path ¶
func Path(method, pattern string, view View, opts ...RouteOption) Route
Path constructs a Route declaration without executing its View.
func (Route) Middleware ¶
func (r Route) Middleware() []Middleware
Middleware returns the route-scoped Middleware attached to this Route.
type RouteOption ¶
type RouteOption func(*Route)
RouteOption customizes a Route during construction.
func Use ¶
func Use(middleware ...Middleware) RouteOption
Use attaches Middleware to one Route. Middleware runs before *Context is constructed; the first middleware passed is outermost.
type RouteRegistry ¶
type RouteRegistry struct {
// contains filtered or unexported fields
}
RouteRegistry is the Milestone 2 sub-registry apps contribute routes to, mirroring the shape of Milestone 1's Registry sub-APIs.
func (*RouteRegistry) Handler ¶
func (rr *RouteRegistry) Handler() (http.Handler, error)
Handler compiles the full route tree, contributed by every app's Include call, into a plain http.Handler. It returns ErrRegistrationNotComplete if Registry.RunRegistration has not yet completed, and a non-nil error if two different Include calls produced the same fully-qualified route name.
func (*RouteRegistry) Include ¶
func (rr *RouteRegistry) Include(prefix string, routes []Route, opts ...IncludeOption) error
Include mounts routes under prefix, namespace-qualifying any named route and normalizing trailing slashes so Include("/users", ...) and Include("/users/", ...) behave identically. It fails fast on a malformed pattern or a duplicate fully-qualified name within this call's routes, registering none of them in that case. Cross-call duplicate detection is deferred to Handler/Reverser compile time.
func (*RouteRegistry) IncludedNames ¶
func (rr *RouteRegistry) IncludedNames() []string
IncludedNames returns the fully-qualified names of every named route included so far, in inclusion order. It exists to make Include's namespacing/normalization behavior testable before Handler/Reverser land.
func (*RouteRegistry) IncludedPatterns ¶
func (rr *RouteRegistry) IncludedPatterns() []string
IncludedPatterns returns the mounted path pattern of every route included so far, in inclusion order.
func (*RouteRegistry) Reverser ¶
func (rr *RouteRegistry) Reverser() (Reverser, error)
Reverser compiles the full route tree (the same compilation Handler performs) and returns a Reverser for building URLs from route names. It returns ErrRegistrationNotComplete if Registry.RunRegistration has not yet completed.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package accounts is tanGO's first-party, optional, installable reusable app: a ready-made HTML email/password register/login/logout flow, built by composing github.com/angvp/tango/auth's primitives rather than adding to them.
|
Package accounts is tanGO's first-party, optional, installable reusable app: a ready-made HTML email/password register/login/logout flow, built by composing github.com/angvp/tango/auth's primitives rather than adding to them. |
|
Package auth provides composable authentication primitives for tanGO applications.
|
Package auth provides composable authentication primitives for tanGO applications. |
|
jwt
Package jwt provides explicit, stateless HS256 access-token primitives.
|
Package jwt provides explicit, stateless HS256 access-token primitives. |
|
cache
|
|
|
memcache
module
|
|
|
redis
module
|
|
|
cmd
|
|
|
tango
command
|
|
|
Package i18n provides tanGO's small text-translation primitives.
|
Package i18n provides tanGO's small text-translation primitives. |
|
internal
|
|
|
Package realtime provides transport-neutral, single-process room coordination.
|
Package realtime provides transport-neutral, single-process room coordination. |
|
websocket
Package websocket adapts realtime.Coordinator to an HTTP WebSocket upgrade, wrapping github.com/coder/websocket.
|
Package websocket adapts realtime.Coordinator to an HTTP WebSocket upgrade, wrapping github.com/coder/websocket. |
|
storage
|
|
|
gcs
module
|
|
|
s3
module
|