xenv

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2023 License: MIT Imports: 9 Imported by: 17

Documentation

Index

Constants

View Source
const (
	AppEnv       = "APP_ENV"
	AppName      = "APP_NAME"
	AppVersion   = "APP_VERSION"
	TraceName    = "TRACE_NAME"
	ApolloUrl    = "APOLLO_URL"
	ApolloAppID  = "APOLLO_APPID"
	ApolloSecret = "APOLLO_ACCESS_KEY_SECRET"

	GrpcPort  = "GRPC_PORT"
	HttpPort  = "HTTP_PORT"
	PprofPort = "PPROF_PORT"
)

Variables

View Source
var (
	// ErrNotAStructPtr is returned if you pass something that is not a pointer to a
	// Struct to Parse.
	ErrNotAStructPtr = errors.New("env: expected a pointer to a Struct")
)

nolint: gochecknoglobals

Functions

func GetApolloCluster added in v0.0.4

func GetApolloCluster(cluster string) string

func GetApolloNamespace added in v0.0.4

func GetApolloNamespace(namespace string) string

func GetApolloSecret added in v0.0.4

func GetApolloSecret() string

func GetEnv

func GetEnv(envName string) string

func Init

func Init(userConf map[string]string)

Init 初始化环境配置 ENV > userConf > default

func IsDebug

func IsDebug(v string) bool

IsDebug 是否为debug模式

func IsDev added in v0.0.5

func IsDev() bool

func IsLocal added in v0.0.5

func IsLocal() bool

IsLocal 判断当前环境(环境主要用户切换配置,不可过度依赖)

func IsProd added in v0.0.5

func IsProd() bool

func IsTest added in v0.0.5

func IsTest() bool

func Parse added in v0.0.7

func Parse(v interface{}, opts ...Options) error

Parse parses a struct containing `env` tags and loads its values from environment variables.

func ParseWithFuncs added in v0.0.7

func ParseWithFuncs(v interface{}, funcMap map[reflect.Type]ParserFunc, opts ...Options) error

ParseWithFuncs is the same as `Parse` except it also allows the user to pass in custom parsers.

Types

type OnSetFn added in v0.0.7

type OnSetFn func(tag string, value interface{}, isDefault bool)

OnSetFn is a hook that can be run when a value is set.

type Options added in v0.0.7

type Options struct {
	// Environment keys and values that will be accessible for the service.
	Environment map[string]string

	// TagName specifies another tagname to use rather than the default env.
	TagName string

	// RequiredIfNoDef automatically sets all env as required if they do not declare 'envDefault'
	RequiredIfNoDef bool

	// OnSet allows to run a function when a value is set
	OnSet OnSetFn

	// Prefix define a prefix for each key
	Prefix string
	// contains filtered or unexported fields
}

Options for the parser.

type ParserFunc added in v0.0.7

type ParserFunc func(v string) (interface{}, error)

ParserFunc defines the signature of a function that can be used within `CustomParsers`.

Jump to

Keyboard shortcuts

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