| 91 | } |
| 92 | |
| 93 | func (s *Spec) Validate() error { |
| 94 | if len(s.Path) == 0 { |
| 95 | return errors.New("`path` must be set") |
| 96 | } |
| 97 | |
| 98 | if s.NoRotate { |
| 99 | if strings.Contains(s.Path, varUUID) { |
| 100 | return fmt.Errorf("`path` should not contain %s when `no_rotate` = true", varUUID) |
| 101 | } |
| 102 | |
| 103 | if (s.BatchSize != nil && *s.BatchSize > 0) || (s.BatchSizeBytes != nil && *s.BatchSizeBytes > 0) || (s.BatchTimeout != nil && s.BatchTimeout.Duration() > 0) { |
| 104 | return errors.New("`no_rotate` cannot be used with non-zero `batch_size`, `batch_size_bytes` or `batch_timeout_ms`") |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | if !strings.Contains(s.Path, varUUID) && s.batchingEnabled() { |
| 109 | return fmt.Errorf("`path` should contain %s when using a non-zero `batch_size`, `batch_size_bytes` or `batch_timeout_ms`", varUUID) |
| 110 | } |
| 111 | |
| 112 | // required for s.FileSpec.Validate call |
| 113 | err := s.FileSpec.UnmarshalSpec() |
| 114 | if err != nil { |
| 115 | return err |
| 116 | } |
| 117 | s.FileSpec.SetDefaults() |
| 118 | |
| 119 | return s.FileSpec.Validate() |
| 120 | } |
| 121 | |
| 122 | func (s *Spec) ReplacePathVariables(table string, fileIdentifier string, t time.Time) string { |
| 123 | name := strings.ReplaceAll(s.Path, varTable, table) |