config

package
v0.0.19 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2021 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	CfgType                = "yaml"
	CfgName                = "config"
	IsBlock                = true
	Domain                 = "golug"
	CatchSigpipe           = true
	Trace                  = false
	Port                   = 8080
	DebugPort              = 8088
	Home                   = filepath.Join(xerror.PanicStr(filepath.Abs(filepath.Dir(""))), "home")
	CfgPath                = ""
	Project                = "golug"
	Level                  = "debug"
	Mode                   = RunMode.Dev
	Signal       os.Signal = syscall.Signal(0)
	// RunEnvMode 项目运行模式
	RunMode = struct {
		Dev     string
		Test    string
		Stag    string
		Prod    string
		Release string
	}{Dev: "dev", Test: "test", Stag: "stag", Prod: "prod", Release: "release"}
)

默认的全局配置

Functions

func Decode

func Decode(name string, fn interface{}) (b bool)

Decode decode config

func DefaultFlags

func DefaultFlags() *pflag.FlagSet

func Init

func Init() (err error)

处理所有的配置,环境变量和flag 配置顺序, 默认值->环境变量->配置文件->flag->配置文件 配置文件中可以设置环境变量 flag可以指定配置文件位置 始化配置文件

func IsDev

func IsDev() bool

func IsProd

func IsProd() bool

func IsRelease

func IsRelease() bool

func IsStag

func IsStag() bool

func IsTest

func IsTest() bool

func Map

func Map(names ...string) map[string]interface{}

func On

func On(fn func(cfg *Config))

func Template

func Template(format string) string

func UnMarshal

func UnMarshal(path string) map[string]interface{}

UnMarshal UnMarshal config from file to map

Types

type Config

type Config struct {
	*viper.Viper
}

func GetCfg

func GetCfg() *Config

Jump to

Keyboard shortcuts

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