gitee.com/h79/goutils@v1.22.10/dao/config/config.go (about)

     1  package config
     2  
     3  import (
     4  	"gitee.com/h79/goutils/common/server"
     5  	"gitee.com/h79/goutils/common/tls"
     6  	"time"
     7  )
     8  
     9  type Redis struct {
    10  	Name     string      `json:"name" yaml:"name" xml:"name"` //redis名
    11  	Master   RedisConfig `json:"master" yaml:"master" xml:"master"`
    12  	Cluster  RedisConfig `json:"cluster" yaml:"cluster" xml:"cluster"`
    13  	Sentinel RedisConfig `json:"sentinel" yaml:"sentinel" xml:"sentinel"`
    14  	Logger   RedisLogger `json:"logger" yaml:"logger" xml:"logger"`
    15  }
    16  
    17  type RedisConfig struct {
    18  	Host               []string      `json:"host" yaml:"host" xml:"host"` //ip:port
    19  	User               string        `json:"user" yaml:"user" xml:"user"`
    20  	Pwd                string        `json:"pwd" yaml:"pwd" xml:"pwd"`
    21  	DB                 int           `json:"db" yaml:"db" xml:"db"`
    22  	PoolSize           int           `json:"poolSize" yaml:"poolSize" xml:"poolSize"`
    23  	MinIdleConns       int           `json:"minIdleConns" yaml:"minIdleConns" xml:"minIdleConns"`
    24  	MaxRetries         int           `json:"maxRetries" yaml:"maxRetries" xml:"maxRetries"`
    25  	DialTimeout        time.Duration `json:"dialTimeout" yaml:"dialTimeout" xml:"dialTimeout"`
    26  	ReadTimeout        time.Duration `json:"readTimeout" yaml:"readTimeout" xml:"readTimeout"`
    27  	WriteTimeout       time.Duration `json:"writeTimeout" yaml:"writeTimeout" xml:"writeTimeout"`
    28  	IdleTimeout        time.Duration `json:"idleTimeout" yaml:"idleTimeout" xml:"idleTimeout"`
    29  	MinRetryBackoff    time.Duration `json:"MinRetryBackoff" yaml:"MinRetryBackoff" xml:"MinRetryBackoff"`
    30  	MaxRetryBackoff    time.Duration `json:"MaxRetryBackoff" yaml:"MaxRetryBackoff" xml:"MaxRetryBackoff"`
    31  	MaxConnAge         time.Duration `json:"MaxConnAge" yaml:"MaxConnAge" xml:"MaxConnAge"`
    32  	PoolTimeout        time.Duration `json:"PoolTimeout" yaml:"PoolTimeout" xml:"PoolTimeout"`
    33  	IdleCheckFrequency time.Duration `json:"IdleCheckFrequency" yaml:"IdleCheckFrequency" xml:"IdleCheckFrequency"`
    34  	Tls                tls.Tls       `json:"tls" yaml:"tls" xml:"tls"`
    35  }
    36  
    37  type RedisLogger struct {
    38  	LogLevel int `json:"level" yaml:"level" xml:"level"`
    39  }
    40  
    41  type Sql struct {
    42  	Name         string        `json:"name" yaml:"name" xml:"name"` //数据名(不是数据库名)
    43  	Master       Database      `json:"master" yaml:"master" xml:"master"`
    44  	Sources      []Database    `json:"sources" yaml:"sources" xml:"sources"`
    45  	Replicas     []Database    `json:"replicas" yaml:"replicas" xml:"replicas"`
    46  	MaxOpenConns int           `json:"max_open_conns" yaml:"max_open_conns" xml:"max_open_conns"`
    47  	MaxIdleConns int           `json:"max_idle_conns" yaml:"max_idle_conns" xml:"max_idle_conns"`
    48  	MaxIdleTime  time.Duration `json:"max_idle_time" yaml:"max_idle_time" xml:"max_idle_time"`
    49  	MaxLifetime  time.Duration `json:"max_life_time" yaml:"max_life_time" xml:"max_life_time"`
    50  	Logger       SqlLogger     `json:"logger" yaml:"logger" xml:"logger"`
    51  }
    52  
    53  type SqlLogger struct {
    54  	LogLevel                  int           `json:"level" yaml:"level" xml:"level"`
    55  	SlowThreshold             time.Duration `json:"slowThreshold" yaml:"slowThreshold" xml:"slowThreshold"`
    56  	IgnoreRecordNotFoundError bool          `json:"ignoreRecordNotFoundError" yaml:"ignoreRecordNotFoundError" xml:"ignoreRecordNotFoundError"`
    57  	AlarmEnabled              bool          `json:"alarmEnabled" yaml:"alarmEnabled" xml:"alarmEnabled"`
    58  }
    59  
    60  type Database struct {
    61  	Host         string           `json:"host" yaml:"host" xml:"host"`
    62  	Port         int              `json:"port" yaml:"port" xml:"port"`
    63  	User         string           `json:"user" yaml:"user" xml:"user"`
    64  	Pwd          string           `json:"pwd" yaml:"pwd" xml:"pwd"`
    65  	Charset      string           `json:"charset" yaml:"charset" xml:"charset"`                // charset字符值
    66  	DriverType   string           `json:"type" yaml:"type" xml:"type"`                         //mysql, sqlite
    67  	Name         string           `json:"name" yaml:"name" xml:"name"`                         //数据库名
    68  	Tls          tls.Tls          `json:"tls" yaml:"tls" xml:"tls"`                            //for key
    69  	ServerPubKey tls.ServerPubKey `json:"serverPubKey" yaml:"serverPubKey" xml:"serverPubKey"` //for serverPubKey
    70  }
    71  
    72  type Elastic struct {
    73  	Host              []string      `json:"hosts" yaml:"hosts" xml:"hosts"` //机群
    74  	Name              string        `json:"name" yaml:"name" xml:"name"`    //数据名(不是数据库名)
    75  	User              string        `json:"user" yaml:"user" xml:"user"`
    76  	Pwd               string        `json:"pwd" yaml:"pwd" xml:"pwd"`
    77  	XPackSecurityUser string        `json:"XPackSecurityUser" yaml:"XPackSecurityUser" xml:"XPackSecurityUser"`
    78  	Interval          time.Duration `json:"interval" yaml:"interval" xml:"interval"`
    79  	Sniff             bool          `json:"sniff" yaml:"sniff" xml:"sniff"`
    80  	Logger            EsLogger      `json:"logger" yaml:"logger" xml:"logger"`
    81  }
    82  
    83  type EsLogger struct {
    84  	LogLevel int `json:"level" yaml:"level" xml:"level"`
    85  }
    86  
    87  // Cluster 集群配置
    88  type Cluster struct {
    89  	Nodes        []server.Address `json:"nodes" yaml:"nodes" xml:"nodes"`
    90  	Password     string           `json:"password" yaml:"password" xml:"password"`
    91  	PoolSize     int              `json:"pool_size" yaml:"pool_size" xml:"pool_size"`
    92  	ReadOnly     bool             `json:"read_only" yaml:"read_only" xml:"read_only"`
    93  	DialTimeout  time.Duration    `json:"dial_timeout" yaml:"dial_timeout" xml:"dial_timeout"`
    94  	ReadTimeout  time.Duration    `json:"read_timeout" yaml:"read_timeout" xml:"read_timeout"`
    95  	WriteTimeout time.Duration    `json:"write_timeout" yaml:"write_timeout" xml:"write_timeout"`
    96  }