config.go 802 B

123456789101112131415161718192021222324252627282930313233343536
  1. package local
  2. import (
  3. "github.com/pkg/errors"
  4. )
  5. // CreateConfig is used to configure new instances of driver
  6. type CreateConfig struct {
  7. DisableCompression bool
  8. MaxFileSize int64
  9. MaxFileCount int
  10. }
  11. func newDefaultConfig() *CreateConfig {
  12. return &CreateConfig{
  13. MaxFileSize: defaultMaxFileSize,
  14. MaxFileCount: defaultMaxFileCount,
  15. DisableCompression: !defaultCompressLogs,
  16. }
  17. }
  18. func validateConfig(cfg *CreateConfig) error {
  19. if cfg.MaxFileSize < 0 {
  20. return errors.New("max size should be a positive number")
  21. }
  22. if cfg.MaxFileCount < 0 {
  23. return errors.New("max file count cannot be less than 0")
  24. }
  25. if !cfg.DisableCompression {
  26. if cfg.MaxFileCount <= 1 {
  27. return errors.New("compression cannot be enabled when max file count is 1")
  28. }
  29. }
  30. return nil
  31. }