config

package
v1.13.4 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package config reads and validates the .forge.yaml project file and the per-app .forge.yaml files the CLI commands run against.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateForgeConfig

func CreateForgeConfig(path string, config *ForgeConfig) error

CreateForgeConfig creates a new .forge.yaml file with default or provided config.

func FormatValidationErrors

func FormatValidationErrors(errs []ValidationError) string

FormatValidationErrors formats validation errors for display.

func SaveForgeConfig

func SaveForgeConfig(config *ForgeConfig, path string) error

SaveForgeConfig saves the configuration to a file. Uses omitempty tags to produce clean, minimal YAML output.

func ValidateConfig

func ValidateConfig(config *ForgeConfig) error

ValidateConfig validates the configuration.

Types

type AppBuildConfig

type AppBuildConfig struct {
	Output     string   `yaml:"output"`
	Dockerfile string   `yaml:"dockerfile,omitempty"`
	Tags       []string `yaml:"tags,omitempty"`
	LDFlags    string   `yaml:"ldflags,omitempty"`
}

AppBuildConfig defines app-specific build configuration.

type AppConfig

type AppConfig struct {
	App      AppSection        `yaml:"app"`
	Dev      AppDevConfig      `yaml:"dev,omitempty"`
	Build    AppBuildConfig    `yaml:"build,omitempty"`
	Database AppDatabaseConfig `yaml:"database,omitempty"`

	// Internal fields
	AppDir     string `yaml:"-"` // Directory containing the app's .forge.yaml
	ConfigPath string `yaml:"-"` // Full path to app's .forge.yaml
}

AppConfig represents app-level .forge.yaml configuration This is different from ForgeConfig (project-level) and is used to configure individual applications within a Forge project.

func LoadAppConfig

func LoadAppConfig(appDir string) (*AppConfig, error)

LoadAppConfig loads an app-level .forge.yaml from the specified directory. Returns the config and any error encountered.

type AppDatabaseConfig

type AppDatabaseConfig struct {
	MigrationsPath string `yaml:"migrations_path,omitempty"` // Override migration directory (relative to app dir)
	SeedsPath      string `yaml:"seeds_path,omitempty"`      // Override seeds directory (relative to app dir)
	Connection     string `yaml:"connection,omitempty"`      // Reference a named connection from project config
}

AppDatabaseConfig defines app-specific database configuration. This allows each app to override the default migration path or reference a specific named connection from the project config.

func (*AppDatabaseConfig) GetMigrationsPath

func (d *AppDatabaseConfig) GetMigrationsPath() string

GetMigrationsPath returns the app-specific migrations path, or empty if not set.

func (*AppDatabaseConfig) GetSeedsPath

func (d *AppDatabaseConfig) GetSeedsPath() string

GetSeedsPath returns the app-specific seeds path, or empty if not set.

type AppDevConfig

type AppDevConfig struct {
	Port    int              `yaml:"port,omitempty"`
	Host    string           `yaml:"host,omitempty"`
	EnvFile string           `yaml:"env_file,omitempty"`
	Docker  *DockerDevConfig `yaml:"docker,omitempty"`
}

AppDevConfig defines app-specific dev configuration.

func (*AppDevConfig) GetHost

func (d *AppDevConfig) GetHost() string

GetHost returns the dev host with fallback to localhost.

func (*AppDevConfig) GetPort

func (d *AppDevConfig) GetPort() int

GetPort returns the dev port with fallback to 0 (not set).

type AppSection

type AppSection struct {
	Name    string `yaml:"name"`
	Type    string `yaml:"type"` // "web", "cli", "worker", etc.
	Version string `yaml:"version,omitempty"`
}

AppSection defines app metadata.

type BuildApp

type BuildApp struct {
	Name       string `yaml:"name"`
	Module     string `yaml:"module,omitempty"` // Multi-module: path to module
	Cmd        string `yaml:"cmd,omitempty"`    // Path to main.go
	Output     string `yaml:"output,omitempty"` // Binary name
	Dockerfile string `yaml:"dockerfile,omitempty"`
}

BuildApp defines a buildable application.

type BuildConfig

type BuildConfig struct {
	OutputDir    string     `yaml:"output_dir,omitempty"`    // Default: ./bin
	CmdDir       string     `yaml:"cmd_dir,omitempty"`       // Default: ./cmd
	AutoDiscover bool       `yaml:"auto_discover,omitempty"` // Default: true
	Apps         []BuildApp `yaml:"apps,omitempty"`          // Optional override
	Platforms    []Platform `yaml:"platforms,omitempty"`     // For future use
	LDFlags      string     `yaml:"ldflags,omitempty"`
	Tags         []string   `yaml:"tags,omitempty"`
}

