Documentation
¶
Index ¶
- Variables
- func AddDriver(driverName string, dial DialFunc)
- func NewTlsConfig(cnf *commontls.Tls) (*tls.Config, error)
- func UseEsClientOption(cnf *config.Elastic, opts ...commonoption.Option) []elastic.ClientOptionFunc
- func WithDnsOption(f func(cnf *config.Database, tls, pubKey bool) string) commonoption.Option
- func WithEsClientOption(f func(cfg *config.Elastic) []elastic.ClientOptionFunc) commonoption.Option
- func WithServerPubKeyOption(f func(cnf *commontls.ServerPubKey) (*rsa.PublicKey, error)) commonoption.Option
- func WithTlsOption(f func(cnf *commontls.Tls) (*tls.Config, error)) commonoption.Option
- type Adapter
- type ConditionCallback
- type DialFunc
- type EsDatabase
- type ScopesFunc
- type ServerPubKeyFunc
- type Sql
- type SqlDatabase
- type Stats
Constants ¶
This section is empty.
Variables ¶
View Source
var DefaultDnsFunc = func(cnf *config.Database, tls, serverPubKey bool) string { if cnf == nil { return "" } if cnf.DriverType == "mysql" { if cnf.Charset == "" { cnf.Charset = "utf8mb4" } dsn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=%s&parseTime=True&loc=Local", cnf.User, cnf.Pwd, cnf.Host, cnf.Port, cnf.Name, cnf.Charset) if tls { dsn += "&tls=" + url.QueryEscape(cnf.Tls.Key) } if serverPubKey { dsn += "&serverPubKey=" + url.QueryEscape(cnf.ServerPubKey.Key) } return dsn } else if cnf.DriverType == "postgres" { return fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s", cnf.Host, cnf.Port, cnf.User, cnf.Pwd, cnf.Name) } else if cnf.DriverType == "sqlite3" { return cnf.Name } else if cnf.DriverType == "sql" { return fmt.Sprintf("sqlserver://%s:%s@%s:%d?database=%s", cnf.User, cnf.Pwd, cnf.Host, cnf.Port, cnf.Name) } return "" }
Functions ¶
func UseEsClientOption ¶ added in v1.30.3
func UseEsClientOption(cnf *config.Elastic, opts ...commonoption.Option) []elastic.ClientOptionFunc
func WithDnsOption ¶ added in v1.9.15
func WithEsClientOption ¶ added in v1.30.3
func WithEsClientOption(f func(cfg *config.Elastic) []elastic.ClientOptionFunc) commonoption.Option
func WithServerPubKeyOption ¶ added in v1.9.15
func WithServerPubKeyOption(f func(cnf *commontls.ServerPubKey) (*rsa.PublicKey, error)) commonoption.Option
func WithTlsOption ¶ added in v1.9.15
Types ¶
type Adapter ¶
type Adapter struct {
// contains filtered or unexported fields
}
Adapter represents the Gorm adapter for policy storage.
func NewAdapter ¶
NewAdapter is the constructor for Adapter.
type ConditionCallback ¶
type EsDatabase ¶
type EsDatabase interface {
// Get return client,version,error
Get(name string) (*elastic.Client, string, error)
Do(name string, call func(es *elastic.Client, version string) error) error
Close(name string) error
CloseAll()
Select(name string)
GetSelector() string
}
func NewES ¶
func NewES(conf []config.Elastic, opts ...commonoption.Option) (EsDatabase, error)
type ServerPubKeyFunc ¶ added in v1.9.15
type ServerPubKeyFunc func(cnf *commontls.ServerPubKey) (*rsa.PublicKey, error)
func (ServerPubKeyFunc) String ¶ added in v1.9.15
func (t ServerPubKeyFunc) String() string
func (ServerPubKeyFunc) Type ¶ added in v1.9.15
func (t ServerPubKeyFunc) Type() int
func (ServerPubKeyFunc) Value ¶ added in v1.9.15
func (t ServerPubKeyFunc) Value() interface{}
type SqlDatabase ¶
type SqlDatabase interface {
Get(name string) (Sql, error)
Do(name string, c func(db Sql) error) error
Close(name string)
CloseAll()
Select(name string)
GetSelector() string
}
func NewDB ¶
func NewDB(cfgs []config.Sql, opts ...commonoption.Option) (SqlDatabase, error)
type Stats ¶ added in v1.26.6
type Stats struct {
MaxOpenConnections int `json:"maxOpenConnections"` //最大打开连接数
OpenConnections int `json:"openConnections"` // 连接数,The number of established connections both in use and idle.
InUse int `json:"inUse"` // 正在使用数,The number of connections currently in use.
Idle int `json:"idle"` // 当前空闲连接数
WaitCount int64 `json:"waitCount"` // The total number of connections waited for.
WaitDuration time.Duration `json:"waitDuration"` // The total time blocked waiting for a new connection.
MaxIdleClosed int64 `json:"maxIdleClosed"` // The total number of connections closed due to SetMaxIdleConns.
MaxIdleTimeClosed int64 `json:"maxIdleTimeClosed"` // The total number of connections closed due to SetConnMaxIdleTime.
MaxLifetimeClosed int64 `json:"maxLifetimeClosed"` // 连接被关闭的次数(因达到最大存活时间)The total number of connections closed due to SetConnMaxLifetime.
}
Click to show internal directories.
Click to hide internal directories.