config

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2021 License: MIT Imports: 9 Imported by: 0

README

config

golang viper 封装

特性:

  • 统一化viper实例化参数,完全兼容 文件读取,远程读取,传入配置文本内容
  • 全局默认参数设置

License:

config is under the MIT license. See the LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(option ...*Option) (v *viper.Viper, err error)

New returns a new configuration management object.

func SetConfigFile

func SetConfigFile(filename string)

SetConfigFile 设置配置文件路径

func SetConfigName

func SetConfigName(name string)

SetConfigName 设置配置名称

func SetConfigType

func SetConfigType(typ string)

SetConfigType 设置配置类型

func SetEnvFileKey

func SetEnvFileKey(val string)

SetEnvFileKey 设置配置文件的系统环境变量名

func SetEnvPrefix

func SetEnvPrefix(prefix string)

SetEnvPrefix 设置默认环境变量的前缀

func SetSearchPath

func SetSearchPath(paths []string)

SetSearchPath 设置配置文件检索目录

func SetWatchHandler

func SetWatchHandler(handler func(v *viper.Viper))

SetWatchHandler 设置默认配置变动后执行的操作

Types

type Option

type Option struct {
	// 提供者,file, content,etcd, consul, firestore
	Provider       string   `json:"provider" yaml:"provider"`
	Name           string   `json:"name" yaml:"name"`
	Type           string   `json:"type" yaml:"type"`
	File           string   `json:"file" yaml:"file"`
	SearchPath     []string `json:"searchPath" yaml:"searchPath"`
	Env            bool     `json:"env" yaml:"env"`
	EnvPrefix      string   `json:"envPrefix" yaml:"envPrefix"`
	EndPoint       string   `json:"endPoint" yaml:"endPoint"`
	SecretKey      string   `json:"secretKey" yaml:"secretKey"`
	Watch          bool     `json:"watch" yaml:"watch"`
	IsRemote       bool     `json:"isRemote" yaml:"isRemote"`
	RemoteProvider string   `json:"remoteProvider" yaml:"remoteProvider"`
	RemoteEndpoint string   `json:"remote_endpoint" yaml:"remote_endpoint"`
	WatchHandler   func(v *viper.Viper)
}

Jump to

Keyboard shortcuts

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