BuildConfig defines build configuration.

func (*BuildConfig) GetCmdDir

func (b *BuildConfig) GetCmdDir() string

GetCmdDir returns the cmd directory with default fallback.

func (*BuildConfig) GetOutputDir

func (b *BuildConfig) GetOutputDir() string

GetOutputDir returns the build output directory with default fallback.

func (*BuildConfig) ShouldAutoDiscover

func (b *BuildConfig) ShouldAutoDiscover() bool

ShouldAutoDiscover returns true if build should auto-discover apps.

type ConnectionConfig

type ConnectionConfig struct {
	URL            string `yaml:"url"`
	MaxConnections int    `yaml:"max_connections,omitempty"`
	MaxIdle        int    `yaml:"max_idle,omitempty"`
}

ConnectionConfig defines database connection settings.

type DatabaseConfig

type DatabaseConfig struct {
	Driver         string                      `yaml:"driver,omitempty"`          // postgres, mysql, sqlite
	MigrationsPath string                      `yaml:"migrations_path,omitempty"` // Default: ./database/migrations
	SeedsPath      string                      `yaml:"seeds_path,omitempty"`      // Default: ./database/seeds
	ModelsOutput   string                      `yaml:"models_output,omitempty"`
	Connections    map[string]ConnectionConfig `yaml:"connections,omitempty"`
}

DatabaseConfig defines database configuration.

func (*DatabaseConfig) GetMigrationsPath

func (d *DatabaseConfig) GetMigrationsPath() string

GetMigrationsPath returns the migrations path with default fallback.

func (*DatabaseConfig) GetModelsOutput

func (d *DatabaseConfig) GetModelsOutput() string

GetModelsOutput returns the models output path with default fallback.

func (*DatabaseConfig) GetSeedsPath

func (d *DatabaseConfig) GetSeedsPath() string

GetSeedsPath returns the seeds path with default fallback.

type DeployConfig

type DeployConfig struct {
	Registry     string              `yaml:"registry,omitempty"`     // e.g., ghcr.io/myorg
	Environments []EnvironmentConfig `yaml:"environments,omitempty"` // Main config used

	// Platform-specific configs (optional)
	Docker       *DockerConfig       `yaml:"docker,omitempty"`
	Kubernetes   *KubernetesConfig   `yaml:"kubernetes,omitempty"`
	DigitalOcean *DigitalOceanConfig `yaml:"digitalocean,omitempty"`
	Render       *RenderConfig       `yaml:"render,omitempty"`
}

DeployConfig defines deployment configuration.

type DevConfig

type DevConfig struct {
	AutoDiscover    bool            `yaml:"auto_discover,omitempty"`
	DiscoverPattern string          `yaml:"discover_pattern,omitempty"`
	DefaultApp      string          `yaml:"default_app,omitempty"`
	Watch           WatchConfig     `yaml:"watch,omitempty"`
	HotReload       HotReloadConfig `yaml:"hot_reload,omitempty"`
	Docker          DockerDevConfig `yaml:"docker,omitempty"`
}

DevConfig defines development server configuration.

type DigitalOceanConfig

type DigitalOceanConfig struct {
	Region       string `yaml:"region,omitempty"`
	AppSpecFile  string `yaml:"app_spec_file,omitempty"`
	ClusterName  string `yaml:"cluster_name,omitempty"`
	GitRepo      string `yaml:"git_repo,omitempty"`       // e.g., "myorg/myrepo"
	GitBranch    string `yaml:"git_branch,omitempty"`     // e.g., "main"
	DeployOnPush bool   `yaml:"deploy_on_push,omitempty"` // Auto-deploy on push
}

DigitalOceanConfig for Digital Ocean deployment.

type DockerConfig

type DockerConfig struct {
	BuildContext string            `yaml:"build_context,omitempty"`
	Dockerfile   string            `yaml:"dockerfile,omitempty"`
	ComposeFile  string            `yaml:"compose_file,omitempty"`
	Network      string            `yaml:"network,omitempty"`
	Volumes      map[string]string `yaml:"volumes,omitempty"`
}

DockerConfig for Docker deployment.

type DockerDevConfig

