load

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2024 License: MIT Imports: 20 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 FilterFunc added in v0.11.0

type FilterFunc func(name string) bool

FilterFunc filter in messagers if returned value is true.

NOTE: name is the protobuf message name, e.g.: "message ItemConf{...}".

type Option added in v0.9.16

type Option func(*Options)

Option is the functional option type.

func Filter added in v0.11.0

func Filter(filter FilterFunc) Option

Filter can only filter in certain specific messagers based on the condition that you provide.

NOTE: only used in https://github.com/tableauio/loader.

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

func PatchDir(dir string) Option

PatchDir specifies the directory path for config patching.

func PatchPaths added in v0.11.0

func PatchPaths(paths map[string]string) Option

PatchPaths maps each messager name to a corresponding patch file path. If specified, then main messager will 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).

type Options added in v0.9.16

type Options struct {
	// Filter can only filter in certain specific messagers based on the
	// condition that you provide.
	//
	// NOTE: only used in https://github.com/tableauio/loader.
	//
	// Default: nil.
	Filter FilterFunc

	// 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 a corresponding patch file path.
	// If specified, then main messager will patched.
	//
	// NOTE: only JSON, Bin, and Text formats are supported.
	//
	// Default: nil.
	PatchPaths map[string]string
	// PatchDir specifies the directory path for config patching.
	//
	// Default: "".
	PatchDir string
}

func ParseOptions added in v0.9.16

func ParseOptions(setters ...Option) *Options

ParseOptions parses functional options and merge them to default Options.

Jump to

Keyboard shortcuts

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