(variable codersdk.TemplateVersionVariable)
| 671 | } |
| 672 | |
| 673 | func createVariableValidator(variable codersdk.TemplateVersionVariable) func(string) error { |
| 674 | return func(s string) error { |
| 675 | if variable.Required && s == "" && variable.DefaultValue == "" { |
| 676 | return xerrors.New("value is required") |
| 677 | } |
| 678 | if variable.Type == "number" && s != "" { |
| 679 | if _, err := strconv.ParseFloat(s, 64); err != nil { |
| 680 | return xerrors.Errorf("must be a valid number, got: %q", s) |
| 681 | } |
| 682 | } |
| 683 | return nil |
| 684 | } |
| 685 | } |
no test coverage detected