validateMountEntries applies shared mount parsing and classification across callers while allowing each caller to preserve its own logging and error construction. onValid may be nil. onInvalid must be non-nil and must return a non-nil error for all non-OK mountValidationKind values.
(mounts []string, onValid func(int, mountParts), onInvalid func(int, string, mountParts, mountValidationKind) error)
| 150 | // construction. onValid may be nil. onInvalid must be non-nil and must return |
| 151 | // a non-nil error for all non-OK mountValidationKind values. |
| 152 | func validateMountEntries(mounts []string, onValid func(int, mountParts), onInvalid func(int, string, mountParts, mountValidationKind) error) error { |
| 153 | if onInvalid == nil { |
| 154 | return errors.New("internal error: onInvalid callback must not be nil") |
| 155 | } |
| 156 | |
| 157 | for i, mount := range mounts { |
| 158 | parts, kind := parseMountEntry(mount) |
| 159 | if kind == mountValidationOK { |
| 160 | if onValid != nil { |
| 161 | onValid(i, parts) |
| 162 | } |
| 163 | continue |
| 164 | } |
| 165 | err := onInvalid(i, mount, parts, kind) |
| 166 | if err == nil { |
| 167 | return fmt.Errorf("internal error: onInvalid callback returned nil for mount kind %d", kind) |
| 168 | } |
| 169 | return err |
| 170 | } |
| 171 | |
| 172 | return nil |
| 173 | } |
| 174 | |
| 175 | // validateStringEnumField checks that a config field, if present, contains one |
| 176 | // of the allowed string values. Non-string values and unrecognised strings are |