initialize

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2023 License: MIT Imports: 19 Imported by: 3

Documentation

Index

Constants

View Source
const (
	DEVELOPMENT = "dev"
	TEST        = "test"
	PRODUCT     = "prod"
	InitKey     = "initialize"
)
View Source
const (
	EntityField = "ENTITY"
	ConfigField = "CONFIG"
)

Variables

View Source
var (
	GlobalConfig = &globalConfig{
		Env: DEVELOPMENT, ConfUrl: "./config.toml",
		confMap: map[string]interface{}{},
	}
)

约定大于配置

Functions

func GetConfig

func GetConfig[T any]() *T

func Parse added in v1.1.0

func Parse(commandLine *pflag.FlagSet)

func ParseTagSetting

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

ParseTagSetting default sep ;

func Start

func Start(conf Config, dao Dao, notinit ...string) func(deferCalls ...func())

func Unmarshal deprecated

func Unmarshal(v reflect.Value) error

Deprecated: 使用独立的tag

Types

type BasicConfig

type BasicConfig struct {
	Module string
	// 代理, socks5://localhost:1080
	Proxy string `flag:"name:proxy;short:p;default:'socks5://localhost:1080';usage:代理"`
}

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

type CloseFunc

type CloseFunc func() error

type Config

type Config = NeedInit

type ConfigCenterConfig

type ConfigCenterConfig struct {
	NoInject []string
	conf_center.ConfigCenterConfig
}

ConfigCenterConfig zh:配置中心的配置 en:

type ConfigTagSettings

type ConfigTagSettings struct {
	Flag string
	Env  string
}

func ParseConfigTagSettings deprecated

func ParseConfigTagSettings(str string) *ConfigTagSettings

Deprecated: 使用独立的tag

type Dao

type Dao = NeedInit

type DaoConfig

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

TODO:泛型统一的Dao结构

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 = io.Closer

type DaoFieldCloser1

type DaoFieldCloser1 interface {
	Close()
}

type DaoTagSettings

type DaoTagSettings struct {
	NotInject  bool   `meta:"not_inject"`
	ConfigName string `meta:"config"`
}

func ParseDaoTagSettings

func ParseDaoTagSettings(str string) *DaoTagSettings

type Env

type Env string

type EnvConfig added in v1.1.0

type EnvConfig struct {
	Proxy string `env:"name:HTTP_PROXY"`
}

example

type EnvTagSettings added in v1.1.0

type EnvTagSettings struct {
	Name  string `meta:"name"`
	Usage string `meta:"usage"`
}

type FileConfig

type FileConfig struct {
	BasicConfig
	Dev, Test, Prod *ConfigCenterConfig
}

FileConfig 配置文件映射结构体,每个启动都有一个必要的配置文件,用于初始化基本配置及配置中心配置, ```toml Module = "user"

[dev] configType = "local" Watch = true NoInject = ["Apollo","Etcd", "Es"]

[dev.local] Debug = true ConfigPath = "local.toml" ReloadType = "fsnotify"

[dev.http] Interval = 100 Url = "http://localhost:6666/local.toml"

[dev.nacos] DataId = "pro" Group = "DEFAULT_GROUP"

[[dev.nacos.ServerConfigs]] Scheme = "http" IpAddr = "nacos" Port = 9000 GrpcPort = 10000

[dev.nacos.ClientConfig] NamespaceId = "" username = "nacos" password = "nacos" LogLevel = "debug" ```

type FlagConfig

type FlagConfig struct {
	// environment
	Env string `flag:"name:env;short:e;default:dev;usage:环境"`
	// 配置文件路径
	ConfUrl string `flag:"name:conf;short:c;default:config.toml;usage:配置文件路径,默认./config.toml或./config/config.toml"`
	// 是否监听配置文件
	Watch bool `flag:"name:watch;short:w;default:false;usage:是否监听配置文件"`
	// 代理, socks5://localhost:1080
	Proxy string `flag:"name:proxy;short:p;default:'socks5://localhost:1080';usage:代理"`
}

TODO: 优先级高于其他Config,覆盖环境变量及配置中心的配置 example

type FlagTagSettings added in v1.1.0

type FlagTagSettings struct {
	Name    string `meta:"name"`
	Short   string `meta:"short"`
	Default string `meta:"default"`
	Usage   string `meta:"usage"`
}

type Generate

type Generate interface {
	Generate() any
}

Deprecated

type NeedInit

type NeedInit interface {
	Init()
}

type NeedInitPlaceholder

type NeedInitPlaceholder struct {
}

Jump to

Keyboard shortcuts

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