options

package
v0.17.2 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: MIT Imports: 2 Imported by: 2 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	// Default error collection limits, shared by protogen and confgen.
	DefaultMaxErrors         = 20
	DefaultMaxErrorsPerBook  = 10
	DefaultMaxErrorsPerSheet = 5
)
View Source
const (
	DefaultNameRow = 1 // Exact row number of column name definition at a worksheet.
	DefaultTypeRow = 2 // Exact row number of column type definition at a worksheet.
	DefaultNoteRow = 3 // Exact row number of column note definition at a worksheet.
	DefaultDataRow = 4 // Start row number of data at a worksheet.
)
View Source
const (
	DefaultSep    = ","
	DefaultSubsep = ":"
)
View Source
const (
	DefaultVersionPattern = "255.255.255"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ConfInputOption added in v0.10.6

type ConfInputOption struct {
	// The proto paths are used to search for dependencies that are referenced
	// in import statements in proto source files. If no import paths are
	// provided then "." (current directory) is assumed to be the only import
	// path.
	//
	// Default: nil.
	ProtoPaths []string `yaml:"protoPaths"`

	// The files to be parsed to generate configurations.
	//
	// NOTE:
	//  - By default, recognize "*.proto" pattern if not set.
	//  - Glob patterns are supported, which can specify sets of filenames with
	//    wildcard characters. Double asterisk (**) for recursive globbing is
	//    not supported.
	//
	// Default: nil.
	ProtoFiles []string `yaml:"protoFiles"`

	// The files not to be parsed to generate configurations.
	//
	// NOTE: Glob patterns are supported, which can specify sets of filenames
	// with wildcard characters. Double asterisk (**) for recursive globbing
	// is not supported.
	//
	// Default: nil.
	ExcludedProtoFiles []string `yaml:"excludedProtoFiles"`

	// Specify input file formats to be parsed.
	// Note: recognize all formats (Excel/CSV/XML/YAML) if not set (value is
	// nil).
	//
	// Default: nil.
	Formats []format.Format

	// Specify only these subdirs (relative to workbook name option in proto file).
	//
	// Default: nil.
	Subdirs []string

	// Specify rewrite subdir path (relative to workbook name option in proto file).
	//
	// Default: nil.
	SubdirRewrites map[string]string `yaml:"subdirRewrites"`

	// VersionPattern sets the default dotted-decimal pattern for tableau.Version
	// fields. Each component sets its maximum. A field-level pattern takes precedence.
	//
	// Default: "255.255.255".
	VersionPattern string `yaml:"versionPattern"`

	// Whether converter will not report an error and abort if a workbook
	// is not recognized in proto files.
	//
	// Default: false.
	IgnoreUnknownWorkbook bool `yaml:"-"`
}

Input options for generating conf files.

type ConfOption added in v0.10.6

type ConfOption struct {
	// Input options for generating conf files.
	Input *ConfInputOption `yaml:"input"`

	// Output options for generating conf files.
	Output *ConfOutputOption `yaml:"output"`
}

Options for generating conf files. Only for confgen.

type ConfOutputOption added in v0.10.6

type ConfOutputOption struct {
	// Specify subdir (relative to output dir) for generated configuration files.
	//
	// Default: "".
	Subdir string `yaml:"subdir"`

	// Specify generated conf file formats. If not set, it will generate all
	// formats (JSON/Text/Bin).
	//
	// Default: nil.
	Formats []format.Format

	// Specify generated conf file formats in messager level. This overrides
	// WorksheetOptions.output_formats (in .proto) and the Formats option.
	//
	// Default: nil.
	MessagerFormats map[string][]format.Format `yaml:"messagerFormats"`

	// Output pretty format of JSON and Text, with multiline and indent.
	//
	// Default: false.
	Pretty bool

	// EmitUnpopulated specifies whether to emit unpopulated fields. It does not
	// emit unpopulated oneof fields or unpopulated extension fields.
	// The JSON value emitted for unpopulated fields are as follows:
	//  ╔═══════╤════════════════════════════╗
	//  ║ JSON  │ Protobuf field             ║
	//  ╠═══════╪════════════════════════════╣
	//  ║ false │ proto3 boolean fields      ║
	//  ║ 0     │ proto3 numeric fields      ║
	//  ║ ""    │ proto3 string/bytes fields ║
	//  ║ null  │ proto2 scalar fields       ║
	//  ║ null  │ message fields             ║
	//  ║ []    │ list fields                ║
	//  ║ {}    │ map fields                 ║
	//  ╚═══════╧════════════════════════════╝
	//
	// NOTE: worksheet with FieldPresence set as true ignore this option.
	//
	// Refer: https://github.com/protocolbuffers/protobuf/blob/main/docs/field_presence.md
	//
	// Default: false.
	EmitUnpopulated bool `yaml:"emitUnpopulated"`

	// EmitTimezones specifies whether to emit timestamp in string format with
	// timezones (as indicated by an offset).
	//
	// Default: false.
	EmitTimezones bool `yaml:"emitTimezones"`

	// UseProtoNames uses proto field name instead of lowerCamelCase name
	// in JSON field names.
	UseProtoNames bool `yaml:"useProtoNames"`

	// UseEnumNumbers emits enum values as numbers.
	UseEnumNumbers bool `yaml:"useEnumNumbers"`

	// Specify dry run mode:
	//  - "patch": if sheet options are specified: Patch (PATCH_MERGE) and Scatter
	//
	// Default: "".
	DryRun DryRun `yaml:"dryRun"`
}

Output options for generating conf files.

type DryRun added in v0.11.0

type DryRun = string
const (
	DryRunPatch DryRun = "patch"
)

type ErrorLimitOption added in v0.17.0

type ErrorLimitOption struct {
	// Generator level: across concurrent workbooks.
	MaxErrors int `yaml:"maxErrors"`

	// Book level: across sheets in one workbook.
	MaxErrorsPerBook int `yaml:"maxErrorsPerBook"`

	// Sheet level: across messages/fields/blocks in one sheet.
	MaxErrorsPerSheet int `yaml:"maxErrorsPerSheet"`
}

ErrorLimitOption is the error collection limit configuration shared by protogen and confgen.

type FirstPassMode added in v0.14.0

type FirstPassMode = string
const (
	FirstPassModeDefault  FirstPassMode = ""         // parse based on specified config files.
	FirstPassModeNormal   FirstPassMode = "normal"   // parse based on all config files.
	FirstPassModeAdvanced FirstPassMode = "advanced" // parse based on all previous generated proto files
)

type HeaderOption

type HeaderOption struct {
	// Exact row number of column name definition at a worksheet.
	//
	// Default: 1.
	NameRow int32 `yaml:"namerow"`

	// Exact row number of column type definition at a worksheet.
	//
	// Default: 2.
	TypeRow int32 `yaml:"typerow"`

	// Exact row number of column note at a worksheet.
	//
	// Default: 3.
	NoteRow int32 `yaml:"noterow"`

	// Start row number of data at a worksheet.
	//
	// Default: 4.
	DataRow int32 `yaml:"datarow"`

	// The line number of column name definition in a cell.
	// Value 0 means the whole cell.
	//
	// Default: 0.
	NameLine int32 `yaml:"nameline"`

	// The line number of column type definition in a cell.
	// Value 0 means the whole cell.
	//
	// Default: 0.
	TypeLine int32 `yaml:"typeline"`

	// The line number of column note definition in a cell.
	// Value 0 means the whole cell.
	//
	// Default: 0.
	NoteLine int32 `yaml:"noteline"`

	// Separator for separating:
	//  - incell list elements (scalar or struct).
	//  - incell map items.
	//
	// Default: ",".
	Sep string

	// Subseparator for separating:
	//  - key-value pair of each incell map item.
	//  - struct fields of each incell struct list element.
	//
	// Default: ":".
	Subsep string
}

type Option

type Option func(*Options)

Option is the functional option type.

func Acronyms added in v0.12.0

func Acronyms(o map[string]string) Option

Acronyms configures your custom acronyms globally in protogen.

func Conf added in v0.10.6

func Conf(o *ConfOption) Option

Conf sets ConfOption.

func ErrorLimit added in v0.17.0

func ErrorLimit(o *ErrorLimitOption) Option

ErrorLimit sets the error collection limits shared by protogen and confgen.

func Lang added in v0.10.6

func Lang(o string) Option

Lang sets BCP 47 language tags: en, zh.

func LocationName

func LocationName(o string) Option

LocationName sets TZ location name for parsing datetime format.

func Log added in v0.10.0

func Log(o *log.Options) Option

Log sets log options.

func Proto added in v0.10.6

func Proto(o *ProtoOption) Option

Proto sets ProtoOption.

type Options

type Options struct {
	// locale BCP 47 language tags: en, zh.
	//
	// Default: "en".
	Lang string

	// Location represents the collection of time offsets in use in a geographical area.
	//  - If the name is "" or "UTC", LoadLocation returns UTC.
	//  - If the name is "Local", LoadLocation returns Local.
	//  - Otherwise, the name is taken to be a location name corresponding to a file in the
	//    IANA Time Zone database, such as "America/New_York", "Asia/Shanghai", and so on.
	//
	// See https://go.dev/src/time/zoneinfo_abbrs_windows.go.
	//
	// Default: "Local".
	LocationName string `yaml:"locationName"`

	// Profiling enables performance profiles and detailed runtime statistics.
	// It is a runtime option and is not serialized to configuration files.
	Profiling bool `yaml:"-"`

	// Configure your custom acronyms(regexp supported). Out of the box, "ID" -> "id" is auto configured.
	//
	// For example, if you configure K8s -> k8s, then the field name in PascalCase "InK8s"
	// will be converted to snake_case "in_k8s" but not "in_k_8_s".
	Acronyms map[string]string `yaml:"acronyms"`

	Log *log.Options // Log options.

	// Error limits for error collection at each level, shared by protogen and confgen.
	ErrorLimit *ErrorLimitOption `yaml:"errorLimit"`

	Proto *ProtoOption `yaml:"proto"` // Proto generation options.
	Conf  *ConfOption  `yaml:"conf"`  // Conf generation options.
}

Options is the wrapper of tableau params. Options follow the design of Functional Options (https://github.com/tmrts/go-patterns/blob/master/idiom/functional-options.md).

func NewDefault added in v0.9.7

func NewDefault() *Options

NewDefault returns a default Options.

func ParseOptions

func ParseOptions(setters ...Option) *Options

ParseOptions parses functional options and merge them to default Options.

type ProtoInputOption added in v0.10.6

type ProtoInputOption struct {
	// Header options of worksheet.
	Header *HeaderOption `yaml:"header"`

	// The proto paths are used to search for dependencies that are referenced in import
	// statements in proto source files. If no import paths are provided then
	// "." (current directory) is assumed to be the only import path.
	//
	// Default: nil.
	ProtoPaths []string `yaml:"protoPaths"`

	// The enums and messages in ProtoFiles can be used in Excel/CSV/XML/YAML
	// as common types.
	//
	// NOTE: Glob patterns are supported, which can specify sets
	// of filenames with wildcard characters.
	//
	// Default: nil.
	ProtoFiles []string `yaml:"protoFiles"`

	// Specify input file formats.
	// Note: recognize all formats (Excel/CSV/XML/YAML) if not set (value is
	// nil).
	//
	// Default: nil.
	Formats []format.Format `yaml:"formats"`

	// Specify only these subdirs (relative to input dir) to be processed.
	//
	// Default: nil.
	Subdirs []string `yaml:"subdirs"`

	// Specify rewrite subdir path (relative to input dir).
	//
	// Default: nil.
	SubdirRewrites map[string]string `yaml:"subdirRewrites"`

	// Follow the symbolic links when traversing directories recursively.
	// WARN: be careful to use this option, it may lead to infinite loop.
	//
	// Default: false.
	FollowSymlink bool `yaml:"followSymlink"`

	// Specify metasheet name. Metasheet is "@TABLEAU" if not set.
	// NOTE: metasheet name must start with '@'.
	//
	// Default: "".
	MetasheetName string `yaml:"metasheetName"`

	// Specify the first-pass mode to parse predefined types when generate
	// specified config files. Under the hood, the parsed predefined types will
	// be recognized and used in the second-pass.
	//
	// The first-pass mode can be:
	//
	//  - "": default mode, parse based on specified config files.
	//  - "normal": parse based on all config files.
	//  - "advanced": parse based on all previous generated proto files.
	//
	// Default: "".
	FirstPassMode FirstPassMode `yaml:"firstPassMode"`

	// Specify the name pattern for messager(regexp supported). If the generated
	// messager name does not match this pattern, an error will be reported.
	// Example: Conf$
	//
	// Default: "".
	MessagerPattern string `yaml:"messagerPattern"`
}

Input options for generating proto files.

type ProtoOption added in v0.10.6

type ProtoOption struct {
	// Input options for generating proto files.
	Input *ProtoInputOption `yaml:"input"`

	// Output options for generating proto files.
	Output *ProtoOutputOption `yaml:"output"`
}

Options for generating proto files. Only for protogen.

type ProtoOutputOption added in v0.10.6

type ProtoOutputOption struct {
	// Specify subdir (relative to output dir) for generated proto files.
	//
	// Default: "".
	Subdir string `yaml:"subdir"`

	// Dir separator `/` or `\`  in filename is replaced by "__".
	//
	// Default: false.
	FilenameWithSubdirPrefix bool `yaml:"filenameWithSubdirPrefix"`

	// Append suffix to each generated proto filename.
	//
	// Default: "".
	FilenameSuffix string `yaml:"filenameSuffix"`

	// Specify the generated protobuf file's edition.
	// See https://protobuf.dev/editions/overview/.
	//
	// Default: "".
	Edition string `yaml:"edition"`

	// Specify options (including features) at file level.
	// Examples: "go_package", "csharp_namespace", "features.(pb.go).strip_enum_prefix" etc.
	//
	// References
	//  - https://protobuf.dev/programming-guides/proto3/#options
	//  - https://protobuf.dev/editions/features/
	//
	// Default: nil.
	FileOptions map[string]string `yaml:"fileOptions"`

	// EnumValueWithPrefix specifies whether to prepend prefix
	// "UPPER_SNAKE_CASE of EnumType" to each enum value name.
	//
	// If set, the enum value name is prepended with "ENUM_TYPE_". For example:
	// enum ItemType has a value "EQUIP", then converted to "ITEM_TYPE_EQUIP".
	// If the enum value name is already prefixed with "ENUM_TYPE_", then it will
	// not be prefixed again.
	//
	// Default: false.
	EnumValueWithPrefix bool `yaml:"enumValueWithPrefix"`

	// In Protocol Buffers (Protobuf), to guarantee both backward and forward
	// compatibility, field numbers must be preserved because they are used as
	// unique identifiers in the binary wire format. Changing a field number
	// breaks backward compatibility with any existing data that uses the old
	// numbering. Compared with the old generated proto message, if a new field
	// name occurs, then assign the max field number plus 1 in the same level.
	//
	// Default: false.
	PreserveFieldNumbers bool `yaml:"preserveFieldNumbers"`
}

Output options for generating proto files.

Jump to

Keyboard shortcuts

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