config

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConfigFuncs map[string]ConfigFunc

Functions

func Add

func Add(name string, configFn ConfigFunc)

Add 新增配置项

func Env

func Env(envName string, defaultValue ...interface{}) interface{}

Env 读取环境变量,支持默认值 优先级:os.Getenv > viper(.env 文件 + APPENV_ 前缀环境变量) > 默认值

func Get

func Get(path string, defaultValue ...interface{}) string

Get 获取配置项 第一个参数 path 允许使用点式获取,如:app.name 第二个参数允许传参默认值

func GetAny added in v0.1.0

func GetAny(path string, defaultValue ...interface{}) any

GetAny 获取原始类型的配置项,用于嵌套结构(map、slice 等)。

func GetBool

func GetBool(path string, defaultValue ...interface{}) bool

GetBool 获取 Bool 类型的配置信息

func GetFloat64

func GetFloat64(path string, defaultValue ...interface{}) float64

GetFloat64 获取 float64 类型的配置信息

func GetInt

func GetInt(path string, defaultValue ...interface{}) int

GetInt 获取 Int 类型的配置信息

func GetInt64

func GetInt64(path string, defaultValue ...interface{}) int64

GetInt64 获取 Int64 类型的配置信息

func GetString

func GetString(path string, defaultValue ...interface{}) string

GetString 获取 String 类型的配置信息

func GetUint

func GetUint(path string, defaultValue ...interface{}) uint

GetUint 获取 Uint 类型的配置信息

func IsNacosEnabled added in v0.1.0

func IsNacosEnabled() bool

IsNacosEnabled 返回是否启用了 Nacos 配置中心

func NacosClient added in v0.1.0

func NacosClient() config_client.IConfigClient

NacosClient 返回 Nacos 配置客户端实例,未启用时返回 nil

func SetupConfig

func SetupConfig(env string) (err error)

SetupConfig 初始化配置信息,完成对环境变量以及 config 信息的加载

Types

type ConfigFunc

type ConfigFunc func() map[string]interface{}

Jump to

Keyboard shortcuts

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