Documentation ¶
Index ¶
Constants ¶
View Source
const SchemaVersion = 3
Variables ¶
View Source
var Validate = func(fn ...schema.SchemaValidateDiagFunc) schema.SchemaValidateDiagFunc { return func(i any, p cty.Path) diag.Diagnostics { var diags diag.Diagnostics for _, validateFunc := range fn { diags = append(diags, validateFunc(i, p)...) } return diags } }
View Source
var ValidateMax = func(max int) schema.SchemaValidateDiagFunc { return func(i any, p cty.Path) diag.Diagnostics { var diags diag.Diagnostics var iv int switch v := i.(type) { case int: iv = v case string: var err error v = strings.TrimSpace(v) if strings.HasPrefix(v, "{{") && strings.HasSuffix(v, "}}") { return diags } iv, err = strconv.Atoi(v) if err != nil { diags = append(diags, diag.Diagnostic{Severity: diag.Error, Summary: fmt.Sprintf("%s is not a number", i.(string))}) return diags } } if iv > max { diags = append(diags, diag.Diagnostic{Severity: diag.Error, Summary: fmt.Sprintf("%v must not be greater than %d", i, max)}) } return diags } }
View Source
var ValidateMaxLength = func(maxLength int) schema.SchemaValidateDiagFunc { return func(i any, p cty.Path) diag.Diagnostics { var diags diag.Diagnostics if len(i.(string)) > maxLength { diag := diag.Diagnostic{ Severity: diag.Error, Summary: fmt.Sprintf("%s exceeds the maximum length of %d characters", i.(string), maxLength), } diags = append(diags, diag) } return diags } }
View Source
var ValidateMin = func(min int) schema.SchemaValidateDiagFunc { return func(i any, p cty.Path) diag.Diagnostics { var diags diag.Diagnostics var iv int switch v := i.(type) { case int: iv = v case string: var err error v = strings.TrimSpace(v) if strings.HasPrefix(v, "{{") && strings.HasSuffix(v, "}}") { return diags } iv, err = strconv.Atoi(v) if err != nil { diags = append(diags, diag.Diagnostic{Severity: diag.Error, Summary: fmt.Sprintf("%s is not a number", i.(string))}) return diags } } if iv < min { diags = append(diags, diag.Diagnostic{Severity: diag.Error, Summary: fmt.Sprintf("%v must not be less than %d", i, min)}) } return diags } }
View Source
var ValidateMinLength = func(min int) schema.SchemaValidateDiagFunc { return func(i any, p cty.Path) diag.Diagnostics { var diags diag.Diagnostics if len(i.(string)) < min { diag := diag.Diagnostic{ Severity: diag.Error, Summary: fmt.Sprintf("%s must be at least %d characters long", i.(string), min), } diags = append(diags, diag) } return diags } }
View Source
var ValidateRange = func(min int, max int) schema.SchemaValidateDiagFunc { return func(i any, p cty.Path) diag.Diagnostics { var diags diag.Diagnostics var iv int switch v := i.(type) { case int: iv = v case string: var err error v = strings.TrimSpace(v) if strings.HasPrefix(v, "{{") && strings.HasSuffix(v, "}}") { return diags } iv, err = strconv.Atoi(v) if err != nil { diags = append(diags, diag.Diagnostic{Severity: diag.Error, Summary: fmt.Sprintf("%s is not a number", i.(string))}) return diags } } if iv < min || iv > max { diags = append(diags, diag.Diagnostic{Severity: diag.Error, Summary: fmt.Sprintf("%v is not in range %d and %d", i, min, max)}) } return diags } }
View Source
var ValidateRegex = func(r *regexp.Regexp, errorMessage string) schema.SchemaValidateDiagFunc { return func(i any, p cty.Path) diag.Diagnostics { var diags diag.Diagnostics if !r.MatchString(i.(string)) { diag := diag.Diagnostic{ Severity: diag.Error, Summary: fmt.Sprintf("%s contains invalid characters", i.(string)), Detail: errorMessage, } diags = append(diags, diag) } return diags } }
View Source
var ValidateTypePossibleValues = func(valuesList []string) schema.SchemaValidateDiagFunc { return func(i any, p cty.Path) diag.Diagnostics { var diags diag.Diagnostics if !isInList(i.(string), valuesList) { diag := diag.Diagnostic{ Severity: diag.Error, Summary: fmt.Sprintf("%s is not on the list of possible values: %s", i.(string), valuesList), } diags = append(diags, diag) } return diags } }
View Source
var ValidateUUID = func(i any, p cty.Path) diag.Diagnostics { var diags diag.Diagnostics if _, err := uuid.Parse(i.(string)); err != nil { diag := diag.Diagnostic{ Severity: diag.Error, Summary: "The value is expected to be a UUID", Detail: fmt.Sprintf("%v is not a UUID", i), } diags = append(diags, diag) } return diags }
Functions ¶
This section is empty.
Types ¶
type Document ¶
type Document struct { Name string `json:"name" maxlength:"200"` Content string `json:"content,omitempty"` Type string `json:"type"` Actor string `json:"actor,omitempty" maxlength:"36" format:"uuid"` Owner string `json:"owner,omitempty" format:"uuid"` Version int `json:"version,omitempty"` SchemaVersion int `json:"schemaVersion,omitempty"` }
func (*Document) MarshalHCL ¶
func (me *Document) MarshalHCL(properties hcl.Properties) error
func (*Document) MarshalJSON ¶
Click to show internal directories.
Click to hide internal directories.