datasources

package
v0.0.0-...-48e7155 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetDataSourceConstructor

func GetDataSourceConstructor(name string) func() DataSource

GetDataSourceConstructor 获取数据源构造函数

func SetDataSourceConstructor

func SetDataSourceConstructor(name string, fn func() DataSource)

SetDataSourceConstructor 设置数据源构造函数

Types

type DataSource

type DataSource interface {
	GetDataSource(name string) (interface{}, error)
	SetConfigs(configs map[string]DataSourceConfig) error
	Close() error
}

func NewElasticSearchDataSource

func NewElasticSearchDataSource() DataSource

func NewMysqlDataSource

func NewMysqlDataSource() DataSource

type DataSourceBase

type DataSourceBase struct {
	// contains filtered or unexported fields
}

DataSourceBase 数据源基础类型

func NewDataSourceBase

func NewDataSourceBase(newConnFunc func(config DataSourceConfig) (interface{}, error),
	closeConnFunc func(conn interface{}) error) *DataSourceBase

func (*DataSourceBase) Close

func (d *DataSourceBase) Close() error

Close 关闭当前数据源的所有连接

func (*DataSourceBase) GetDataSource

func (d *DataSourceBase) GetDataSource(name string) (interface{}, error)

GetDataSource 获取数据源,如果数据源不存在根据 config 创建

func (*DataSourceBase) SetConfigs

func (d *DataSourceBase) SetConfigs(configs map[string]DataSourceConfig) error

SetConfigs 设置配置,如果配置变更或已删除,则关闭对应数据源

type DataSourceConfig

type DataSourceConfig struct {
	Name     string `json:"name" yaml:"name"`                             // 连接名称 唯一
	Type     string `json:"type" yaml:"type"`                             // 配置类型 mysql es
	Host     string `json:"host" yaml:"host"`                             // ip
	Port     int    `json:"port" yaml:"port"`                             // 端口
	Username string `json:"username,omitempty" yaml:"username,omitempty"` // 账户 可为空
	Password string `json:"password,omitempty" yaml:"password,omitempty"` // 密码 可为空
	Target   string `json:"target,omitempty" yaml:"target,omitempty"`     // type 为mysql时未目标库 es时为空
	Debug    bool   `json:"debug,omitempty" yaml:"debug,omitempty"`
}

type ElasticSearchDataSource

type ElasticSearchDataSource struct {
	*DataSourceBase
}

type MysqlDataSource

type MysqlDataSource struct {
	*DataSourceBase
}

Jump to

Keyboard shortcuts

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