/
githubmirror
/
GoFrame
Обзор
Документация
Войти
/
githubmirror
/
GoFrame
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
util/gvalid/internal/builtin/builtin.go
55 строк
2 KB
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 implements built-in validation rules. // // Referred to Laravel validation: // https://laravel.com/docs/master/validation#available-validation-rules package builtin import ( "github.com/gogf/gf/v2/container/gvar" ) type Rule interface { // Name returns the builtin name of the rule. Name() string // Message returns the default error message of the rule. Message() string // Run starts running the rule, it returns nil if successful, or else an error. Run(in RunInput) error } type RunInput struct { RuleKey string // RuleKey is like the "max" in rule "max: 6" RulePattern string // RulePattern is like "6" in rule:"max:6" Field string // The field name of Value. Value *gvar.Var // Value specifies the value for this rule to validate. Data *gvar.Var // Data specifies the `data` which is passed to the Validator. Message string // Message specifies the custom error message or configured i18n message for this rule. Option RunOption // Option provides extra configuration for validation rule. } type RunOption struct { CaseInsensitive bool // CaseInsensitive indicates that it does Case-Insensitive comparison in string. } var ( // ruleMap stores all builtin validation rules. ruleMap = map[string]Rule{} ) // Register registers builtin rule into manager. func Register(rule Rule) { ruleMap[rule.Name()] = rule } // GetRule retrieves and returns rule by `name`. func GetRule(name string) Rule { return ruleMap[name] }