Documentation
¶
Overview ¶
Package load provides functions to load a protobuf message from different formats:
- generated fomats: json, bin, txt
- origin formats: xlsx, csv, xml, yaml.
Index ¶
- func Load(msg proto.Message, dir string, fmt format.Format, options ...Option) error
- type LoadMode
- type Option
- func IgnoreUnknownFields() Option
- func LocationName(name string) Option
- func Mode(mode LoadMode) Option
- func PatchDirs(dirs ...string) Option
- func PatchPaths(paths map[string][]string) Option
- func Paths(paths map[string]string) Option
- func SubdirRewrites(subdirRewrites map[string]string) Option
- func WithReadFunc(readFunc ReadFunc) Option
- type Options
- type ReadFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Option ¶ added in v0.9.16
type Option func(*Options)
Option is the functional option type.
func IgnoreUnknownFields ¶ added in v0.10.6
func IgnoreUnknownFields() Option
IgnoreUnknownFields ignores unknown JSON fields during parsing.
func LocationName ¶ added in v0.10.5
LocationName sets TZ location name for parsing datetime format.
func Mode ¶ added in v0.12.0
Mode specifies the loading mode for config patching.
NOTE: only JSON, Bin, and Text formats are supported.
func PatchPaths ¶ added in v0.11.0
PatchPaths maps each messager name to one or multiple corresponding patch file paths. If specified, then main messager will be patched.
NOTE: only JSON, Bin, and Text formats are supported.
func Paths ¶ added in v0.11.0
Paths maps each messager name to a corresponding config file path. If specified, then the main messager will be parsed from the file directly, other than the specified load dir.
NOTE: only JSON, Bin, and Text formats are supported.
func SubdirRewrites ¶ added in v0.9.16
SubdirRewrites rewrites subdir paths (relative to workbook name option in .proto file).
func WithReadFunc ¶ added in v0.12.0
ReadFunc reads the config file and returns its content.
type Options ¶ added in v0.9.16
type Options struct {
// ReadFunc reads the config file and returns its content.
//
// Default: os.ReadFile.
ReadFunc ReadFunc
// 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.
//
// Default: "Local".
LocationName string
// IgnoreUnknownFields signifies whether to ignore unknown JSON fields
// during parsing.
//
// Default: false.
IgnoreUnknownFields bool
// SubdirRewrites rewrites subdir paths (relative to workbook name option
// in .proto file).
//
// Default: nil.
SubdirRewrites map[string]string
// Paths maps each messager name to a corresponding config file path.
// If specified, then the main messager will be parsed from the file
// directly, other than the specified load dir.
//
// NOTE: only JSON, Bin, and Text formats are supported.
//
// Default: nil.
Paths map[string]string
// PatchPaths maps each messager name to one or multiple corresponding patch file paths.
// If specified, then main messager will be patched.
//
// NOTE: only JSON, Bin, and Text formats are supported.
//
// Default: nil.
PatchPaths map[string][]string
// PatchDirs specifies the directory paths for config patching.
//
// Default: nil.
PatchDirs []string
// Mode specifies the loading mode for config patching.
//
// Default: ModeDefault.
Mode LoadMode
}
func ParseOptions ¶ added in v0.9.16
ParseOptions parses functional options and merge them to default Options.