Documentation
¶
Index ¶
- Variables
- func DefaultDirectoryTagFunc(dirs []string) []string
- 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) 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
- type ResolveValue
- type Row
- type RowConfig
- type Rows
- type Table
- type TableConfig
- type TaggedValueParser
- type TaggedValueParserFunc
- type TokenPosition
- type Value
- type ValueGenerated
- type ValueInternalID
- type ValueRefID
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func DefaultDirectoryTagFunc ¶
DefaultDirectoryTagFunc joins directories using a dot (.).
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) 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 d. 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.
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 WithLoadProgress ¶
func WithLoadProgress(progress func(filename string)) LoadOption
WithLoadProgress sets a callback to report load progress.
func WithLoadTaggedValueParser ¶
func WithLoadTaggedValueParser(parser TaggedValueParser) LoadOption
WithLoadTaggedValueParser 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 {
}
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.
type ResolveValue ¶
type ResolveValue interface {
// contains filtered or unexported methods
}
ResolveValue indicates a field value that must be resolved.
type Table ¶
type Table struct {
ID string
Config TableConfig
Rows Rows
}
func (*Table) AppendDeps ¶
AppendDeps adds table dependencies checking duplicates.
type TableConfig ¶
func (*TableConfig) Merge ¶
func (c *TableConfig) Merge(other *TableConfig) error
Merge checks if merging is allowed before merging.
type TaggedValueParser ¶
TaggedValueParser is used to parse YAML tag values.
func NewTaggedValueParserList ¶
func NewTaggedValueParserList(list map[string]TaggedValueParser) TaggedValueParser
NewTaggedValueParserList creates a TaggedValueParser from a list of named parsers
func ValueParserUUID ¶
func ValueParserUUID() TaggedValueParser
ValueParserUUID is a TaggedValueParser to parse "!uuid" tags to uuid.UUID.
type TaggedValueParserFunc ¶
TaggedValueParserFunc is a func adapter for TaggedValueParser
type TokenPosition ¶
type Value ¶
type Value interface {
// contains filtered or unexported methods
}
Value indicates a field value requires processing.
type ValueGenerated ¶
type ValueGenerated struct {
}
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 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.
