initialize

package
v1.10.17 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2024 License: MIT Imports: 31 Imported by: 0

README

基于环境的配置

需要配置中心的配置

生成模板

配置中心模板最少配置

env = "dev"

[dev]
ConfigTemplateDir = "."

如果单纯想生成模板,可以不用基本配置,直接用--format ${配置格式} -e ${环境} -p ${模板路径} 启动

单配置文件

如果你的项目不需要分环境,那么不要env这个配置,不要 -e flag,直接在启动目录放一个config.xxx文件即可 或者可以手动指定-c ${配置文件}

生成模板

要为单配置文件生成模板--format ${配置格式} -p ${模板路径}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DaoFieldType = reflect.TypeOf((*DaoField)(nil)).Elem()
View Source
var EmbeddedPresetsType = reflect.TypeOf((*EmbeddedPresets)(nil)).Elem()

Functions

func GlobalConfig

func GlobalConfig() *globalConfig

func ParseTagSetting

func ParseTagSetting(str string, sep string, settings any)

ParseTagSetting default sep ;

func RegisterDeferFunc added in v1.2.1

func RegisterDeferFunc(deferf ...func())

func Start

func Start(conf Config, dao Dao, configCenter ...conf_center.ConfigCenter) func()

Types

type BuiltinConfig added in v1.4.0

type BuiltinConfig struct {
	Log log.Config
}

type Config

type Config interface {
	// 注入之前设置默认值
	InitBeforeInject
	// 注入之后初始化
	InitAfterInject
}

type Dao

type Dao interface {
	InitBeforeInject
	// 注入config后执行
	InitAfterInjectConfig
	// 注入dao后执行
	InitAfterInject
}

type DaoField

type DaoField interface {
	Config() any
	Set()
	io.Closer
}

type DaoFieldCloseE added in v1.10.0

type DaoFieldCloseE = io.Closer

TODO

type DaoFieldCloser

type DaoFieldCloser interface {
	Close()
}

type EmbeddedPresets

type EmbeddedPresets struct {
}

func (EmbeddedPresets) InitAfterInject

func (u EmbeddedPresets) InitAfterInject()

func (EmbeddedPresets) InitAfterInjectConfig

func (u EmbeddedPresets) InitAfterInjectConfig()

func (EmbeddedPresets) InitBeforeInject

func (u EmbeddedPresets) InitBeforeInject()

type Encoder added in v1.4.0

type Encoder interface {
	Encode(format string, v map[string]any) ([]byte, error)
}

type FileConfig

type FileConfig struct {
	// 模块名
	initconf.BasicConfig
	EnvConfig *initconf.EnvConfig // field name can be dev,test,prod ... and anything you like
}

FileConfig unused example 配置文件映射结构体,每个启动都有一个必要的配置文件,用于初始化基本配置及配置中心配置

type FlagTagSettings

type FlagTagSettings struct {
	Name    string `meta:"name"`
	Short   string `meta:"short"`
	Env     string `meta:"env" explain:"从环境变量读取"`
	Default string `meta:"default"`
	Usage   string `meta:"usage"`
}

type InitAfterInject

type InitAfterInject interface {
	InitAfterInject()
}

type InitAfterInjectConfig

type InitAfterInjectConfig interface {
	InitAfterInjectConfig()
}

type InitAfterInjectConfigWithInitConfig added in v1.4.0

type InitAfterInjectConfigWithInitConfig interface {
	InitAfterInjectConfigWithInitConfig(*initconf.InitConfig)
}

type InitAfterInjectWithInitConfig added in v1.4.0

type InitAfterInjectWithInitConfig interface {
	InitAfterInjectWithInitConfig(*initconf.InitConfig)
}

type InitBeforeInject

type InitBeforeInject interface {
	InitBeforeInject()
}

type InitBeforeInjectWithInitConfig added in v1.4.0

type InitBeforeInjectWithInitConfig interface {
	InitBeforeInjectWithInitConfig(*initconf.InitConfig)
}

type InitTagSettings

type InitTagSettings struct {
	ConfigName   string `meta:"config"`
	DefaultValue string `meta:"default"`
}

func ParseInitTagSettings

func ParseInitTagSettings(str string) *InitTagSettings

type Marshal

type Marshal = func(any) ([]byte, error)

type SingleFileConfig added in v1.2.5

type SingleFileConfig struct {
	initconf.BasicConfig
	initconf.EnvConfig
}

SingleFileConfig This is for illustrative purposes only and is not for practical use

type Unmarshal

type Unmarshal = func([]byte, any) error

Jump to

Keyboard shortcuts

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