cfg

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MergeTypesMaps

func MergeTypesMaps(maps ...stringlist.StringMap) stringlist.StringMap

Merge merges all properties from an ancestor TypeMap.

func Version

func Version() string

Types

type Config

type Config struct {
	// Database connection
	DB DBInput `yaml:"db,omitempty"`
	// List of file sets
	Files FileInputMap `yaml:"files,omitempty"`
	// Format Defaults (e.g. go, openapi, swift).
	Formats Processes `yaml:"formats,omitempty"`
	// Map of all processes
	Processes Processes `yaml:"processes,omitempty"`
}

func Load

func Load(filename string, includeDefaults bool) (Config, error)

Load reads a config file from filename. If includeDefaults it will also load the defaults from the embedded config and merges.

func LoadYaml added in v0.1.0

func LoadYaml(source string) (Config, error)

func (Config) Merge

func (c Config) Merge(from Config) Config

Merge merges all properties from an ancestor Config.

type DBInput

type DBInput struct {
	// DB Connection string.
	// e.g. `host=localhost dbname=MyProject sslmode=disable`
	Connection string `yaml:"connection,omitempty"`
	// Regex for filtering the properties.
	// e.g. ".*\\.schema_migrations"
	Filter stringlist.Strings `yaml:"filter,omitempty"`
}

type Error

type Error string

func (Error) Error

func (e Error) Error() string

type FileHandler

type FileHandler func(string) error // Used for post generation processing

type FileInput

type FileInput struct {
	// Files to process, supports glob syntax https://golang.org/pkg/path/filepath/#Match
	Files stringlist.Strings
	// Optional regex for filtering the files.  The filename must not match any of the filter
	// expressions to be considered valid.
	Filter  stringlist.Strings   `yaml:"filter,omitempty"`
	Rewrite stringlist.StringMap `yaml:"rewrite,omitempty"` // Optional rules for rewriting file names
}

func (FileInput) IsEmpty

func (f FileInput) IsEmpty() bool

IsEmpty checks Files globs.

func (FileInput) Merge

func (f FileInput) Merge(from FileInput) FileInput

Merge merges all properties from an ancestor FileInput.

type FileInputMap

type FileInputMap map[string]FileInput

func (FileInputMap) Merge

func (ff FileInputMap) Merge(from FileInputMap) FileInputMap

Merge merges all properties from an ancestor FileInputMap.

type Maps

type Maps struct {
	Type     stringlist.StringMap `yaml:"type,omitempty"`     // Type maps (varchar -> string)
	Nullable stringlist.StringMap `yaml:"nullable,omitempty"` // Type maps for nullable types (varchar -> sql.NullString)
	Name     stringlist.StringMap `yaml:"name,omitempty"`     // Name maps (addr_l1 -> address_line_1)
	// special purpose case settings. Can be used in templates with "caseType" command.
	Case stringlist.StringMap `yaml:"case,omitempty"`
}

Maps are a set of lookups for mapping various attributes (type, name, case) for welds.

func (Maps) Merge

func (m Maps) Merge(from Maps) Maps

Merge merges all properties from an ancestor Maps.

type Output

type Output map[string]stringlist.StringMap

func (Output) All

func (o Output) All() stringlist.StringMap

All merges all the mapped TypeMaps into a single StringMap, useful for getting the list of all templates.

func (Output) Merge

func (o Output) Merge(from Output) Output

Merge merges all properties from an ancestor Output.

type ParamMap

type ParamMap map[string]any // Generic bucket of params passed to templates

func (ParamMap) GetWithDefault added in v0.1.1

func (pp ParamMap) GetWithDefault(name, def string) string

GetWithDefault returns a string param identified by `name`, otherwise returns the default.

func (ParamMap) HasString

func (pp ParamMap) HasString(name string) (string, bool)

HasString returns a string param identified by `name`, otherwise the second value (ok) is false.

func (ParamMap) Merge

func (pp ParamMap) Merge(from ParamMap) ParamMap

Merge merges all properties from an ancestor ParamMap.

type Process

type Process struct {
	// Used to make a bundle of processes, if populated all other attributes are ignored
	Processes stringlist.Strings `yaml:"processes,omitempty,flow"`
	// ID of the process (used for bundle processes), populated by Processes.Merge
	ID string `yaml:"-"`
	// Output format, used to get defaults for naming, mapping, post processor
	Format string `yaml:"format,omitempty"`
	// Default case function (e.g snake, pascal, camel, kebab)
	Case string `yaml:"case,omitempty"`
	// Used for mapping data from Input to Output
	Maps Maps `yaml:"maps,omitempty"`
	// List of post-processing commands for each file generated (commonly used to invoke formatters like goimports)
	Post stringlist.Strings2D `yaml:"post,omitempty,flow"`
	// Custom parameters that can be passed into each template
	Params ParamMap `yaml:"params,omitempty"`
	// List of files to use as input
	Files FileInput `yaml:"files,omitempty"`
	// Root directory for outputs
	RootDir string `yaml:"rootDir,omitempty"`
	// ID of shared resources used for file input
	Resources stringlist.Strings `yaml:"resources,omitempty,flow"`
	Output    `yaml:",inline"`
}

Process encapsulates all data for executing a weld.

func (Process) Merge

func (p Process) Merge(from Process) Process

Merge merges all properties from an ancestor Process.

type Processes

type Processes map[string]Process

func (Processes) ApplyFormat

func (pp Processes) ApplyFormat(formats Processes) Processes

ApplyFormat merges linked format into each process config.

func (Processes) Keys

func (pp Processes) Keys() stringlist.Strings

Keys is a simple helper that returns the list of keys in the processes map.

func (Processes) Merge

func (pp Processes) Merge(from Processes) Processes

Merge merges all properties from an ancestor Processes.

func (Processes) String

func (pp Processes) String() string

func (Processes) Target

func (pp Processes) Target(targets []string) ([]Process, error)

Target Converts a list of process names into final list of processes. Including de-referencing bundles.

Jump to

Keyboard shortcuts

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