Documentation
¶
Overview ¶
core/block.go
core/container.go
core/errors.go
core/get.go
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrBlockNotFound is returned when Get cannot find a registered block by name. ErrBlockNotFound = errors.New("go-code-blocks: block not found") // ErrNotInitialized is returned when a block operation is called before Init. ErrNotInitialized = errors.New("go-code-blocks: block not initialized; call Init first") // ErrItemNotFound is returned when a requested item does not exist. ErrItemNotFound = errors.New("go-code-blocks: item not found") // ErrAlreadyRegistered is returned when registering a duplicate block name. ErrAlreadyRegistered = errors.New("go-code-blocks: block already registered") )
Functions ¶
func Get ¶
Get retrieves a registered block by name and asserts it to type B. Returns ErrBlockNotFound when the name is unknown, or a type mismatch error when the block exists but its concrete type does not match B.
This is the preferred retrieval API when the concrete block type is known at the call site, as it avoids a manual type assertion in application code.
users, err := core.Get[*dynamodb.Block[User]](app, "users")
if err != nil { … }
users.PutItem(ctx, u)
Types ¶
type Block ¶
type Block interface {
// Name returns the unique identifier used to register and retrieve this block.
Name() string
// Init establishes connections, validates configuration, and readies the block.
// It is called once during application startup.
Init(ctx context.Context) error
// Shutdown releases all resources held by the block.
// It is called in reverse-registration order during graceful shutdown.
Shutdown(ctx context.Context) error
}
Block defines the lifecycle contract that every integration block must fulfill. Blocks are self-contained units that encapsulate a single external dependency (DynamoDB, S3, Redis, etc.) and expose a typed API over it.
type Container ¶
type Container struct {
// contains filtered or unexported fields
}
Container manages the registration and lifecycle of all blocks. Blocks are initialized in registration order and shut down in reverse order, following standard dependency teardown conventions.
func (*Container) Get ¶
Get retrieves a registered block by name. Returns ErrBlockNotFound if no block with that name exists.
func (*Container) InitAll ¶
InitAll initializes all registered blocks in registration order. Stops and returns on the first error.
func (*Container) MustRegister ¶
MustRegister is like Register but panics on error. Useful for wiring blocks at startup where an error is unrecoverable.