Documentation ¶
Index ¶
- Variables
- func DefaultDirectoryTagFunc(dirs []string) []string
- func DefaultParseResolvedValue(typ string, value any) (bool, any, error)
- func ResolveCheck(data *Data, options ...ResolveOption) error
- func ResolveCheckCallback(ctx ResolveContext, fields map[string]any) error
- func StripNumberPunctuationPrefixDirectoryTagFunc(dirs []string) []string
- type Data
- func Generate(fileProvider FileProvider, resolver ResolveCallback, options ...GenerateOption) (*Data, error)
- func GenerateDirectory(rootDir string, resolver ResolveCallback, options ...GenerateOption) (*Data, error)
- func GenerateFS(fs fs.FS, resolver ResolveCallback, options ...GenerateOption) (*Data, error)
- func Load(fileProvider FileProvider, options ...LoadOption) (*Data, error)
- func MergeData(list ...*Data) (*Data, error)
- func Resolve(data *Data, f ResolveCallback, options ...ResolveOption) (*Data, error)
- func (d *Data) Clone() (*Data, error)
- func (d *Data) ExtractRows(f func(table *Table, row Row) (bool, error)) (*Data, error)
- func (d *Data) ExtractRowsNamed(f func(table *Table, row Row) (bool, string, error)) (map[string]Row, error)
- func (d *Data) Merge(source *Data) error
- func (d *Data) WalkRows(f func(table *Table, row Row) bool)
- func (d *Data) WalkTableData(tableID string, f func(row Row) (bool, any, error)) (any, error)
- type FSFileProviderOption
- type FileInfo
- type FileProvider
- type FileProviderCallback
- type GenerateOption
- type IsGenerateOption
- type LoadOption
- type ParseError
- type ResolveCallback
- type ResolveContext
- type ResolveGenerate
- type ResolveIncludeTagsFunc
- type ResolveOption
- func WithResolveProgress(progress func(tableID, tableName string)) ResolveOption
- func WithResolveRowProgress(...) ResolveOption
- func WithResolveTags(tags []string) ResolveOption
- func WithResolveTagsFunc(f ResolveIncludeTagsFunc) ResolveOption
- func WithResolvedValueParser(f ResolvedValueParser) ResolveOption
- type ResolveValue
- type ResolvedValueParser
- type ResolvedValueParserFunc
- type Row
- type RowConfig
- type Rows
- type StringFileProviderOption
- type Table
- type TableConfig
- type TokenPosition
- type Value
- type ValueGenerated
- type ValueInternalID
- type ValueParser
- type ValueParserFunc
- type ValueRefID
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func DefaultDirectoryTagFunc ¶
DefaultDirectoryTagFunc joins directories using a dot (.).
func DefaultParseResolvedValue ¶ added in v0.13.0
func ResolveCheck ¶
func ResolveCheck(data *Data, options ...ResolveOption) error
ResolveCheck checks if all dependencies between rows are resolvable.
func ResolveCheckCallback ¶
func ResolveCheckCallback(ctx ResolveContext, fields map[string]any) error
ResolveCheckCallback is the callback for the ResolveCheck function.
func StripNumberPunctuationPrefixDirectoryTagFunc ¶ added in v0.10.2
StripNumberPunctuationPrefixDirectoryTagFunc strips number and punctuation prefixes from each dir (like "01-") and joins directories using a dot (.).
Types ¶
type Data ¶
Data stores the entire collection of parsed Table information.
func Generate ¶
func Generate(fileProvider FileProvider, resolver ResolveCallback, options ...GenerateOption) (*Data, error)
Generate loads files and calls a resolver callback to resolve the values, and returns the resolved data. It is a combination of Load and Resolve.
func GenerateDirectory ¶
func GenerateDirectory(rootDir string, resolver ResolveCallback, options ...GenerateOption) (*Data, error)
GenerateDirectory is a version of Generate that loads from a directory name.
func GenerateFS ¶
func GenerateFS(fs fs.FS, resolver ResolveCallback, options ...GenerateOption) (*Data, error)
GenerateFS is a version of Generate that loads from a fs.FS.
func Load ¶
func Load(fileProvider FileProvider, options ...LoadOption) (*Data, error)
Load loads the files from the fileProvider and returns the list of loaded tables. Rows dependencies are not resolved, use ResolveCheck to check for them.
func MergeData ¶ added in v0.9.2
MergeData merge a list of Data objects into a new instance. The data is deep-copied, the source Data instances are never modified in any way.
func Resolve ¶
func Resolve(data *Data, f ResolveCallback, options ...ResolveOption) (*Data, error)
Resolve calls a callback for each table row, taking table dependency in account, and returns the resolved data.
func (*Data) Clone ¶ added in v0.12.0
Clone creates a deep-copy of the source. The source Data is never modified.
func (*Data) ExtractRows ¶
ExtractRows extract rows matched by the callback.
func (*Data) ExtractRowsNamed ¶
func (d *Data) ExtractRowsNamed(f func(table *Table, row Row) (bool, string, error)) (map[string]Row, error)
ExtractRowsNamed extract rows matched by the callback into a named map.
func (*Data) Merge ¶ added in v0.9.2
Merge merges source into the current instance. A deep copy is done to ensure source is never modified.
type FSFileProviderOption ¶
type FSFileProviderOption interface { GenerateOption // contains filtered or unexported methods }
func WithDirectoryAsTag ¶
func WithDirectoryAsTag() FSFileProviderOption
WithDirectoryAsTag creates tags for each directory. Inner directories will be concatenated by a dot (.).
func WithDirectoryIncludeFunc ¶
func WithDirectoryIncludeFunc(include func(path string, entry os.DirEntry) bool) FSFileProviderOption
WithDirectoryIncludeFunc sets a callback to allow choosing files that will be read. Check entry os.DirEntry.IsDir to detect files or directories.
func WithDirectoryTagFunc ¶
func WithDirectoryTagFunc(tagFunc func(dirs []string) []string) FSFileProviderOption
WithDirectoryTagFunc allows returning custom tags for each directory entry.
type FileProvider ¶
type FileProvider interface {
Load(FileProviderCallback) error
}
FileProvider provides files and tags to Load. The order matters, so it should be deterministic.
func NewDirectoryFileProvider ¶
func NewDirectoryFileProvider(rootDir string, options ...FSFileProviderOption) FileProvider
NewDirectoryFileProvider creates a FileProvider that list files from a directory, sorted by name. Only files with the ".dbf.yaml" extension are returned. Returned file names are relative to the rootDir.
func NewFSFileProvider ¶
func NewFSFileProvider(fs fs.FS, options ...FSFileProviderOption) FileProvider
NewFSFileProvider creates a FileProvider that list files from a fs.FS, sorted by name. Only files with the ".dbf.yaml" extension are returned.
func NewStringFileProvider ¶ added in v0.12.0
func NewStringFileProvider(files []string, options ...StringFileProviderOption) FileProvider
NewStringFileProvider creates a FileProvider that simulates a file for each string field, in the array order.
type FileProviderCallback ¶
type GenerateOption ¶
type GenerateOption interface {
// contains filtered or unexported methods
}
func WithGenerateResolveCheck ¶
func WithGenerateResolveCheck(check bool) GenerateOption
WithGenerateResolveCheck sets whether to check the data using ResolveCheck. Default is false.
type IsGenerateOption ¶
type IsGenerateOption struct { }
type LoadOption ¶
type LoadOption interface { GenerateOption // contains filtered or unexported methods }
func WithLoadInitialData ¶ added in v0.12.0
func WithLoadInitialData(initialData *Data) LoadOption
WithLoadInitialData sets the initial data. Can be used to merge more items into an existing data. The instance WILL be modified, call Data.Clone if you want to load into a copy.
func WithLoadProgress ¶
func WithLoadProgress(progress func(filename string)) LoadOption
WithLoadProgress sets a callback to report load progress.
func WithLoadRowsSetIgnoreTags ¶ added in v0.12.1
func WithLoadRowsSetIgnoreTags(rowsSetIgnoreTags bool) LoadOption
WithLoadRowsSetIgnoreTags sets "IgnoreTags" on all rows loaded. This is mainly used in tests to be sure the rows will be included.
func WithLoadValueParser ¶ added in v0.15.0
func WithLoadValueParser(parser ValueParser) LoadOption
WithLoadValueParser adds a YAML tag value parser.
type ParseError ¶
type ParseError struct { ErrorMessage string Path string Position *TokenPosition }
func NewParseError ¶
func NewParseError(msg string, path string, position *TokenPosition) ParseError
func (ParseError) Error ¶
func (e ParseError) Error() string
type ResolveCallback ¶
type ResolveCallback func(ctx ResolveContext, fields map[string]any) error
type ResolveContext ¶
type ResolveContext interface { TableID() string TableName() string ResolveField(fieldName string, value any) }
ResolveContext is the context used to resolve values.
type ResolveGenerate ¶
type ResolveGenerate struct {
Type string
}
ResolveGenerate is a ResolveValue that indicates a value will be generated and must be returned.
type ResolveIncludeTagsFunc ¶
ResolveIncludeTagsFunc is the function signature for WithResolveTagsFunc
func DefaultResolveIncludeTagFunc ¶
func DefaultResolveIncludeTagFunc(tags []string) ResolveIncludeTagsFunc
DefaultResolveIncludeTagFunc returns a ResolveIncludeTagsFunc check checks if at least one tags is contained.
type ResolveOption ¶
type ResolveOption interface { GenerateOption // contains filtered or unexported methods }
func WithResolveProgress ¶
func WithResolveProgress(progress func(tableID, tableName string)) ResolveOption
WithResolveProgress sets a function to receive resolve progress.
func WithResolveRowProgress ¶
func WithResolveRowProgress(rowProgress func(tableID, tableName string, current, amount int, isIncluded bool)) ResolveOption
WithResolveRowProgress sets a function to receive resolve row progress.
func WithResolveTags ¶
func WithResolveTags(tags []string) ResolveOption
WithResolveTags set Resolve to only resolve rows that contains at least one of these tags. If nil or 0 length, no row filtering is performed.
func WithResolveTagsFunc ¶
func WithResolveTagsFunc(f ResolveIncludeTagsFunc) ResolveOption
WithResolveTagsFunc sets a row tag filter function.
func WithResolvedValueParser ¶ added in v0.13.0
func WithResolvedValueParser(f ResolvedValueParser) ResolveOption
type ResolveValue ¶
type ResolveValue interface {
// contains filtered or unexported methods
}
ResolveValue indicates a field value that must be resolved.
type ResolvedValueParser ¶ added in v0.13.0
ResolvedValueParser parses resolved value types, like generated fields.
type ResolvedValueParserFunc ¶ added in v0.15.0
ResolvedValueParserFunc is a func wrapper for ResolvedValueParser.
func (ResolvedValueParserFunc) ParseResolvedValue ¶ added in v0.15.0
type RowConfig ¶
type StringFileProviderOption ¶ added in v0.12.0
type StringFileProviderOption func(*stringFileProvider)
func WithStringFileProviderTags ¶ added in v0.12.0
func WithStringFileProviderTags(tags [][]string) StringFileProviderOption
WithStringFileProviderTags sets tags using the same array indexes as the files parameter.
type Table ¶
type Table struct { ID string Config TableConfig Rows Rows }
func (*Table) AppendDeps ¶
AppendDeps adds table dependencies checking duplicates.
type TableConfig ¶
type TableConfig struct { TableName string `yaml:"table_name"` Depends []string `yaml:"depends"` DefaultValues map[string]any `yaml:"default_values"` }
func (*TableConfig) Merge ¶
func (c *TableConfig) Merge(other *TableConfig) error
Merge checks if merging is allowed before merging.
type TokenPosition ¶
type Value ¶
type Value interface {
// contains filtered or unexported methods
}
Value indicates a field value requires processing.
type ValueGenerated ¶
type ValueGenerated struct {
Type string
}
ValueGenerated is a Value that will be generated in the future (possibly by a database).
type ValueInternalID ¶
ValueInternalID is a Value that references a field value in a table using the internal ID.
func (ValueInternalID) TableDepends ¶
func (v ValueInternalID) TableDepends() string
TableDepends indicates a dependency on another table.
type ValueParser ¶ added in v0.15.0
ValueParser is used to parse YAML tag values.
type ValueParserFunc ¶ added in v0.15.0
ValueParserFunc is a func adapter for ValueParser
func (ValueParserFunc) ParseValue ¶ added in v0.15.0
type ValueRefID ¶
ValueRefID is a Value that references a field value in a table using the RefID (string ID).
func (ValueRefID) TableDepends ¶
func (v ValueRefID) TableDepends() string
TableDepends indicates a dependency on another table.