config.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package lancerlogstream
  2. import (
  3. "errors"
  4. "go-common/app/service/ops/log-agent/output/cache/file"
  5. "github.com/BurntSushi/toml"
  6. )
  7. type Config struct {
  8. Local bool `tome:"local"`
  9. Name string `tome:"name"`
  10. AggrSize int `tome:"aggrSize"`
  11. SendConcurrency int `tome:"sendConcurrency"`
  12. CacheConfig *file.Config `tome:"cacheConfig"`
  13. PoolConfig *ConnPoolConfig `tome:"poolConfig"`
  14. }
  15. func (c *Config) ConfigValidate() (error) {
  16. if c == nil {
  17. return errors.New("config of Sock Input is nil")
  18. }
  19. if c.Name == "" {
  20. return errors.New("output Name can't be nil")
  21. }
  22. if c.AggrSize == 0 {
  23. c.AggrSize = 819200
  24. }
  25. if c.SendConcurrency == 0 {
  26. c.SendConcurrency = 5
  27. }
  28. if err := c.CacheConfig.ConfigValidate(); err != nil {
  29. return err
  30. }
  31. if err := c.PoolConfig.ConfigValidate(); err != nil {
  32. return err
  33. }
  34. return nil
  35. }
  36. func DecodeConfig(md toml.MetaData, primValue toml.Primitive) (c interface{}, err error) {
  37. c = new(Config)
  38. if err = md.PrimitiveDecode(primValue, c); err != nil {
  39. return nil, err
  40. }
  41. return c, nil
  42. }