Documentation
¶
Overview ¶
Package load provides functions to load a protobuf message from different formats:
- output formats: JSON, Bin, Text
- input formats: Excel, CSV, XML, YAML
Index ¶
- func LoadMessager(msg proto.Message, path string, fmt format.Format, opts *MessagerOptions) error
- func LoadMessagerInDir(msg proto.Message, dir string, fmt format.Format, opts *MessagerOptions) error
- func Unmarshal(content []byte, msg proto.Message, path string, fmt format.Format, ...) error
- type BaseOptions
- type LoadFunc
- type LoadMode
- type MessagerOptions
- func (o *MessagerOptions) GetIgnoreUnknownFields() bool
- func (o *MessagerOptions) GetLoadFunc() LoadFunc
- func (o *MessagerOptions) GetLocationName() string
- func (o *MessagerOptions) GetMode() LoadMode
- func (o *MessagerOptions) GetPatchDirs() []string
- func (o *MessagerOptions) GetPatchPaths() []string
- func (o *MessagerOptions) GetPath() string
- func (o *MessagerOptions) GetReadFunc() ReadFunc
- func (o *MessagerOptions) GetSubdirRewrites() map[string]string
- type Option
- func IgnoreUnknownFields() Option
- func LocationName(name string) Option
- func Mode(mode LoadMode) Option
- func PatchDirs(dirs ...string) Option
- func SubdirRewrites(subdirRewrites map[string]string) Option
- func WithLoadFunc(loadFunc LoadFunc) Option
- func WithMessagerOptions(options map[string]*MessagerOptions) Option
- func WithReadFunc(readFunc ReadFunc) Option
- type Options
- type ReadFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LoadMessager ¶ added in v0.14.0
LoadMessager is the default LoadFunc which loads the message's content based on the given path, format, and options.
NOTE: only output formats (JSON, Bin, Text) are supported.
func LoadMessagerInDir ¶ added in v0.14.0
func LoadMessagerInDir(msg proto.Message, dir string, fmt format.Format, opts *MessagerOptions) error
LoadMessagerInDir loads message's content in the given dir, based on format and messager options.
Types ¶
type BaseOptions ¶ added in v0.14.0
type BaseOptions struct {
// Location represents the collection of time offsets in use in
// a geographical area.
//
// NOTE: only input formats(Excel, CSV, XML, YAML) are supported.
//
// 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.
//
// NOTE: only JSON format is supported.
//
// Default: false.
IgnoreUnknownFields *bool
// PatchDirs specifies the directory paths for config patching.
//
// NOTE: only output formats (JSON, Bin, Text) are supported.
//
// Default: nil.
PatchDirs []string
// Mode specifies the loading mode for config patching.
//
// NOTE: only output formats (JSON, Bin, Text) are supported.
//
// Default: ModeAll.
Mode *LoadMode
// ReadFunc reads the config file and returns its content.
//
// Default: [os.ReadFile].
ReadFunc ReadFunc
// LoadFunc loads a messager's content.
//
// NOTE: only output formats (JSON, Bin, Text) are supported.
//
// Default: [LoadMessager].
LoadFunc LoadFunc
// SubdirRewrites rewrites subdir paths (relative to workbook name option
// in .proto file).
//
// NOTE: only input formats (Excel, CSV, XML, YAML) are supported.
//
// Default: nil.
SubdirRewrites map[string]string
}
BaseOptions is the common struct for both global-level and messager-level options.
type LoadFunc ¶ added in v0.14.0
LoadFunc defines a func which can load message's content based on the given path, format, and options.
NOTE: only output formats (JSON, Bin, Text) are supported.
type MessagerOptions ¶ added in v0.14.0
type MessagerOptions struct {
BaseOptions
// Path specifies messager's config file path.
// If specified, then the main messager will be parsed directly,
// other than the specified load dir.
//
// NOTE: only output formats(JSON, Bin, Text) are supported.
//
// Default: "".
Path string
// PatchPaths specifies one or multiple corresponding patch file paths.
// If specified, then main messager will be patched.
//
// NOTE: only output formats (JSON, Bin, Text) are supported.
//
// Default: nil.
PatchPaths []string
}
MessagerOptions is the options struct for a messager.
func (*MessagerOptions) GetIgnoreUnknownFields ¶ added in v0.14.3
func (o *MessagerOptions) GetIgnoreUnknownFields() bool
GetIgnoreUnknownFields returns whether to ignore unknown fields when loading JSON.
func (*MessagerOptions) GetLoadFunc ¶ added in v0.14.3
func (o *MessagerOptions) GetLoadFunc() LoadFunc
GetLoadFunc returns the load function.
func (*MessagerOptions) GetLocationName ¶ added in v0.14.3
func (o *MessagerOptions) GetLocationName() string
GetLocationName returns the location name.
func (*MessagerOptions) GetMode ¶ added in v0.14.3
func (o *MessagerOptions) GetMode() LoadMode
GetMode returns the loading mode.
func (*MessagerOptions) GetPatchDirs ¶ added in v0.14.3
func (o *MessagerOptions) GetPatchDirs() []string
GetPatchDirs returns the directory paths for config patching.
func (*MessagerOptions) GetPatchPaths ¶ added in v0.14.2
func (o *MessagerOptions) GetPatchPaths() []string
GetPatchPaths returns corresponding patch file paths.
func (*MessagerOptions) GetPath ¶ added in v0.14.2
func (o *MessagerOptions) GetPath() string
GetPath returns messager's config file path.
func (*MessagerOptions) GetReadFunc ¶ added in v0.14.3
func (o *MessagerOptions) GetReadFunc() ReadFunc
GetReadFunc returns the read function.
func (*MessagerOptions) GetSubdirRewrites ¶ added in v0.14.3
func (o *MessagerOptions) GetSubdirRewrites() map[string]string
GetSubdirRewrites returns the subdir path mapping.
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 SubdirRewrites ¶ added in v0.9.16
SubdirRewrites rewrites subdir paths (relative to workbook name option in .proto file).
func WithLoadFunc ¶ added in v0.14.0
WithLoadFunc sets a custom load func.
func WithMessagerOptions ¶ added in v0.14.0
func WithMessagerOptions(options map[string]*MessagerOptions) Option
WithMessagerOptions sets the messager options.
func WithReadFunc ¶ added in v0.12.0
WithReadFunc sets a custom read func.
type Options ¶ added in v0.9.16
type Options struct {
BaseOptions
// MessagerOptions maps each messager name to a MessageOptions.
// If specified, then the messager will be parsed with the given options
// directly.
//
// Default: empty.
MessagerOptions map[string]*MessagerOptions
}
Options is the options struct, which contains both global-level and messager-level options.
func ParseOptions ¶ added in v0.9.16
ParseOptions parses functional options and merge them to default Options.
func (*Options) ParseMessagerOptionsByName ¶ added in v0.14.2
func (o *Options) ParseMessagerOptionsByName(name string) *MessagerOptions
ParseMessagerOptionsByName parses messager options with both global-level and messager-level options taken into consideration.