-
Notifications
You must be signed in to change notification settings - Fork 112
/
Copy pathcompiler.go
22 lines (18 loc) · 946 Bytes
/
compiler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package schema
// Compiler is similar to the Compiler interface, but intended for types that implements, or may hold, a
// reference. All nested types must implement this interface.
type Compiler interface {
Compile(rc ReferenceChecker) error
}
// ReferenceChecker is used to retrieve a FieldValidator that can be used for validating referenced IDs.
type ReferenceChecker interface {
// ReferenceChecker should return a FieldValidator that can be used for validate that a referenced ID exists and
// is of the right format. If there is no resource matching path, nil should e returned.
ReferenceChecker(path string) (FieldValidator, Validator)
}
// ReferenceCheckerFunc is an adapter that allows ordinary functions to be used as reference checkers.
type ReferenceCheckerFunc func(path string) FieldValidator
// ReferenceChecker calls f(path).
func (f ReferenceCheckerFunc) ReferenceChecker(path string) FieldValidator {
return f(path)
}