configure

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2024 License: MIT Imports: 12 Imported by: 17

README

Getting Started with configure

Configuration file path

In the root of your executable
./farseer.yaml

Get Configuration

configure.GetString("Database.default")

Get child nodes

config := configure.GetSubNodes("Database")  // return map[string]string

Set default configuration

// When the Database.test node, is not set, the default configuration is used
configure.SetDefault("Database.test", "DataType=MySql,PoolMaxSize=50,PoolMinSize=1,ConnectionString=root:xxxx@123456@tcp(mysql:3306)/test?charset=utf8&parseTime=True&loc=Local")

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetBool

func GetBool(key string) bool

GetBool 获取配置

func GetFopsServer added in v0.12.0

func GetFopsServer() string

GetFopsServer 获取FOPS地址

func GetInt

func GetInt(key string) int

GetInt 获取配置

func GetInt64

func GetInt64(key string) int64

GetInt64 获取配置

func GetSlice

func GetSlice(key string) []string

GetSlice 获取数组

func GetSliceNodes added in v0.6.0

func GetSliceNodes(key string) []map[string]any

GetSliceNodes 获取数组节点

func GetString

func GetString(key string) string

GetString 获取配置

func GetStrings

func GetStrings(key string) []string

GetStrings 获取配置

func GetSubNodes

func GetSubNodes(key string) map[string]any

GetSubNodes 获取所有子节点

func InitConfig added in v0.8.0

func InitConfig()

InitConfig 初始化配置文件

func NewEnvConfig added in v0.4.0

func NewEnvConfig() *envConfig

func NewYamlConfig added in v0.4.0

func NewYamlConfig(configFile string) *yamlConfig

func ParseConfig

func ParseConfig[TConfig any](key string) TConfig

ParseConfig 将配置转换成对象

func ParseConfigs added in v0.6.0

func ParseConfigs[TConfig any](key string) []TConfig

ParseConfigs 将配置转换成数组对象

func ParseString added in v0.6.0

func ParseString[TConfig any](configString string) TConfig

ParseString 解析字符串,转成配置对象

func SetDefault

func SetDefault(key string, value any)

SetDefault 设置配置的默认值

Types

type IConfigProvider added in v0.4.0

type IConfigProvider interface {
	// LoadConfigure 加载配置
	LoadConfigure() error
	// Get 读取配置
	Get(key string) (any, bool)
	// GetSubNodes 获取所有子节点
	GetSubNodes(key string) (map[string]any, bool)
	// GetArray 读取切片
	GetArray(key string) ([]any, bool)
	// Name 提供者名称
	Name() string
}

Jump to

Keyboard shortcuts

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