type DockerDevConfig struct {
	Enabled    bool              `yaml:"enabled,omitempty"`
	Image      string            `yaml:"image,omitempty"`      // Base image (default: golang:1.25-alpine).
	Dockerfile string            `yaml:"dockerfile,omitempty"` // Custom Dockerfile path for dev.
	Network    string            `yaml:"network,omitempty"`    // Docker network (default: bridge).
	Volumes    map[string]string `yaml:"volumes,omitempty"`    // Extra volumes host:container.
	Env        map[string]string `yaml:"env,omitempty"`        // Extra env vars for the container.
	BuildArgs  map[string]string `yaml:"build_args,omitempty"` // Docker build args.
	Platform   string            `yaml:"platform,omitempty"`   // Target platform (e.g., linux/amd64).
}

DockerDevConfig defines Docker-specific development configuration.

func (*DockerDevConfig) GetImage

func (d *DockerDevConfig) GetImage() string

GetImage returns the Docker base image with default fallback.

func (*DockerDevConfig) GetNetwork

func (d *DockerDevConfig) GetNetwork() string

GetNetwork returns the Docker network with default fallback.

type EnvironmentConfig

type EnvironmentConfig struct {
	Name      string            `yaml:"name"`
	Cluster   string            `yaml:"cluster,omitempty"`
	Namespace string            `yaml:"namespace,omitempty"` // K8s namespace
	Region    string            `yaml:"region,omitempty"`    // Cloud region
	Variables map[string]string `yaml:"variables,omitempty"` // Env vars
}

EnvironmentConfig defines deployment environment.

type ForgeConfig

type ForgeConfig struct {
	Project    ProjectConfig  `yaml:"project"`
	Dev        DevConfig      `yaml:"dev,omitempty"`
	Database   DatabaseConfig `yaml:"database,omitempty"`
	Build      BuildConfig    `yaml:"build,omitempty"`
	Deploy     DeployConfig   `yaml:"deploy,omitempty"`
	Generate   GenerateConfig `yaml:"generate,omitempty"`
	Extensions map[string]any `yaml:"extensions,omitempty"`
	Test       TestConfig     `yaml:"test,omitempty"`

	// Internal fields
	RootDir    string `yaml:"-"` // Directory containing .forge.yaml
	ConfigPath string `yaml:"-"` // Full path to .forge.yaml
}

ForgeConfig represents the complete .forge.yaml configuration.

func DefaultConfig

func DefaultConfig() *ForgeConfig

DefaultConfig returns a default configuration with all fields populated.

func DefaultConfigMinimal

func DefaultConfigMinimal() *ForgeConfig

DefaultConfigMinimal returns minimal config with smart defaults.

func LoadForgeConfig

func LoadForgeConfig() (*ForgeConfig, string, error)

LoadForgeConfig loads the nearest project configuration. Invalid or ambiguous files stop the search.

func LoadForgeConfigFrom

func LoadForgeConfigFrom(root string) (*ForgeConfig, error)

LoadForgeConfigFrom loads root only and rejects ambiguous filenames.

func (*ForgeConfig) HasErrors

func (c *ForgeConfig) HasErrors() bool

HasErrors returns true if there are any error-level validation issues.

func (*ForgeConfig) HasWarnings

func (c *ForgeConfig) HasWarnings() bool

HasWarnings returns true if there are any warning-level validation issues.

func (*ForgeConfig) IsMultiModule

func (c *ForgeConfig) IsMultiModule() bool

IsMultiModule returns true if the project uses multi-module layout.

func (*ForgeConfig) IsSingleModule

func (c *ForgeConfig) IsSingleModule() bool

IsSingleModule returns true if the project uses single-module layout.

func (*ForgeConfig) Validate

func (c *ForgeConfig) Validate() []ValidationError

Validate checks the configuration and returns any validation errors or warnings.

type GenerateConfig

type GenerateConfig struct {
	TemplatesPath string                     `yaml:"templates_path,omitempty"` // Default: ./templates
	Generators    map[string]GeneratorConfig `yaml:"generators,omitempty"`     // Optional overrides
}

GenerateConfig defines code generation configuration.

func (*GenerateConfig) GetTemplatesPath

func (g *GenerateConfig) GetTemplatesPath() string

GetTemplatesPath returns the templates path with default fallback.

type GeneratorConfig

type GeneratorConfig struct {
	Output       string `yaml:"output,omitempty"`        // Template: ./{{.Type}}/{{.Name}}
	CmdPath      string `yaml:"cmd_path,omitempty"`      // Single-module (optional override)
	InternalPath string `yaml:"internal_path,omitempty"` // Single-module (optional override)
	CreateModule bool   `yaml:"create_module,omitempty"` // Multi-module
	ModulePath   string `yaml:"module_path,omitempty"`   // Multi-module
}

