Search Apps Documentation Source Content File Folder Download Copy Actions Download

default_string_policy.gno

0.62 Kb · 31 lines
 1package validate
 2
 3type DefaultStringPolicy struct {
 4	LenKind    StringLenKind
 5	AllowEmpty bool
 6}
 7
 8func (policy DefaultStringPolicy) Validate() (bool, string) {
 9	valid, message := policy.LenKind.Valid()
10	if !valid {
11		return false, message
12	}
13	return true, ""
14}
15
16func (policy DefaultStringPolicy) MustValid() {
17	valid, message := policy.Validate()
18	if !valid {
19		panic(message)
20	}
21}
22
23func (policy DefaultStringPolicy) StringPolicy(key string) StringPolicy {
24	return StringPolicy{
25		key:        StringPolicyKey(key),
26		kind:       StringPlain,
27		lenKind:    policy.LenKind,
28		required:   false,
29		allowEmpty: policy.AllowEmpty,
30	}
31}