File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -93,6 +93,30 @@ func (c *Codec) Encode(v cue.Value, x interface{}) error {
93
93
return v .Decode (x )
94
94
}
95
95
96
+ var defaultCodec = New (& cue.Runtime {}, nil )
97
+
98
+ // Validate calls Validate on a default Codec for the type of x.
99
+ func Validate (x interface {}) error {
100
+ c := defaultCodec
101
+ c .mutex .RLock ()
102
+ defer c .mutex .RUnlock ()
103
+
104
+ r := defaultCodec .runtime
105
+ v , err := fromGoType (r , x )
106
+ if err != nil {
107
+ return err
108
+ }
109
+ w , err := fromGoValue (r , x , false )
110
+ if err != nil {
111
+ return err
112
+ }
113
+ v = v .Unify (w )
114
+ if err := v .Validate (); err != nil {
115
+ return err
116
+ }
117
+ return nil
118
+ }
119
+
96
120
// Validate checks whether x satisfies the constraints defined by v.
97
121
//
98
122
// The given value must be created using the same Runtime with which c was
You can’t perform that action at this time.
0 commit comments