Help us shape the future of Go! Take the 2026 Go Developer Survey

seed

package
v0.0.0-...-2fd5d2c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 14, 2026 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const HandlerScopeFilename = "handler-scope.json"

HandlerScopeFilename is the file the CLI writes so a handler can resolve which of the application's resources it actually uses.

The resource links file describes what each resource is, which is a property of the application and identical for every handler. This file records which of those a given handler touches, which is a property of the handler.

One bundle serves every function, so the resource links file necessarily describes the whole application. With nothing else to go on, the SDK's resource layers took it as their scope and every handler initialised every resource type present anywhere in the app. A handler using nothing but its own config still resolved the internal resources namespace, and failed at cold start on `Config namespace "resources" not registered`.

View Source
const ResourcesConfigStoreID = "resources"

ResourcesConfigStoreID is the Valkey key used for the "resources" config namespace. The SDK's resource layers (datastore, bucket, queue, topic, cache, sql-database) read connection credentials from this namespace.

Variables

This section is empty.

Functions

func ConfigStoreIDEnvVars

func ConfigStoreIDEnvVars(bp *schema.Blueprint) map[string]string

ConfigStoreIDEnvVars generates the environment variables that tell the runtime where to find each config store in Valkey.

func DetectContentType

func DetectContentType(objectKey string, data []byte) string

DetectContentType determines the MIME type for an object by extension, falling back to http.DetectContentType for unrecognised extensions.

func HandlerScopeJSON

func HandlerScopeJSON(bp *schema.Blueprint) (string, error)

HandlerScopeJSON maps each handler's id to the resources it uses.

Keyed by handler id, the value of spec.handler such as "app-module.StatsController.check", because that is what reaches the running function as CELERITY_HANDLER_ID and so the only thing a handler can identify itself by at cold start.

An entry with an empty list is meaningful and is written, recording that the handler reaches nothing and so must not initialise anything. That differs from having no entry at all, which happens for an older bundle or a handler whose id could not be determined. The SDK treats a missing entry as the whole application being in scope, degrading to the behaviour that existed before this file rather than to a handler that silently reaches nothing.

func LoadAndMergeConfig

func LoadAndMergeConfig(configDir string, secretsDir string, storeName string) (map[string]string, error)

LoadAndMergeConfig reads config and secrets YAML files for a given store name, merges them (secrets override config), and returns the combined map.

func LoadConfigYAML

func LoadConfigYAML(filePath string) (map[string]string, error)

LoadConfigYAML reads a YAML file containing flat key-value pairs and returns them as a map. Returns an empty map if the file does not exist.

func ResolveConfigDir

func ResolveConfigDir(appDir string, mode string) string

ResolveConfigDir determines the config directory based on the command mode. For "test" mode, it prefers config/test/ and falls back to config/local/. For "run" mode (or any other), it uses config/local/.

func ResolveSecretsDir

func ResolveSecretsDir(appDir string, mode string) string

ResolveSecretsDir determines the secrets directory based on the command mode. For "test" mode, it prefers secrets/test/ and falls back to secrets/local/. For "run" mode (or any other), it uses secrets/local/.

func ResolveSeedDir

func ResolveSeedDir(appDir string, mode string) string

ResolveSeedDir determines the seed directory based on the command mode. For "test" mode, it prefers seed/test/ and falls back to seed/local/. For "run" mode (or any other), it uses seed/local/.

func ResourceConfigValues

func ResourceConfigValues(bp *schema.Blueprint) map[string]string

ResourceConfigValues generates all resource credential config keys for the "resources" config namespace. This includes cache, datastore, bucket, queue, topic, and SQL database resources.

func ResourceLinksJSON

func ResourceLinksJSON(bp *schema.Blueprint) (string, error)

ResourceLinksJSON generates the CELERITY_RESOURCE_LINKS JSON string from a blueprint. This env var tells the SDK about the resource topology so each resource layer (datastore, bucket, queue, topic, cache, sql-database) can discover and initialise its resources.

The output maps resource names to {type, configKey} objects:

{"usersDatastore": {"type":"datastore","configKey":"users"}, ...}

The configKey is derived from spec.name (falling back to the resource name).

func ResourcesConfigStoreEnvVars

func ResourcesConfigStoreEnvVars() map[string]string

ResourcesConfigStoreEnvVars returns the environment variables needed to register the "resources" config namespace in the SDK's ConfigService.

func RunHooks

