es_config.go 749 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package config
  2. import "eta/eta_mini_ht_api/common/contants"
  3. // ESOpts es连接属性
  4. type ESOpts struct {
  5. Url string
  6. Username string
  7. Password string
  8. }
  9. type ESConfig struct {
  10. BaseConfig
  11. opts ESOpts
  12. }
  13. func (e *ESConfig) GetUrl() string {
  14. return e.opts.Url
  15. }
  16. func (e *ESConfig) GetUserName() string {
  17. return e.opts.Username
  18. }
  19. func (e *ESConfig) GetPassword() string {
  20. return e.opts.Password
  21. }
  22. func (e *ESConfig) InitConfig() {
  23. opts := ESOpts{
  24. Url: e.GetString("url"),
  25. Username: e.GetString("username"),
  26. Password: e.GetString("password"),
  27. }
  28. e.opts = opts
  29. }
  30. func NewES() Config {
  31. return &ESConfig{
  32. BaseConfig: BaseConfig{prefix: contants.ES},
  33. opts: ESOpts{},
  34. }
  35. }
  36. func init() {
  37. Register(contants.ES, NewES)
  38. }