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) ExtractFilterValue(row Row, filter ExtractFilter) (any, 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) (add bool, name string, err error)) (map[string]Row, error)
- func (d *Data) ExtractTableRows(tableID string, f func(row Row) (bool, error)) (*Table, error)
- func (d *Data) ExtractTableRowsNamed(tableID string, f func(row Row) (bool, string, error)) (map[string]Row, error)
- func (d *Data) ExtractValue(row Row, filter string) (any, error)
- func (d *Data) ExtractValues(row Row, filters map[string]string) (map[string]any, 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)
- func (d *Data) WalkTableRows(tableID string, f func(row Row) bool)
- type DirConfig
- type DirConfigConfig
- type ExtractFilter
- type ExtractFilterMetadata
- type ExtractFilterParent
- type ExtractFilterRefID
- type ExtractFilterValue
- type ExtractFilterValueRef
- type FSFileProviderOption
- type FileConfig
- type FileInfo
- type FileProvider
- type FileProviderCallback
- type GenerateOption
- type IsGenerateOption
- type LoadOption
- type NamedResolveCallback
- type NamedResolveCallbackFunc
- type NamedValueCallback
- type ParentRowInfo
- type ParentRowInfoData
- type ParseError
- type ResolveCallback
- type ResolveContext
- type ResolveGenerate
- type ResolveIncludeTagsFunc
- type ResolveOption
- func WithNamedResolveCallback(callback NamedResolveCallback) ResolveOption
- func WithResolveProgress(progress func(tableID, databaseName, tableName string)) ResolveOption
- func WithResolveRowProgress(...) ResolveOption
- func WithResolveTags(tags []string) ResolveOption
- func WithResolveTagsFunc(f ResolveIncludeTagsFunc) ResolveOption
- func WithResolvedValueCalculator(f ValueCalculator) ResolveOption
- func WithResolvedValueParser(f ResolvedValueParser) ResolveOption
- func WithRowResolvedCallback(callback RowResolvedCallback) ResolveOption
- type ResolveValue
- type ResolvedValueParser
- type ResolvedValueParserFunc
- type Row
- type RowConfig
- type RowResolvedCallback
- type RowResolvedCallbackFunc
- type Rows
- type StringFileProviderOption
- type Table
- type TableConfig
- type TokenPosition
- type Value
- type ValueCalculated
- type ValueCalculator
- type ValueCallback
- type ValueCallbackFunc
- type ValueCallbackResolveContext
- type ValueGenerated
- type ValueImpl
- type ValueInternalID
- type ValueParser
- type ValueParserFunc
- type ValueRefID
- type ValueResolveContext
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) ExtractFilterValue ¶ added in v1.3.0
func (d *Data) ExtractFilterValue(row Row, filter ExtractFilter) (any, error)
ExtractFilterValue extracts a field value based on a ExtractFilter.
func (*Data) ExtractRows ¶
ExtractRows extract rows matched by the callback, returning a filtered Data instance.
func (*Data) ExtractRowsNamed ¶
func (d *Data) ExtractRowsNamed(f func(table *Table, row Row) (add bool, name string, err error)) (map[string]Row, error)
ExtractRowsNamed extract rows matched by the callback into a named map.
func (*Data) ExtractTableRows ¶ added in v1.3.0
ExtractTableRows extract rows matched by the callback.
func (*Data) ExtractTableRowsNamed ¶ added in v1.3.0
func (d *Data) ExtractTableRowsNamed(tableID string, f func(row Row) (bool, string, error)) (map[string]Row, error)
ExtractTableRowsNamed extract rows matched by the callback into a named map.
func (*Data) ExtractValue ¶ added in v1.3.0
ExtractValue extracts a field value based on a ExtractFilter.
func (*Data) ExtractValues ¶ added in v1.3.0
ExtractValues extracts field values based on a list of ExtractFilter.
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.
func (*Data) WalkRows ¶
WalkRows calls a callback for each row in each table. Return false in the callback to stop walking.
func (*Data) WalkTableData ¶
WalkTableData searches for a single row value in tables.
type DirConfig ¶ added in v1.1.3
type DirConfig struct {
Config DirConfigConfig `yaml:"config"`
}
type DirConfigConfig ¶ added in v1.1.3
type ExtractFilter ¶ added in v1.3.0
type ExtractFilter interface {
// contains filtered or unexported methods
}
ExtractFilter is the base interface for filters that extract data.
func ParseExtractFilters ¶ added in v1.3.0
func ParseExtractFilters(filters ...string) ([]ExtractFilter, error)
ParseExtractFilters parses a list of ExtractFilter filters.
type ExtractFilterMetadata ¶ added in v1.3.1
ExtractFilterMetadata has the format "metadata:<fieldname>[:defaultValue]"
type ExtractFilterParent ¶ added in v1.3.4
ExtractFilterParent has the format "parent<:level>:<fieldname>"
type ExtractFilterRefID ¶ added in v1.3.0
ExtractFilterRefID has the format "refid:<table>:<refid>:<fieldname>"
type ExtractFilterValue ¶ added in v1.3.0
ExtractFilterValue has the format "value:<fieldname>[:defaultValue]"
type ExtractFilterValueRef ¶ added in v1.3.0
type ExtractFilterValueRef struct {
SourceFieldName string
TableID string
TargetFieldName string
ReturnFieldName string
}
ExtractFilterValueRef has the format "valueref:<source_fieldname>:<table>:<target_fieldname>:<return_fieldname>"
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.
func WithSkipDirConfigFile ¶ added in v1.1.3
func WithSkipDirConfigFile() FSFileProviderOption
WithSkipDirConfigFile skips loading a "dbfconfig.yaml" per folder.
type FileConfig ¶ added in v1.1.2
type FileConfig struct {
Tags []string `yaml:"tags"`
}
FileConfig stores configs that are specific to a yaml file.
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. If a folder has a "dbfconfig.yaml" file, its settings will be applied to the entire folder.
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. If a folder has a "dbfconfig.yaml" file, its settings will be applied to the entire folder.
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 NamedResolveCallback ¶ added in v1.3.4
type NamedResolveCallback interface {
NamedResolveValue(ctx ValueCallbackResolveContext, name string) (resolvedValue any, addField bool, err error)
}
type NamedResolveCallbackFunc ¶ added in v1.3.4
type NamedResolveCallbackFunc func(ctx ValueResolveContext, name string) (resolvedValue any, addField bool, err error)
func (NamedResolveCallbackFunc) NamedResolveValue ¶ added in v1.3.4
func (r NamedResolveCallbackFunc) NamedResolveValue(ctx ValueCallbackResolveContext, name string) (resolvedValue any, addField bool, err error)
type NamedValueCallback ¶ added in v1.3.4
type NamedValueCallback struct {
Name string
}
NamedValueCallback is like ValueCallback but uses a global resolver callback.
type ParentRowInfo ¶ added in v1.3.4
type ParentRowInfo interface {
ParentLevel(level int) ParentRowInfoData
}
ParentRowInfo gets parent info from a level number.
type ParentRowInfoData ¶ added in v1.3.4
type ParentRowInfoData interface {
ParentSupported() bool
HasParent() bool
TableID() string
InternalID() uuid.UUID
}
ParentRowInfoData indicates if a parent exists and its information.
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
DatabaseName() 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 WithNamedResolveCallback ¶ added in v1.3.4
func WithNamedResolveCallback(callback NamedResolveCallback) ResolveOption
WithNamedResolveCallback sets a function to receive named resolve callbacks.
func WithResolveProgress ¶
func WithResolveProgress(progress func(tableID, databaseName, tableName string)) ResolveOption
WithResolveProgress sets a function to receive resolve progress.
func WithResolveRowProgress ¶
func WithResolveRowProgress(rowProgress func(tableID, databaseName, 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 WithResolvedValueCalculator ¶ added in v1.3.2
func WithResolvedValueCalculator(f ValueCalculator) ResolveOption
func WithResolvedValueParser ¶ added in v0.13.0
func WithResolvedValueParser(f ResolvedValueParser) ResolveOption
func WithRowResolvedCallback ¶ added in v1.3.0
func WithRowResolvedCallback(callback RowResolvedCallback) ResolveOption
WithRowResolvedCallback sets a function to receive all resolved rows.
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 Row ¶
type RowConfig ¶
type RowResolvedCallback ¶ added in v1.3.0
type RowResolvedCallback interface {
RowResolved(ctx ValueResolveContext) error
}
RowResolvedCallback is a callback called for every row fully resolved
type RowResolvedCallbackFunc ¶ added in v1.3.0
type RowResolvedCallbackFunc func(ctx ValueResolveContext) error
func (RowResolvedCallbackFunc) RowResolved ¶ added in v1.3.0
func (r RowResolvedCallbackFunc) RowResolved(ctx ValueResolveContext) error
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 {
DatabaseName string `yaml:"database_name"`
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 ValueCalculated ¶ added in v1.3.2
ValueCalculated is a Value that will be calculated by custom code.
type ValueCalculator ¶ added in v1.3.2
ValueCalculator is used to calculate a value.
type ValueCallback ¶ added in v1.2.2
type ValueCallback interface {
Value
GetValueCallback(ctx ValueCallbackResolveContext) (resolvedValue any, addField bool, err error)
}
ValueCallback sets a callback to return the value. Never change any of the passed parameters, they are to be used only for reading. This can only be set in code.
type ValueCallbackFunc ¶ added in v1.3.0
type ValueCallbackFunc func(ctx ValueCallbackResolveContext) (resolvedValue any, addField bool, err error)
ValueCallbackFunc is a functional implementation of ValueCallback
func (ValueCallbackFunc) GetValueCallback ¶ added in v1.3.0
func (v ValueCallbackFunc) GetValueCallback(ctx ValueCallbackResolveContext) (resolvedValue any, addField bool, err error)
type ValueCallbackResolveContext ¶ added in v1.3.0
type ValueGenerated ¶
type ValueGenerated struct {
Type string
}
ValueGenerated is a Value that will be generated in the future (possibly by a database).
type ValueImpl ¶ added in v1.3.0
type ValueImpl struct{}
ValueImpl is a helper to be able to implement Value outside the package.
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.
