initialize

package
v1.8.2 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: MIT Imports: 21 Imported by: 2

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()
View Source
var (
	GlobalConfig = &globalConfig{
		BasicConfig: BasicConfig{ConfUrl: "./config.toml"},
		EnvConfig:   EnvConfig{Debug: true},
		lock:        sync.RWMutex{},
	}
)

约定大于配置

Functions

func GenConfigTemplate added in v1.6.0

func GenConfigTemplate(format encoding.Format, config Config, dao Dao, dir string)

func GetConfig

func GetConfig[T any]() *T

func ParseTagSetting

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

ParseTagSetting default sep ;

func Start

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

Types

type BasicConfig

type BasicConfig struct {
	// 配置文件路径
	ConfUrl string `` /* 152-byte string literal not displayed */
	// 模块名
	Module string `flag:"name:mod;short:m;default:tiga-app;usage:模块名;env:MODULE" json:"module,omitempty"`
	// environment
	Env string `flag:"name:env;short:e;default:dev;usage:环境;env:ENV" json:"env,omitempty"`
}

BasicConfig zh: 基本配置,包含模块名

type CloseFunc

type CloseFunc func() error

type Config

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

type Dao

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

type DaoConfig

type DaoConfig[D any] interface {
	Build() (*D, CloseFunc)
}

type DaoEntity

type DaoEntity[C DaoConfig[D], D any] struct {
	Conf   C
	Client *D
	// contains filtered or unexported fields
}

func (*DaoEntity[C, D]) Close

func (d *DaoEntity[C, D]) Close() error

func (*DaoEntity[C, D]) Config

func (d *DaoEntity[C, D]) Config() any

func (*DaoEntity[C, D]) SetEntity

func (d *DaoEntity[C, D]) SetEntity()

type DaoField

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

type DaoFieldCloser

type DaoFieldCloser interface {
	Close()
}

type DaoFieldCloserWithError

type DaoFieldCloserWithError = io.Closer

TODO

type EmbeddedPresets added in v1.8.0

type EmbeddedPresets struct {
}

func (EmbeddedPresets) InitAfterInject added in v1.8.0

func (u EmbeddedPresets) InitAfterInject()

func (EmbeddedPresets) InitAfterInjectConfig added in v1.8.0

func (u EmbeddedPresets) InitAfterInjectConfig()

func (EmbeddedPresets) InitBeforeInject added in v1.8.0

func (u EmbeddedPresets) InitBeforeInject()

type EnvConfig added in v1.6.0

type EnvConfig struct {
	Debug             bool   `flag:"name:debug;short:d;default:debug;usage:是否测试;env:DEBUG" json:"debug" toml:"debug"`
	ConfigTemplateDir string `flag:"name:conf_tmpl_dir;short:t;usage:是否生成配置模板;env:CONFIG_TEMPLATE_DIR" json:"config_template_dir"`
	// 代理, socks5://localhost:1080
	Proxy    string `flag:"name:proxy;short:p;default:'socks5://localhost:1080';usage:代理;env:HTTP_PROXY" json:"proxy"`
	NoInject []string
	// config字段顺序不能变,ConfigCenter 保持在最后
	ConfigCenter conf_center.Config
}

type FileConfig

type FileConfig struct {
	// 模块名
	Module    string
	Env       string
	EnvConfig *EnvConfig
}

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 added in v1.6.0

type InitAfterInject interface {
	InitAfterInject()
}

type InitAfterInjectConfig added in v1.6.0

type InitAfterInjectConfig interface {
	InitAfterInjectConfig()
}

type InitBeforeInject added in v1.6.0

type InitBeforeInject interface {
	InitBeforeInject()
}

type InitTagSettings added in v1.7.0

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

func ParseInitTagSettings added in v1.7.0

func ParseInitTagSettings(str string) *InitTagSettings

type Marshal added in v1.7.0

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

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