confgen

package
v0.16.3 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: MIT Imports: 35 Imported by: 0

README

confgen — Configuration Generation

Converts workbook data (Excel/CSV/XML/YAML) into protobuf messages with concurrent parsing and a hierarchical error collector for multi-level error limiting.

Parsing Hierarchy

Generator
 ├── GenAll / GenWorkbook
 │    └── collector.NewGroup(ctx)                    ← concurrent workbook batch
 │         └── Group.Go(convert)                     ← one goroutine per proto file
 │
 └── convert(fd)                                     ← sequential per-sheet loop within one workbook
      ├── processScatter → ScatterAndExport
      │    ├── parseMessageFromOneImporter(main)      ← main importer: sequential
      │    └── collector.NewGroup(ctx)                ← concurrent scatter batch
      │         └── Group.Go(parseMessageFromOneImporter)
      │
      └── processMerger → MergeAndExport
           └── ParseMessage
                ├── single importer → parseMessageFromOneImporter   ← sequential
                └── multiple importers
                     └── collector.NewGroup(ctx)                    ← concurrent merge batch
                          └── Group.Go(parseMessageFromOneImporter)
parseMessageFromOneImporter (leaf)
parseMessageFromOneImporter(info, collector, impInfo)
 └── sheetCollector = collector.NewChild(maxErrorsPerSheet=5)
 └── sheetParser.Parse(protomsg, sheet)
      ├── [document sheet] → documentParser.Parse
      │    └── parseMessage(node)                    ← recursive tree walk
      │         └── messageCollector = sheetCollector.NewChild(maxErrorsPerMessage=3)
      │
      └── [table sheet]    → tableParser.Parse
           └── tableParser.parse
                └── RangeDataRows(row callback)
                     └── parseMessage(row)           ← per row
                          └── messageCollector = sheetCollector.NewChild(maxErrorsPerMessage=3)

Concurrent Model

flowchart TB
    subgraph Generator
        C["gen.collector (maxParseErrors=20)"]
    end

    subgraph "Workbook Group (concurrent)"
        direction TB
        G1["goroutine: convert(fd₁)"]
        G2["goroutine: convert(fd₂)"]
        Gn["goroutine: convert(fdₙ)"]
    end

    Generator --> G1 & G2 & Gn

    subgraph "convert(fd) — sequential sheet loop"
        B["bookCollector = gen.collector.NewChild(maxErrorsPerBook=10)"]
        S1["sheet₁: processScatter → ScatterAndExport"]
        S2["sheet₂: processMerger → MergeAndExport"]
    end

    G1 --> B --> S1 --> S2

    subgraph "parseMessageFromOneImporter"
        SC["sheetCollector = bookCollector.NewChild(maxErrorsPerSheet=5)"]
        TP["tableParser.parse → RangeDataRows"]
        DP["documentParser.Parse"]
    end

    S1 & S2 --> SC --> TP & DP
Level Collector Limit Scope
Generator gen.collector 20 across all concurrent workbooks
Book bookCollector = gen.collector.NewChild(10) 10 across sheets in one workbook
Sheet sheetCollector = bookCollector.NewChild(5) 5 across messages/rows in one sheet
Message messageCollector = sheetCollector.NewChild(3) 3 across fields in one message/row

Error Collector

Hierarchy

Errors are counted at field level. The Collector forms a tree via NewChild(maxErrs) — each level has its own cap. Collect() increments counters on self and all ancestors; when any level is full, further errors are dropped at that level. Join() recursively assembles the error tree.

flowchart TB
    subgraph "Generator"
        Root["gen.collector  (limit=20)"]
    end

    subgraph "convert(fd)"
        Book["bookCollector = gen.collector.NewChild(10)"]
    end

    subgraph "parseMessageFromOneImporter"
        Sheet["sheetCollector = bookCollector.NewChild(5)"]
    end

    subgraph "parseMessage (per row/node)"
        Message["messageCollector = sheetCollector.NewChild(3)"]
    end

    Root --> Book --> Sheet --> Message
    Message -- "Collect(err) → increments self + sheet + book + root" --> Root
    Sheet -- "IsFull() → fail-fast: skip remaining rows" --> Sheet
    Book -- "Join() → assembles all children errors" --> Book
Fail-fast Behavior
  • Message level: stops iterating fields when messageCollector.IsFull().
  • Sheet level: tableParser.parse checks sheetCollector.IsFull() before each row; returns early if full.
  • Book level: convert checks the error returned by bookCollector.Collect(); breaks the sheet loop if full.
  • Generator level: collector.NewGroup propagates the first fatal error (book-full) to stop the workbook goroutine.

