load

package
v0.12.2 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2025 License: MIT Imports: 19 Imported by: 4

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Load

func Load(msg proto.Message, dir string, fmt format.Format, options ...Option) error

Load fills message from file in the specified directory and format.

Types

type LoadMode added in v0.12.0

type LoadMode int
const (
	ModeDefault   LoadMode = iota // Load all related files
	ModeOnlyMain                  // Only load the main file
	ModeOnlyPatch                 // Only load the patch files
)

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 PatchPaths added in v0.11.0

func PatchPaths(paths map[string][]string) Option

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

func Paths(paths map[string]string) Option

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

func SubdirRewrites(subdirRewrites map[string]string) Option

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

func WithReadFunc added in v0.12.0

func WithReadFunc(readFunc ReadFunc) Option

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

func ParseOptions(setters ...Option) *Options

ParseOptions parses functional options and merge them to default Options.

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