Sin descripción
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

doris_config.go 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package subconfigs
  2. import (
  3. "fmt"
  4. "git.x2erp.com/qdy/go-base/config/core"
  5. )
  6. type DorisConfig struct {
  7. core.BaseConfig
  8. FEHost string `yaml:"fe_host" desc:"Doris FE节点主机地址"`
  9. FEPort int `yaml:"fe_port" desc:"Doris FE节点端口"`
  10. FEUsername string `yaml:"fe_username" desc:"Doris FE节点用户名"`
  11. FEPassword string `yaml:"fe_password" desc:"Doris FE节点密码"`
  12. MySQLHost string `yaml:"mysql_host" desc:"MySQL兼容接口主机地址"`
  13. MySQLPort int `yaml:"mysql_port" desc:"MySQL兼容接口端口"`
  14. MaxOpenConns int `yaml:"max_open_conns" desc:"最大打开连接数"`
  15. MaxIdleConns int `yaml:"max_idle_conns" desc:"最大空闲连接数"`
  16. ConnMaxLifetime int `yaml:"conn_max_lifetime" desc:"连接最大生命周期(秒)"`
  17. StreamLoadTimeout int `yaml:"stream_load_timeout" desc:"Stream Load超时时间(秒)"`
  18. BatchSize int `yaml:"batch_size" desc:"批量操作大小"`
  19. }
  20. func (c *DorisConfig) Description() string {
  21. return "Doris数据库连接配置"
  22. }
  23. func NewDorisConfig() *DorisConfig {
  24. return &DorisConfig{}
  25. }
  26. func (c *DorisConfig) SetDefaults() {
  27. c.FEPort = 8030
  28. c.MySQLPort = 9030
  29. c.MaxOpenConns = 20
  30. c.MaxIdleConns = 10
  31. c.ConnMaxLifetime = 3600
  32. c.StreamLoadTimeout = 30
  33. c.BatchSize = 1000
  34. }
  35. func (c *DorisConfig) Load(data map[string]interface{}) error {
  36. return c.LoadFromYAML(data, c)
  37. }
  38. func (c *DorisConfig) Validate() error {
  39. if c.FEHost == "" && c.MySQLHost == "" {
  40. return fmt.Errorf("at least one of fe_host or mysql_host must be configured")
  41. }
  42. return nil
  43. }
  44. func (c *DorisConfig) IsConfigured() bool {
  45. return c.FEHost != "" || c.MySQLHost != ""
  46. }
  47. // 自动注册
  48. func init() {
  49. core.Register("doris", &DorisConfig{})
  50. }