GeneratorConfig defines a specific generator.

type HotReloadConfig

type HotReloadConfig struct {
	Enabled bool          `yaml:"enabled,omitempty"`
	Delay   time.Duration `yaml:"delay,omitempty"`
}

HotReloadConfig defines hot reload configuration.

type KubernetesConfig

type KubernetesConfig struct {
	Manifests string `yaml:"manifests,omitempty"`
	Namespace string `yaml:"namespace,omitempty"`
	Context   string `yaml:"context,omitempty"`
	Registry  string `yaml:"registry,omitempty"`
}

KubernetesConfig for Kubernetes deployment.

type Platform

type Platform struct {
	OS   string `yaml:"os"`
	Arch string `yaml:"arch"`
}

Platform defines target build platform.

type ProjectConfig

type ProjectConfig struct {
	Name        string           `yaml:"name"`
	Version     string           `yaml:"version,omitempty"`
	Description string           `yaml:"description,omitempty"`
	Type        string           `yaml:"type,omitempty"`      // Default: "monorepo"
	Layout      string           `yaml:"layout,omitempty"`    // Default: "single-module"
	Module      string           `yaml:"module,omitempty"`    // Required for single-module
	Workspace   WorkspaceConfig  `yaml:"workspace,omitempty"` // For multi-module layout
	Structure   *StructureConfig `yaml:"structure,omitempty"` // For single-module layout (optional, uses conventions)
}

ProjectConfig defines project metadata and structure.

func (*ProjectConfig) GetStructure

func (p *ProjectConfig) GetStructure() StructureConfig

GetStructure returns the project structure configuration with Go convention defaults.

type RenderConfig

type RenderConfig struct {
	BlueprintFile string `yaml:"blueprint_file,omitempty"`
	Region        string `yaml:"region,omitempty"`
	GitRepo       string `yaml:"git_repo,omitempty"`   // e.g., "myorg/myrepo"
	GitBranch     string `yaml:"git_branch,omitempty"` // e.g., "main"
}

RenderConfig for Render.com deployment.

type StructureConfig

type StructureConfig struct {
	Cmd         string `yaml:"cmd,omitempty"`         // Path to cmd/ (default: ./cmd)
	Apps        string `yaml:"apps,omitempty"`        // Path to apps/ (default: ./apps)
	Pkg         string `yaml:"pkg,omitempty"`         // Path to pkg/ (default: ./pkg)
	Internal    string `yaml:"internal,omitempty"`    // Path to internal/ (default: ./internal)
	Extensions  string `yaml:"extensions,omitempty"`  // Path to extensions/ (default: ./extensions)
	Database    string `yaml:"database,omitempty"`    // Path to database/ (default: ./database)
	Config      string `yaml:"config,omitempty"`      // Path to config/ (default: ./config)
	Deployments string `yaml:"deployments,omitempty"` // Path to deployments/ (default: ./deployments)
}

StructureConfig for single-module layout.

type TestConfig

type TestConfig struct {
	CoverageThreshold int           `yaml:"coverage_threshold,omitempty"`
	RaceDetector      bool          `yaml:"race_detector,omitempty"`
	Parallel          bool          `yaml:"parallel,omitempty"`
	Timeout           time.Duration `yaml:"timeout,omitempty"`
}

TestConfig defines testing configuration.

type ValidationError

type ValidationError struct {
	Field      string // The config field with the error
	Message    string // Human-readable error message
	Suggestion string // Suggested fix
	Level      string // "error" or "warning"
}

ValidationError represents a configuration validation error.

func (ValidationError) Error

func (v ValidationError) Error() string

Error implements the error interface.

type WatchConfig

type WatchConfig struct {
	Enabled bool     `yaml:"enabled,omitempty"`
	Paths   []string `yaml:"paths,omitempty"`
	Exclude []string `yaml:"exclude,omitempty"`
}

WatchConfig defines file watching configuration.

type WorkspaceConfig

type WorkspaceConfig struct {
	Enabled    bool   `yaml:"enabled,omitempty"`
	Apps       string `yaml:"apps,omitempty"`       // Glob pattern: "./apps/*"
	Services   string `yaml:"services,omitempty"`   // Glob pattern: "./services/*"
	Extensions string `yaml:"extensions,omitempty"` // Glob pattern: "./extensions/*"
	Pkg        string `yaml:"pkg,omitempty"`        // Path: "./pkg"
}

WorkspaceConfig for multi-module layout.

Jump to

Keyboard shortcuts

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