Documentation
¶
Overview ¶
Package pfw declares dependency graphs for build-time generation. Put declarations in files guarded by //go:build pfw_inject, then run pfw generate. The generated application uses ordinary constructor calls.
Index ¶
- func Build[T any](registrations ...Registration) (T, error)
- func BuildWithCleanup[T any](registrations ...Registration) (T, func() error, error)
- type Environment
- type Registration
- func AutoBind() Registration
- func Bind[Interface, Concrete any]() Registration
- func Constructors(constructors ...any) Registration
- func Discover(patterns ...string) Registration
- func Environments(names ...Environment) Registration
- func Exclude(constructors ...any) Registration
- func ForEnv(name Environment, registrations ...Registration) Registration
- func Implementation[Interface, Concrete any]() Registration
- func Module(registrations ...Registration) Registration
- func Override(registrations ...Registration) Registration
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Build ¶
func Build[T any](registrations ...Registration) (T, error)
Build declares the root type for an initializer. Initializer parameters are external inputs. Build is a generation marker, never a runtime DI container.
func BuildWithCleanup ¶
func BuildWithCleanup[T any](registrations ...Registration) (T, func() error, error)
BuildWithCleanup declares a root whose resources are owned by the initializer. On success the generated function returns a cleanup that runs once, in reverse construction order. On failure cleanup runs automatically and is returned nil. Existing constructors returning T or (T, error) are supported as well.
Types ¶
type Environment ¶
type Environment string
Environment is an application-defined name, validated without predefined semantics.
const ( Local Environment = "local" Staging Environment = "staging" Production Environment = "production" )
Conventional names are optional conveniences; applications declare their own supported names through Environments.
func EnvironmentFromEnv ¶
func EnvironmentFromEnv(fallback Environment) (Environment, error)
EnvironmentFromEnv resolves PFW_ENV, or an explicit application fallback. An explicitly empty PFW_ENV is invalid rather than silently using a fallback.
func (Environment) Validate ¶
func (e Environment) Validate() error
type Registration ¶
type Registration struct {
// contains filtered or unexported fields
}
Registration is a build-time declaration read by the generator.
func AutoBind ¶
func AutoBind() Registration
AutoBind enables interface inference for providers in its enclosing Module, including nested modules. Other modules remain explicit by default.
func Bind ¶
func Bind[Interface, Concrete any]() Registration
Bind is an alias for Implementation, with the same type argument order.
func Constructors ¶
func Constructors(constructors ...any) Registration
Constructors registers named constructor functions, whose parameters are their dependencies. Supported results are T, (T, error), and (T, func() error, error) for resources that need cleanup.
func Discover ¶
func Discover(patterns ...string) Registration
Discover registers functions annotated //pfw:coconut in selected Go package patterns. Relative patterns are resolved from the initializer's package.
func Environments ¶
func Environments(names ...Environment) Registration
Environments declares supported names. It is required for initializers with an Environment parameter; ForEnv names must belong to this explicit set.
func Exclude ¶
func Exclude(constructors ...any) Registration
Exclude removes constructors from discovery, independent of declaration order. Explicit Constructors registrations remain available.
func ForEnv ¶
func ForEnv(name Environment, registrations ...Registration) Registration
ForEnv activates registrations in the named environment only.
func Implementation ¶
func Implementation[Interface, Concrete any]() Registration
Implementation selects Concrete as the implementation of Interface. The generator verifies implementation using Go's type system.
func Module ¶
func Module(registrations ...Registration) Registration
Module groups static registrations without imposing a package layout.
func Override ¶
func Override(registrations ...Registration) Registration
Override gives wrapped constructors precedence in their scope. Manual interface bindings still win; different override candidates remain ambiguous.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
pfw
command
|
|
|
Package config loads environment variables into typed application configuration.
|
Package config loads environment variables into typed application configuration. |
|
examples
|
|
|
cleanup
command
|
|
|
httpapi/cmd/api
command
|
|
|
Package http provides transport-independent HTTP responses, JSON decoding and application error mapping.
|
Package http provides transport-independent HTTP responses, JSON decoding and application error mapping. |
|
internal
|
|
|
di
Package di implements the build-time dependency graph used by pfw.
|
Package di implements the build-time dependency graph used by pfw. |
|
generate
Package generate loads explicit pfw declarations and emits Go initializers.
|
Package generate loads explicit pfw declarations and emits Go initializers. |
|
scaffold
Package scaffold creates standalone Go projects from bundled templates.
|
Package scaffold creates standalone Go projects from bundled templates. |
|
Package lifecycle coordinates application components and resource cleanup.
|
Package lifecycle coordinates application components and resource cleanup. |
|
transport
|
|
|
httpserver
Package httpserver connects a standard HTTP server to the application lifecycle.
|
Package httpserver connects a standard HTTP server to the application lifecycle. |