github.com/gogf/gf/v2@v2.7.4/util/gvalid/internal/builtin/builtin_float.go (about) 1 // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 // 3 // This Source Code Form is subject to the terms of the MIT License. 4 // If a copy of the MIT was not distributed with this file, 5 // You can obtain one at https://github.com/gogf/gf. 6 7 package builtin 8 9 import ( 10 "errors" 11 "strconv" 12 ) 13 14 // RuleFloat implements `float` rule: 15 // Float. Note that an integer is actually a float number. 16 // 17 // Format: float 18 type RuleFloat struct{} 19 20 func init() { 21 Register(RuleFloat{}) 22 } 23 24 func (r RuleFloat) Name() string { 25 return "float" 26 } 27 28 func (r RuleFloat) Message() string { 29 return "The {field} value `{value}` is not of valid float type" 30 } 31 32 func (r RuleFloat) Run(in RunInput) error { 33 if _, err := strconv.ParseFloat(in.Value.String(), 10); err == nil { 34 return nil 35 } 36 return errors.New(in.Message) 37 }