Browse Source

🐛 validateCast function

master
n0m1s 6 years ago
parent
commit
48f9f04476
Signed by: nomis GPG Key ID: BC0454CAD76FE803
1 changed files with 13 additions and 5 deletions
  1. +13
    -5
      jdr/type.go

+ 13
- 5
jdr/type.go View File

@ -22,6 +22,14 @@ type VariableType interface {
DefaultValue() JsonValue DefaultValue() JsonValue
} }
func validateCast(err error) bool {
if err != nil {
log.Println(err)
return false
}
return true
}
type VariableType_badType struct {} type VariableType_badType struct {}
func (*VariableType_badType) Name() string { func (*VariableType_badType) Name() string {
@ -57,7 +65,7 @@ func (*VariableType_bool) ToBool(value JsonValue) (bool, error) {
func (self *VariableType_bool) Validate(value JsonValue) bool { func (self *VariableType_bool) Validate(value JsonValue) bool {
_, err := self.ToBool(value) _, err := self.ToBool(value)
return err == nil
return validateCast(err)
} }
func (self *VariableType_bool) ToHTML(value JsonValue) (template.HTML, error) { func (self *VariableType_bool) ToHTML(value JsonValue) (template.HTML, error) {
@ -101,7 +109,7 @@ func (self *VariableType_int) ToInt(value JsonValue) (int64, error) {
func (self *VariableType_int) Validate(value JsonValue) bool { func (self *VariableType_int) Validate(value JsonValue) bool {
_, err := self.ToInt(value) _, err := self.ToInt(value)
return err == nil
return validateCast(err)
} }
func (self *VariableType_int) ToHTML(value JsonValue) (template.HTML, error) { func (self *VariableType_int) ToHTML(value JsonValue) (template.HTML, error) {
@ -135,7 +143,7 @@ func (*VariableType_float) ToFloat(value JsonValue) (float64, error) {
func (self *VariableType_float) Validate(value JsonValue) bool { func (self *VariableType_float) Validate(value JsonValue) bool {
_, err := self.ToFloat(value) _, err := self.ToFloat(value)
return err == nil
return validateCast(err)
} }
func (self *VariableType_float) ToHTML(value JsonValue) (template.HTML, error) { func (self *VariableType_float) ToHTML(value JsonValue) (template.HTML, error) {
@ -170,7 +178,7 @@ func (self *VariableType_string) ToString(value JsonValue) (string, error) {
func (self *VariableType_string) Validate(value JsonValue) bool { func (self *VariableType_string) Validate(value JsonValue) bool {
_, err := self.ToString(value) _, err := self.ToString(value)
return err != nil
return validateCast(err)
} }
func (self *VariableType_string) ToHTML(value JsonValue) (template.HTML, error) { func (self *VariableType_string) ToHTML(value JsonValue) (template.HTML, error) {
@ -254,7 +262,7 @@ func (self *CustomEnum) ToId(value JsonValue) (int, error) {
func (self *CustomEnum) Validate(value JsonValue) bool { func (self *CustomEnum) Validate(value JsonValue) bool {
_, err := self.ToId(value) _, err := self.ToId(value)
return err == nil
return validateCast(err)
} }
func (self *CustomEnum) ToHTML(value JsonValue) (template.HTML, error) { func (self *CustomEnum) ToHTML(value JsonValue) (template.HTML, error) {


Loading…
Cancel
Save