load

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2026 License: MIT Imports: 20 Imported by: 4

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadMessager added in v0.14.0

func LoadMessager(msg proto.Message, path string, fmt format.Format, opts *MessagerOptions) error

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.

func Unmarshal added in v0.14.0

func Unmarshal(content []byte, msg proto.Message, path string, fmt format.Format, opts *MessagerOptions) error

Unmarshal unmarshals the message based on the given content, format, and options.

NOTE: only output formats (JSON, Bin, Text) are supported.

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

type LoadFunc func(msg proto.Message, path string, fmt format.Format, opts *MessagerOptions) error

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 = iota // 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: "".
	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

func LocationName(name string) Option

LocationName sets TZ location name for parsing datetime format.

func Mode added in v0.12.0

func Mode(mode LoadMode) Option

Mode specifies the loading mode for config patching.

NOTE: only JSON, Bin, and Text formats are supported.

func PatchDirs added in v0.12.0

func PatchDirs(dirs ...string) Option

PatchDirs specifies the directory paths for config patching.

func SubdirRewrites added in v0.9.16

func SubdirRewrites(subdirRewrites map[string]string) Option

SubdirRewrites rewrites subdir paths (relative to workbook name option in .proto file).

func WithLoadFunc added in v0.14.0

func WithLoadFunc(loadFunc LoadFunc) Option

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

func WithReadFunc(readFunc ReadFunc) Option

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

func ParseOptions(setters ...Option) *Options

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.

type ReadFunc added in v0.12.0

type ReadFunc func(name string) ([]byte, error)

ReadFunc reads the config file and returns its content.

Jump to

Keyboard shortcuts

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