config.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package file
  2. import (
  3. "time"
  4. "errors"
  5. "path"
  6. xtime "go-common/library/time"
  7. )
  8. type Config struct {
  9. CacheFlushInterval xtime.Duration `tome:"cacheFlushInterval"`
  10. WriteBuffer int `tome:"writeBuffer"`
  11. Storage string `tome:"storage"`
  12. StorageMaxMB int `tome:"storageMaxMB"`
  13. FileBytes int `tome:"fileBytes"`
  14. Suffix string `tome:"suffix"`
  15. ReadBuffer int `tome:"readBuffer"`
  16. Index string `tome:"index"`
  17. }
  18. func (c *Config) ConfigValidate() (error) {
  19. if c == nil {
  20. return errors.New("config of fileCache is nil")
  21. }
  22. if time.Duration(c.CacheFlushInterval) == 0 {
  23. c.CacheFlushInterval = xtime.Duration(time.Second * 5)
  24. }
  25. if c.WriteBuffer == 0 {
  26. c.WriteBuffer = 1024 * 1024 * 2 // 2M by default
  27. }
  28. if c.Storage == "" {
  29. return errors.New("storage settings for lancer output can't be nil")
  30. }
  31. if c.StorageMaxMB == 0 {
  32. c.StorageMaxMB = 5120
  33. }
  34. if c.FileBytes == 0 {
  35. c.FileBytes = 1024 * 1024 * 2 // 2M by default
  36. }
  37. if c.Suffix == "" {
  38. c.Suffix = ".log"
  39. }
  40. if c.ReadBuffer == 0 {
  41. c.ReadBuffer = 1024 * 1024 * 2 // 2M by default
  42. }
  43. if c.Index == "" {
  44. c.Index = path.Join(c.Storage, "output.index")
  45. }
  46. return nil
  47. }