增加规则默认实例
This commit is contained in:
107
rule_instance.go
Normal file
107
rule_instance.go
Normal file
@ -0,0 +1,107 @@
|
||||
// Package validator ...
|
||||
//
|
||||
// Description : validator ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 2024-04-29 12:18
|
||||
package validator
|
||||
|
||||
import "git.zhangdeman.cn/gateway/validator/define"
|
||||
|
||||
// NewDefaultFieldRule ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 14:01 2024/4/29
|
||||
func NewDefaultFieldRule(path string, dataType string, isRequired bool, defaultValue string) *define.FieldRule {
|
||||
r := &define.FieldRule{
|
||||
Path: path,
|
||||
Type: dataType,
|
||||
DefaultValue: defaultValue,
|
||||
IsRequired: isRequired,
|
||||
AllowNil: false,
|
||||
AllowEmpty: false,
|
||||
AllowZero: true,
|
||||
RequiredConditionGroup: make([][]define.RequiredCondition, 0),
|
||||
ValueLimit: &define.ValueLimit{
|
||||
String: nil,
|
||||
Int: nil,
|
||||
Float: nil,
|
||||
Slice: nil,
|
||||
Map: nil,
|
||||
},
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
// NewDefaultStringValueLimit ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 12:22 2024/4/29
|
||||
func NewDefaultStringValueLimit(minLength int64, maxLength int64) *define.StringValueLimit {
|
||||
l := &define.StringValueLimit{
|
||||
MinLength: minLength,
|
||||
MaxLength: maxLength,
|
||||
AutoTrimSpace: true,
|
||||
IncludeSubStrList: make([]string, 0),
|
||||
EnumList: make([]string, 0),
|
||||
}
|
||||
return l
|
||||
}
|
||||
|
||||
// NewDefaultIntValueLimit ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 12:24 2024/4/29
|
||||
func NewDefaultIntValueLimit(min *int64, max *int64) *define.IntValueLimit {
|
||||
l := &define.IntValueLimit{
|
||||
Min: min,
|
||||
Max: max,
|
||||
EnumList: make([]int64, 0),
|
||||
}
|
||||
return l
|
||||
}
|
||||
|
||||
// NewDefaultFloatValueLimit ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 12:27 2024/4/29
|
||||
func NewDefaultFloatValueLimit(min *float64, max *float64) *define.FloatValueLimit {
|
||||
l := &define.FloatValueLimit{
|
||||
Min: min,
|
||||
Max: max,
|
||||
EnumList: make([]float64, 0),
|
||||
}
|
||||
return l
|
||||
}
|
||||
|
||||
// NewDefaultSliceValueLimit ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 12:30 2024/4/29
|
||||
func NewDefaultSliceValueLimit(minLength int64, maxLength int64) *define.SliceValueLimit {
|
||||
l := &define.SliceValueLimit{
|
||||
MinLength: minLength,
|
||||
MaxLength: maxLength,
|
||||
}
|
||||
return l
|
||||
}
|
||||
|
||||
// NewDefaultMapValueLimit ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 12:30 2024/4/29
|
||||
func NewDefaultMapValueLimit(minLength int64, maxLength int64) *define.MapValueLimit {
|
||||
l := &define.MapValueLimit{
|
||||
MinLength: minLength,
|
||||
MaxLength: maxLength,
|
||||
IncludeFieldList: make([]string, 0),
|
||||
}
|
||||
return l
|
||||
}
|
Reference in New Issue
Block a user