redis_store_config.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package conf
  2. import (
  3. "fmt"
  4. "github.com/lf-edge/ekuiper/pkg/cast"
  5. )
  6. type optional struct {
  7. Password string `json:"password"`
  8. }
  9. type edgeXConfig struct {
  10. Protocol string `json:"protocol"`
  11. Server string `json:"server"`
  12. Port int `json:"port"`
  13. Type string `json:"type"`
  14. MessageType string `json:"message_type"`
  15. OptionalCfg optional `json:"optional"`
  16. }
  17. func RedisStorageConSelectorApply(connectionSelector string, conf *KuiperConf) error {
  18. sel := ConSelector{
  19. ConnSelectorStr: connectionSelector,
  20. }
  21. err := sel.Init()
  22. if err != nil {
  23. return err
  24. }
  25. // this should be edgeX redis config
  26. kvs, err := sel.ReadCfgFromYaml()
  27. if err != nil {
  28. return err
  29. }
  30. redisCfg := edgeXConfig{}
  31. err = cast.MapToStruct(kvs, &redisCfg)
  32. if err != nil {
  33. return err
  34. }
  35. if redisCfg.Type != "redis" || redisCfg.Protocol != "redis" {
  36. return fmt.Errorf("redis storage connection selector %s only support redis mesage bus, but got %v", sel.ConnSelectorStr, kvs)
  37. }
  38. conf.Store.Redis.Host = redisCfg.Server
  39. conf.Store.Redis.Port = redisCfg.Port
  40. conf.Store.Redis.Password = redisCfg.OptionalCfg.Password
  41. return nil
  42. }