moduleconfig

package
v0.458.2 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EngineMySQL    = "mysql"
	EnginePostgres = "postgresql"
)

Variables

This section is empty.

Functions

func ToEngineType added in v0.458.0

func ToEngineType(engine string) (string, error)

ToEngineType validates and converts an engine type string to its internal representation

func ValidateSQLRoot added in v0.456.0

func ValidateSQLRoot(moduleDir, sqlDir string) (valid bool, databases map[string]DatabaseContent, err error)

ValidateSQLRoot validates that the SQL directory correctly structured. It returns true if the directory is valid, false otherwise. Structure is: <SQLRootDir>/<Engine>/<DatabaseName>/<Schema/Queries>

For example, `db/mysql/mydb/schema` where `db` is the SQLRootDir implies the following: Engine: mysql DatabaseName: mydb Schema/Queries: schema (contains migration files)

Types

type AbsModuleConfig

type AbsModuleConfig ModuleConfig

AbsModuleConfig is a ModuleConfig with all paths made absolute.

This is a type alias to prevent accidental use of the wrong type.

type CustomDefaults

type CustomDefaults struct {
	DeployDir    string
	Watch        []string
	BuildLock    optional.Option[string]
	Build        optional.Option[string]
	DevModeBuild optional.Option[string]

	// only the root keys in LanguageConfig are used to find missing values that can be defaulted
	LanguageConfig map[string]any `toml:"-"`

	// SQLRootDir is the root directory to look for SQL migrations and queries.
	SQLRootDir string
}

type DatabaseContent added in v0.456.0

type DatabaseContent struct {
	// Engine is the database engine,
	Engine string
	// QueriesDir is the path to the queries directory, relative to the module directory.
	QueriesDir optional.Option[string]
	// SchemaDir is the path to the schema directory, relative to the module directory.
	SchemaDir optional.Option[string]
}

type ModuleConfig

type ModuleConfig struct {
	// Dir is the absolute path to the root of the module.
	Dir string `toml:"-"`

	Language string `toml:"language"`
	Realm    string `toml:"realm"`
	Module   string `toml:"module"`
	// Build is the command to build the module.
	Build string `toml:"build"`
	// Build is the command to build the module in dev mode.
	DevModeBuild string `toml:"dev-mode-build"`
	// BuildLock is file lock path to prevent concurrent builds of a module.
	BuildLock string `toml:"build-lock"`
	// DeployDir is the directory to deploy from, relative to the module directory.
	DeployDir string `toml:"deploy-dir"`
	// Watch is the list of files to watch for changes.
	Watch []string `toml:"watch"`

	// LanguageConfig is a map of language specific configuration.
	// It is saved in the toml with the value of Language as the key.
	LanguageConfig map[string]any `toml:"-"`

	// SQLRootDir is the root directory for all SQL migrations and queries, relative to the module directory.
	// Beneath is is a hierarchy of directories whose structure provides information about the module's databases:
	// <SQLRootDir>/<Engine>/<DatabaseName>/<Schema/Queries>
	//
	// For example, `db/mysql/mydb/schema` where `db` is the SQLRootDir implies the following:
	// Engine: mysql
	// DatabaseName: mydb
	// Schema/Queries: schema (contains migration files)
	//
	// or `db/postgresql/mydb/queries`
	// Engine: postgresql
	// DatabaseName: mydb
	// Queries: queries (contains query files)
	SQLRootDir string `toml:"sql-root-dir"`
	// SQLDatabases is the list of databases beneath the SQLRootDir. Key is the database name, value is the database content
	// (engine, queries directory path, schema directory path).
	SQLDatabases map[string]DatabaseContent `toml:"-"`
}

ModuleConfig is the configuration for an FTL module.

Module config files are currently TOML.

func (ModuleConfig) Abs

func (c ModuleConfig) Abs() AbsModuleConfig

Abs creates a clone of ModuleConfig with all paths made absolute.

This function will panic if any paths are not beneath the module directory. This should never happen under normal use, as LoadModuleConfig performs this validation separately. This is just a sanity check.

func (ModuleConfig) String

func (c ModuleConfig) String() string

func (*ModuleConfig) UnmarshalTOML

func (c *ModuleConfig) UnmarshalTOML(data []byte) error

type UnvalidatedModuleConfig

type UnvalidatedModuleConfig ModuleConfig

UnvalidatedModuleConfig is a ModuleConfig that holds only the values read from the toml file.

It has not had it's defaults set or been validated, so values may be empty or invalid. Use FillDefaultsAndValidate() to get a ModuleConfig.

func LoadConfig

func LoadConfig(dir string) (UnvalidatedModuleConfig, error)

LoadConfig from a directory. This returns only the values found in the toml file. To get the full config with defaults and validation, use FillDefaultsAndValidate.

func (UnvalidatedModuleConfig) FillDefaultsAndValidate

func (c UnvalidatedModuleConfig) FillDefaultsAndValidate(customDefaults CustomDefaults) (ModuleConfig, error)

FillDefaultsAndValidate sets values for empty fields and validates the config. It involves standard defaults for Real and Errors fields, and also looks at CustomDefaults for defaulting other fields.

Jump to

Keyboard shortcuts

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