config

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// MarshalOptions is a configurable JSON format marshaller.
	MarshalOptions = protojson.MarshalOptions{
		UseProtoNames:     true,
		EmitUnpopulated:   true,
		EmitDefaultValues: true,
	}
	// UnmarshalOptions is a configurable JSON format parser.
	UnmarshalOptions = protojson.UnmarshalOptions{
		DiscardUnknown: true,
	}
)

Functions

func LoadConfig

func LoadConfig(dst interface{}, opts ...ConfigOption) error

LoadConfig 加载配置, 优先级为 flag > env > yaml

func LoadEnv

func LoadEnv(prefix string, v interface{}) error

LoadEnv 解析环境变量到结构体

func LoadFlag

func LoadFlag(flagSet *flag.FlagSet, args []string, conf interface{}) error

func LoadPFlag

func LoadPFlag(flagSet *pflag.FlagSet, args []string, conf interface{}) error

func LoadYaml

func LoadYaml(filepath string, conf interface{}) error

func Marshal

func Marshal(v interface{}) ([]byte, error)

func Unmarshal

func Unmarshal(data []byte, v interface{}) error

Types

type ConfigOption

type ConfigOption func(*ConfigOptions)

func WithEnv

func WithEnv(prefix string) ConfigOption

WithEnv 从环境变量加载配置

func WithFlag

func WithFlag(flagSet *flag.FlagSet, args []string) ConfigOption

WithFlag 从 flag 加载配置

func WithPFlag

func WithPFlag(pflagSet *pflag.FlagSet, args []string) ConfigOption

WithPFlag 从 pflag 加载配置

func WithYaml

func WithYaml(filepath string) ConfigOption

WithYaml 从 YAML 加载配置, 依赖 json flag , 需要定义正确的数据类型

type ConfigOptions

type ConfigOptions struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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