conf.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package sock
  2. import (
  3. "errors"
  4. "time"
  5. xtime "go-common/library/time"
  6. )
  7. type Config struct {
  8. TcpAddr string `toml:"tcpAddr"`
  9. UdpAddr string `toml:"udpAddr"`
  10. ReadChanSize int `toml:"readChanSize"`
  11. TcpBatchMaxBytes int `toml:"tcpBatchMaxBytes"`
  12. UdpPacketMaxSize int `toml:"udpPacketMaxSize"`
  13. LogMaxBytes int `toml:"logMaxBytes"`
  14. UdpReadTimeout xtime.Duration `toml:"udpReadTimeout"`
  15. TcpReadTimeout xtime.Duration `toml:"tcpReadTimeout"`
  16. }
  17. func (c *Config) ConfigValidate() (error) {
  18. if c == nil {
  19. return errors.New("config of Sock Input is nil")
  20. }
  21. if c.TcpAddr == "" {
  22. c.TcpAddr = "/var/run/lancer/collector_tcp.sock"
  23. }
  24. if c.UdpAddr == "" {
  25. c.UdpAddr = "/var/run/lancer/collector.sock"
  26. }
  27. if c.ReadChanSize == 0 {
  28. c.ReadChanSize = 5000
  29. }
  30. if c.TcpBatchMaxBytes == 0 {
  31. c.TcpBatchMaxBytes = 10240000 // 10MB
  32. }
  33. if c.UdpPacketMaxSize == 0 {
  34. c.UdpPacketMaxSize = 1024 * 64 //64KB
  35. }
  36. if c.UdpReadTimeout == 0 {
  37. c.UdpReadTimeout = xtime.Duration(time.Second * 10)
  38. }
  39. if c.TcpReadTimeout == 0 {
  40. c.TcpReadTimeout = xtime.Duration(time.Minute * 5)
  41. }
  42. return nil
  43. }