func RunHooks(
	ctx context.Context,
	scripts []string,
	serviceEndpoints map[string]string,
	onOutput HookOutputFunc,
	logger *zap.Logger,
) error

RunHooks executes post-setup hook scripts from the seed directory. Each script receives service endpoint environment variables so hooks can interact with running local services. Output is streamed line-by-line through the onOutput callback.

Types

type BucketProvisioner

type BucketProvisioner interface {
	ProvisionBucket(ctx context.Context, bucketName string) error
}

BucketProvisioner creates storage buckets.

type ConfigResourceInfo

type ConfigResourceInfo struct {
	ResourceName string
	StoreName    string
}

ConfigResourceInfo describes a config resource extracted from the blueprint.

func CollectConfigResources

func CollectConfigResources(bp *schema.Blueprint) []ConfigResourceInfo

CollectConfigResources extracts celerity/config resources from a blueprint and returns their resource names and spec.name values.

type ConfigSeedResult

type ConfigSeedResult struct {
	StoreIDs []string
	Keys     int
}

ConfigSeedResult tracks what was seeded for TUI reporting.

type ConfigSeeder

type ConfigSeeder interface {
	SeedConfig(ctx context.Context, storeID string, values map[string]string) error
	Close() error
}

ConfigSeeder loads config and secrets YAML files into a Valkey store.

type DatastoreProvisioner

type DatastoreProvisioner interface {
	ProvisionTable(ctx context.Context, table TableDefinition) error
}

DatastoreProvisioner creates tables/buckets from blueprint resource definitions.

type DynamoDBProvisioner

type DynamoDBProvisioner struct {
	// contains filtered or unexported fields
}

DynamoDBProvisioner provisions DynamoDB tables in DynamoDB Local.

func NewDynamoDBProvisioner

func NewDynamoDBProvisioner(endpoint string, logger *zap.Logger) *DynamoDBProvisioner

NewDynamoDBProvisioner creates a provisioner targeting a DynamoDB Local endpoint.

func (*DynamoDBProvisioner) ProvisionTable

func (p *DynamoDBProvisioner) ProvisionTable(ctx context.Context, table TableDefinition) error

type DynamoDBSeeder

type DynamoDBSeeder struct {
	// contains filtered or unexported fields
}

DynamoDBSeeder implements NoSQLSeeder for DynamoDB Local.

func NewDynamoDBSeeder

func NewDynamoDBSeeder(endpoint string, logger *zap.Logger) *DynamoDBSeeder

NewDynamoDBSeeder creates a seeder targeting a DynamoDB Local endpoint.

func (*DynamoDBSeeder) PutItem

func (s *DynamoDBSeeder) PutItem(ctx context.Context, tableName string, itemJSON []byte) error

type HookLine

type HookLine struct {
	Script string
	Line   string
	IsErr  bool
}

HookLine represents a single line of output from a hook script.

type HookOutputFunc

type HookOutputFunc func(line HookLine)

HookOutputFunc is called for each line of output from a hook script.

type IndexDefinition

type IndexDefinition struct {
	Name   string
	Fields []KeyField
}

IndexDefinition describes a secondary index.

type KeyField

type KeyField struct {
	Name     string
	DataType string
}

KeyField is a name + type pair for a key attribute.

type MinIOProvisioner

type MinIOProvisioner struct {
	// contains filtered or unexported fields
}

MinIOProvisioner provisions MinIO buckets.

func NewMinIOProvisioner

func NewMinIOProvisioner(endpoint string, accessKey string, secretKey string, logger *zap.Logger) (*MinIOProvisioner, error)

NewMinIOProvisioner creates a provisioner targeting a MinIO endpoint.

func (*MinIOProvisioner) ProvisionBucket

func (p *MinIOProvisioner) ProvisionBucket(ctx context.Context, bucketName string) error

type MinIOUploader

type MinIOUploader struct {
	// contains filtered or unexported fields
}

MinIOUploader implements StorageUploader for MinIO.

func NewMinIOUploader

func NewMinIOUploader(endpoint string, accessKey string, secretKey string, logger *zap.Logger) (*MinIOUploader, error)

NewMinIOUploader creates an uploader targeting a MinIO endpoint.

func (*MinIOUploader) Upload

func (u *MinIOUploader) Upload(
	ctx context.Context,
	bucketName string,
	objectKey string,
	data []byte,
) error

type NoSQLSeeder

type NoSQLSeeder interface {
	PutItem(ctx context.Context, tableName string, itemJSON []byte) error
}

