1 Star 0 Fork 0

h79/goutils

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
config.go 6.90 KB
一键复制 编辑 原始数据 按行查看 历史
huqiuyun 提交于 2023-03-07 00:32 . db maxlife time
package server
import (
"fmt"
"time"
)
type Redis struct {
Name string `json:"name" yaml:"name" xml:"name"` //redis名
Master RedisConfig `json:"master" yaml:"master" xml:"master"`
Cluster RedisConfig `json:"cluster" yaml:"cluster" xml:"cluster"`
Sentinel RedisConfig `json:"sentinel" yaml:"sentinel" xml:"sentinel"`
Logger RedisLogger `json:"logger" yaml:"logger" xml:"logger"`
}
type RedisConfig struct {
Host []string `json:"host" yaml:"host" xml:"host"` //ip:port
User string `json:"user" yaml:"user" xml:"user"`
Pwd string `json:"pwd" yaml:"pwd" xml:"pwd"`
DB int `json:"db" yaml:"db" xml:"db"`
PoolSize int `json:"poolSize" yaml:"poolSize" xml:"poolSize"`
MinIdleConns int `json:"minIdleConns" yaml:"minIdleConns" xml:"minIdleConns"`
MaxRetries int `json:"maxRetries" yaml:"maxRetries" xml:"maxRetries"`
DialTimeout time.Duration `json:"dialTimeout" yaml:"dialTimeout" xml:"dialTimeout"`
ReadTimeout time.Duration `json:"readTimeout" yaml:"readTimeout" xml:"readTimeout"`
WriteTimeout time.Duration `json:"writeTimeout" yaml:"writeTimeout" xml:"writeTimeout"`
IdleTimeout time.Duration `json:"idleTimeout" yaml:"idleTimeout" xml:"idleTimeout"`
MinRetryBackoff time.Duration `json:"MinRetryBackoff" yaml:"MinRetryBackoff" xml:"MinRetryBackoff"`
MaxRetryBackoff time.Duration `json:"MaxRetryBackoff" yaml:"MaxRetryBackoff" xml:"MaxRetryBackoff"`
MaxConnAge time.Duration `json:"MaxConnAge" yaml:"MaxConnAge" xml:"MaxConnAge"`
PoolTimeout time.Duration `json:"PoolTimeout" yaml:"PoolTimeout" xml:"PoolTimeout"`
IdleCheckFrequency time.Duration `json:"IdleCheckFrequency" yaml:"IdleCheckFrequency" xml:"IdleCheckFrequency"`
}
type RedisLogger struct {
LogLevel int `json:"level" yaml:"level" xml:"level"`
}
type Sql struct {
Name string `json:"name" yaml:"name" xml:"name"` //数据名(不是数据库名)
Master Database `json:"master" yaml:"master" xml:"master"`
Sources []Database `json:"sources" yaml:"sources" xml:"sources"`
Replicas []Database `json:"replicas" yaml:"replicas" xml:"replicas"`
MaxOpenConns int `json:"max_open_conns" yaml:"max_open_conns" xml:"max_open_conns"`
MaxIdleConns int `json:"max_idle_conns" yaml:"max_idle_conns" xml:"max_idle_conns"`
MaxIdleTime time.Duration `json:"max_idle_time" yaml:"max_idle_time" xml:"max_idle_time"`
MaxLifetime time.Duration `json:"max_life_time" yaml:"max_life_time" xml:"max_life_time"`
Logger SqlLogger `json:"logger" yaml:"logger" xml:"logger"`
}
type SqlLogger struct {
LogLevel int `json:"level" yaml:"level" xml:"level"`
SlowThreshold time.Duration `json:"slowThreshold" yaml:"slowThreshold" xml:"slowThreshold"`
IgnoreRecordNotFoundError bool `json:"ignoreRecordNotFoundError" yaml:"ignoreRecordNotFoundError" xml:"ignoreRecordNotFoundError"`
AlarmEnabled bool `json:"alarmEnabled" yaml:"alarmEnabled" xml:"alarmEnabled"`
}
type Database struct {
Host string `json:"host" yaml:"host" xml:"host"`
Port int `json:"port" yaml:"port" xml:"port"`
User string `json:"user" yaml:"user" xml:"user"`
Pwd string `json:"pwd" yaml:"pwd" xml:"pwd"`
DriverType string `json:"type" yaml:"type" xml:"type"` //mysql, sqlite
Name string `json:"name" yaml:"name" xml:"name"` //数据库名
}
func (d Database) GetDataSourceName() string {
if d.DriverType == "mysql" {
return fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8&parseTime=True&loc=Local",
d.User, d.Pwd, d.Host, d.Port, d.Name)
} else if d.DriverType == "postgres" {
return fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s",
d.Host, d.Port, d.User, d.Pwd, d.Name)
} else if d.DriverType == "sqlite3" {
return d.Name
} else if d.DriverType == "sql" {
return fmt.Sprintf("sqlserver://%s:%s@%s:%d?database=%s",
d.User, d.Pwd, d.Host, d.Port, d.Name)
}
return ""
}
type Elastic struct {
Name string `json:"name" yaml:"name" xml:"name"` //数据名(不是数据库名)
Host []string `json:"hosts" yaml:"hosts" xml:"hosts"` //机群
User string `json:"user" yaml:"user" xml:"user"`
Pwd string `json:"pwd" yaml:"pwd" xml:"pwd"`
Sniff bool `json:"sniff" yaml:"sniff" xml:"sniff"`
Interval time.Duration `json:"interval" yaml:"interval" xml:"interval"`
XPackSecurityUser string `json:"XPackSecurityUser" yaml:"XPackSecurityUser" xml:"XPackSecurityUser"`
Logger EsLogger `json:"logger" yaml:"logger" xml:"logger"`
}
type EsLogger struct {
LogLevel int `json:"level" yaml:"level" xml:"level"`
}
type MqClient struct {
GroupID string `json:"groupId" yaml:"groupId" xml:"groupId"`
Server string `json:"server" yaml:"server" xml:"server"`
Domain string `json:"domain" yaml:"domain" xml:"domain"`
GroupName string `json:"groupName" yaml:"groupName" xml:"groupName"`
InstanceName string `json:"instance" yaml:"instance" xml:"instance"`
}
type MqCredentials struct {
AccessKey string `json:"accessKey" yaml:"accessKey" xml:"accessKey"`
SecretKey string `json:"secretKey" yaml:"secretKey" xml:"secretKey"`
SecretToken string `json:"secretToken" yaml:"secretToken" xml:"secretToken"`
}
type MqConfig struct {
Client MqClient `json:"client" yaml:"client" xml:"client"`
Credentials MqCredentials `json:"credentials" yaml:"credentials" xml:"credentials"`
LogLevel int `json:"logLevel" yaml:"logLevel" xml:"logLevel"`
ProducerConf MqProducerConfig `json:"producer" yaml:"producer" xml:"producer"`
ConsumerConf MqConsumerConfig `json:"consumer" yaml:"consumer" xml:"consumer"`
}
type MqProducerConfig struct {
Timeout int `json:"timeout" yaml:"timeout" xml:"timeout"`
Compress int `json:"compress" yaml:"compress" xml:"compress"`
Size int `json:"size" yaml:"size" xml:"size"`
Retry int `json:"retry" yaml:"retry" xml:"retry"`
}
type MqConsumerConfig struct {
ThreadCount int `json:"threadCount" yaml:"threadCount" xml:"threadCount"`
Model int `json:"model" yaml:"model" xml:"model"`
Size int `json:"size" yaml:"size" xml:"size"`
}
// Cluster 集群配置
type Cluster struct {
Nodes []Address `json:"nodes" yaml:"nodes" xml:"nodes"`
Password string `json:"password" yaml:"password" xml:"password"`
PoolSize int `json:"pool_size" yaml:"pool_size" xml:"pool_size"`
ReadOnly bool `json:"read_only" yaml:"read_only" xml:"read_only"`
DialTimeout time.Duration `json:"dial_timeout" yaml:"dial_timeout" xml:"dial_timeout"`
ReadTimeout time.Duration `json:"read_timeout" yaml:"read_timeout" xml:"read_timeout"`
WriteTimeout time.Duration `json:"write_timeout" yaml:"write_timeout" xml:"write_timeout"`
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/h79/goutils.git
git@gitee.com:h79/goutils.git
h79
goutils
goutils
v1.4.21

搜索帮助