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 Load(msg proto.Message, dir string, fmt format.Format, options ...Option) error
- 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
- 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) Optiondeprecated
- func Paths(paths map[string]string) Optiondeprecated
- 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: nil.
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.
func (*BaseOptions) GetIgnoreUnknownFields ¶ added in v0.14.0
func (o *BaseOptions) GetIgnoreUnknownFields() bool
GetIgnoreUnknownFields returns whether to ignore unknown fields when loading JSON.
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 LoadMode ¶ added in v0.12.0
type LoadMode int
const ( ModeAll LoadMode // Load all related files ModeOnlyMain // Only load the main file ModeOnlyPatch // Only load the patch files )
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: nil.
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 ParseMessagerOptionsFromOptions ¶ added in v0.14.0
func ParseMessagerOptionsFromOptions(o *Options, name string) *MessagerOptions
ParseMessagerOptionsFromOptions parses messager options with both global-level and messager-level options taken into consideration.
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
deprecated
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.
Deprecated: use WithMessagerOptions instead.
func Paths
deprecated
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.
Deprecated: use WithMessagerOptions instead.
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.