Documentation

Index

Constants

View Source
const Version = "0.10.0"

Variables

This section is empty.

Functions

func NewExtendedSheetParser added in v0.11.0

func NewExtendedSheetParser(ctx context.Context, protoPackage, locationName string, bookOpts *tableaupb.WorkbookOptions, sheetOpts *tableaupb.WorksheetOptions, extInfo *SheetParserExtInfo) *sheetParser

NewExtendedSheetParser creates a new sheet parser with extended info.

func NewSheetExporter

func NewSheetExporter(outputDir string, output *options.ConfOutputOption, validator protovalidate.Validator, collector *xerrors.Collector) *sheetExporter

NewSheetExporter creates a new sheet exporter.

func NewSheetParser

func NewSheetParser(ctx context.Context, protoPackage, locationName string, opts *tableaupb.WorksheetOptions) *sheetParser

NewSheetParser creates a new sheet parser.

func NewValidator added in v0.16.3

func NewValidator(prFiles *protoregistry.Files) (protovalidate.Validator, error)

NewValidator creates a protovalidate validator whose extension type resolver is built from prFiles, so custom predefined rules can be recognized. It is shared by both the confgen (generate) and load (checker) paths to keep validation behavior consistent.

func ParseFileOptions added in v0.9.0

ParseFileOptions parse the options of a protobuf definition file.

func ParseMessage added in v0.10.5

func ParseMessage(info *SheetInfo, collector *xerrors.Collector, impInfos ...importer.ImporterInfo) (proto.Message, error)

ParseMessage parses multiple importer infos into one protomsg.

func ParseMessageOptions added in v0.9.0

ParseMessageOptions parse the options of a protobuf message.

func PrintPerfStats added in v0.10.0

func PrintPerfStats(gen *Generator)

func Validate added in v0.16.3

func Validate(msg proto.Message, validator protovalidate.Validator) error

Validate validates a proto message using the provided validator. Each violation is wrapped as an E2027 error and all violations are joined together.

Types

type Field

type Field struct {
	// contains filtered or unexported fields
}

type Generator

type Generator struct {
	ProtoPackage string // protobuf package name.
	InputDir     string // input dir of workbooks.
	OutputDir    string // output dir of generated files.

	LocationName string                    // TZ location name.
	InputOpt     *options.ConfInputOption  // Input settings.
	OutputOpt    *options.ConfOutputOption // output settings.

	// Performance stats
	PerfStats sync.Map
	// contains filtered or unexported fields
}

func NewGenerator

func NewGenerator(protoPackage, indir, outdir string, setters ...options.Option) *Generator

func NewGeneratorWithOptions added in v0.9.14

func NewGeneratorWithOptions(protoPackage, indir, outdir string, opts *options.Options) *Generator

func (*Generator) GenAll added in v0.10.0

func (gen *Generator) GenAll() error

func (*Generator) GenWorkbook added in v0.10.0

func (gen *Generator) GenWorkbook(bookSpecifiers ...string) error

bookSpecifier can be:

  • only workbook: excel/Item.xlsx
  • with worksheet: excel/Item.xlsx#Item (To be implemented)

func (*Generator) Generate

func (gen *Generator) Generate(bookSpecifiers ...string) (err error)

bookSpecifier can be:

  • only workbook: excel/Item.xlsx
  • specific worksheet: excel/Item.xlsx#Item (To be implemented)

type SheetInfo added in v0.10.7

type SheetInfo struct {
	ProtoPackage    string
	LocationName    string
	PrimaryBookName string
	MD              protoreflect.MessageDescriptor
	BookOpts        *tableaupb.WorkbookOptions
	SheetOpts       *tableaupb.WorksheetOptions

	ExtInfo *SheetParserExtInfo
}

func (*SheetInfo) BookName added in v0.15.0

func (si *SheetInfo) BookName() string

func (*SheetInfo) HasMerger added in v0.10.7

func (si *SheetInfo) HasMerger() bool

func (*SheetInfo) HasScatter added in v0.10.7

func (si *SheetInfo) HasScatter() bool

func (*SheetInfo) SheetName added in v0.15.0

func (si *SheetInfo) SheetName() string

type SheetParserExtInfo added in v0.11.0

type SheetParserExtInfo struct {
	InputDir       string
	SubdirRewrites map[string]string
	PRFiles        *protoregistry.Files
	BookFormat     format.Format // workbook format
	DryRun         options.DryRun
}

SheetParserExtInfo is the extended info for refer check and so on.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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