NoSQLSeeder inserts records into a NoSQL datastore.

type NoSQLTableSeed

type NoSQLTableSeed struct {
	TableName string
	Files     []string
}

NoSQLTableSeed represents seed data for a single NoSQL table.

type ProvisionResult

type ProvisionResult struct {
	Tables  []string
	Buckets []string
}

ProvisionResult tracks what was provisioned for TUI reporting.

func ProvisionFromBlueprint

func ProvisionFromBlueprint(
	ctx context.Context,
	bp *schema.Blueprint,
	datastoreProvisioner DatastoreProvisioner,
	bucketProvisioner BucketProvisioner,
	streamEnabledTables map[string]bool,
	logger *zap.Logger,
) (*ProvisionResult, error)

ProvisionFromBlueprint reads the blueprint and provisions tables and buckets for local development. streamEnabledTables is a set of datastore resource names that should have change streams enabled (e.g. DynamoDB Streams) because a consumer is linked to them.

type SQLDatabaseSeed

type SQLDatabaseSeed struct {
	DatabaseName string
	Files        []string // .sql files, sorted alphabetically
}

SQLDatabaseSeed represents seed data for a single SQL database. Each subdirectory in sql/ maps to a database name (matching celerity/sqlDatabase spec.name).

type SQLSeeder

type SQLSeeder interface {
	ExecSQL(ctx context.Context, databaseName string, sql string) error
}

SQLSeeder executes SQL statements against a named database.

type SeedConfig

type SeedConfig struct {
	NoSQL   []NoSQLTableSeed
	SQL     []SQLDatabaseSeed
	Storage []StorageBucketSeed
	Hooks   []string
}

SeedConfig describes all seed data discovered in a convention directory.

func LoadSeedConfig

func LoadSeedConfig(seedDir string) (*SeedConfig, error)

LoadSeedConfig discovers seed data in the given directory following the Celerity convention structure: nosql/, sql/, buckets/, hooks/. Returns nil if the directory does not exist.

type SeedResult

type SeedResult struct {
	Records    int
	Files      int
	SQLScripts int
}

SeedResult tracks what was seeded for TUI reporting.

func ExecuteSeed

func ExecuteSeed(
	ctx context.Context,
	cfg *SeedConfig,
	nosqlSeeder NoSQLSeeder,
	storageUploader StorageUploader,
	sqlSeeder SQLSeeder,
	logger *zap.Logger,
) (*SeedResult, error)

ExecuteSeed applies seed data from a loaded SeedConfig to the running services.

type StorageBucketSeed

type StorageBucketSeed struct {
	BucketName string
	Files      []string
}

StorageBucketSeed represents seed data for a single storage bucket.

type StorageUploader

type StorageUploader interface {
	Upload(ctx context.Context, bucketName string, objectKey string, data []byte) error
}

StorageUploader uploads files to an object store bucket.

type TableDefinition

type TableDefinition struct {
	Name          string
	PartitionKey  KeyField
	SortKey       *KeyField
	Indexes       []IndexDefinition
	Fields        map[string]string
	StreamEnabled bool
}

TableDefinition describes a NoSQL table to provision.

type ValkeyConfigSeeder

type ValkeyConfigSeeder struct {
	// contains filtered or unexported fields
}

ValkeyConfigSeeder implements ConfigSeeder using a Valkey (Redis-compatible) backend.

func NewValkeyConfigSeeder

func NewValkeyConfigSeeder(endpoint string, logger *zap.Logger) (*ValkeyConfigSeeder, error)

NewValkeyConfigSeeder creates a new Valkey config seeder. The endpoint must be a redis:// URL (e.g. "redis://localhost:6379") as produced by the compose generator's runtime env vars.

func (*ValkeyConfigSeeder) Close

func (s *ValkeyConfigSeeder) Close() error

Close closes the Valkey client connection.

func (*ValkeyConfigSeeder) SeedConfig

func (s *ValkeyConfigSeeder) SeedConfig(ctx context.Context, storeID string, values map[string]string) error

SeedConfig merges a config map into the JSON-encoded value in Valkey. If the key already exists, new values are merged into the existing data (new keys are added, existing keys are overwritten). If the key does not exist, it is created with the provided values. The storeID is used as the Valkey key, matching the convention expected by the SDK config local backends.

Directories

Path Synopsis
Package dynamoconv provides pure conversion functions between Go types and DynamoDB attribute values.
Package dynamoconv provides pure conversion functions between Go types and DynamoDB attribute values.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL