/
githubmirror
/
GoFrame
Обзор
Документация
Войти
/
githubmirror
/
GoFrame
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
util/gvalid/internal/builtin/builtin_max.go
43 строки
1015 B
John Guo
feature/v2.2.0 (#2154)
26 сен 2022, 17:11
Не верифицирован
26 сен 2022, 17:11
141ca62
Код
Авторство
О чём код?
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved. // // This Source Code Form is subject to the terms of the MIT License. // If a copy of the MIT was not distributed with this file, // You can obtain one at https://github.com/gogf/gf. package builtin import ( "errors" "strconv" "github.com/gogf/gf/v2/text/gstr" ) // RuleMax implements `max` rule: // Equal or lesser than :max. It supports both integer and float. // // Format: max:max type RuleMax struct{} func init() { Register(RuleMax{}) } func (r RuleMax) Name() string { return "max" } func (r RuleMax) Message() string { return "The {field} value `{value}` must be equal or lesser than {max}" } func (r RuleMax) Run(in RunInput) error { var ( max, err1 = strconv.ParseFloat(in.RulePattern, 10) valueN, err2 = strconv.ParseFloat(in.Value.String(), 10) ) if valueN > max || err1 != nil || err2 != nil { return errors.New(gstr.Replace(in.Message, "{max}", strconv.FormatFloat(max, 'f', -1, 64))) } return nil }