-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.go
34 lines (29 loc) · 1.02 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package valley
import (
"go/ast"
"go/token"
)
// Config represents the configuration for generating an entire set of validation code.
type Config struct {
Types map[string]TypeConfig `json:"types"`
}
// TypeConfig represents the configuration needed to generate validation code for a specific type.
type TypeConfig struct {
Constraints []ConstraintConfig `json:"constraints"`
Fields map[string]FieldConfig `json:"fields"`
}
// FieldConfig represents the configuration needed to generate validation code for a specific field
// on a specific type.
type FieldConfig struct {
Constraints []ConstraintConfig `json:"constraints"`
Elements []ConstraintConfig `json:"elements"`
Keys []ConstraintConfig `json:"keys"`
}
// ConstraintConfig represents the configuration passed to a ConstraintGenerator to generate some
// code. It's used throughout the configuration structure.
type ConstraintConfig struct {
Predicate ast.Expr
Name string `json:"name"`
Opts []ast.Expr `json:"opts"`
Pos token.Pos
}