initialize

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2024 License: MIT Imports: 20 Imported by: 2

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{
		BasicConfig: BasicConfig{Module: "tiga-app", Env: DEVELOPMENT, ConfUrl: "./config.toml"},
		confMap:     map[string]interface{}{},
		RWMutex:     sync.RWMutex{},
	}
)

约定大于配置

Functions

func GetConfig

func GetConfig[T any]() *T

func Parse

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 `flag:"name:mod;short:m;default:;usage:模块名" env:"name:MODULE"`
	// environment
	Env string `flag:"name:env;short:e;default:dev;usage:环境" env:"name:ENV"`
	// 配置文件路径
	ConfUrl string `` /* 130-byte string literal not displayed */
	// 代理, socks5://localhost:1080
	Proxy string `flag:"name:proxy;short:p;default:'socks5://localhost:1080';usage:代理" env:"HTTP_PROXY"`
}

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 interface {
	Close()
}

type DaoFieldCloserWithError

type DaoFieldCloserWithError = io.Closer

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 EnvTagSettings

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

example

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

type FileConfig

type FileConfig struct {
	// 模块名
	Module          string `flag:"name:mod;short:m;default:;usage:模块名" env:"name:MODULE"`
	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 FlagTagSettings

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
}

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