service/library/validator/json_param.go

219 lines
6.0 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package validator
type JsonParam struct {
ErrMsg string // 检验失败输出的消息
IsTypeStaticallyDefinable bool // true-类型可静态确定, false-类型不可静态确定,只能采用反射动态确定,一般为自定义类
IsValidateFuncDefined bool // true-用户自定义了检验方法false-用户未自定义检验方法
TypeDesc string // 指示可静态确定类型的字符串详见json_param_type
// 自定义检验方法
CustomizedValidateFunc ValidateFunc
// 通用字段值
Value any
NullableValue NullableItem
SliceLen int
// 指针域
BoolPtrVal *bool
IntPtrVal *int
Int64PtrVal *int64
Float64PtrVal *float64
StringPtrVal *string
// 切片域
BoolSliceVal []bool
IntSliceVal []int
Int64SliceVal []int64
Float64SliceVal []float64
StringSliceVal []string
// 切片的指针域
BoolSlicePtrVal *[]bool
IntSlicePtrVal *[]int
Int64SlicePtrVal *[]int64
Float64SlicePtrVal *[]float64
StringSlicePtrVal *[]string
}
func NewStringParam(errMsg string, value any) *JsonParam {
return &JsonParam{
ErrMsg: errMsg,
IsTypeStaticallyDefinable: true,
TypeDesc: "string",
Value: value,
}
}
// 指针
func NewBoolPtrParam(errMsg string, value *bool) *JsonParam {
return &JsonParam{
ErrMsg: errMsg,
IsTypeStaticallyDefinable: true,
TypeDesc: "*bool",
BoolPtrVal: value,
}
}
func NewIntPtrParam(errMsg string, value *int) *JsonParam {
return &JsonParam{
ErrMsg: errMsg,
IsTypeStaticallyDefinable: true,
TypeDesc: "*int",
IntPtrVal: value,
}
}
func NewInt64PtrParam(errMsg string, value *int64) *JsonParam {
return &JsonParam{
ErrMsg: errMsg,
IsTypeStaticallyDefinable: true,
TypeDesc: "*int64",
Int64PtrVal: value,
}
}
func NewFloat64PtrParam(errMsg string, value *float64) *JsonParam {
return &JsonParam{
ErrMsg: errMsg,
IsTypeStaticallyDefinable: true,
TypeDesc: "*float64",
Float64PtrVal: value,
}
}
func NewStringPtrParam(errMsg string, value *string) *JsonParam {
return &JsonParam{
ErrMsg: errMsg,
IsTypeStaticallyDefinable: true,
TypeDesc: "*string",
StringPtrVal: value,
}
}
// 切片
func NewBoolSliceParam(errMsg string, value []bool) *JsonParam {
return &JsonParam{
ErrMsg: errMsg,
IsTypeStaticallyDefinable: true,
TypeDesc: "[]bool",
BoolSliceVal: value,
}
}
func NewIntSliceParam(errMsg string, value []int) *JsonParam {
return &JsonParam{
ErrMsg: errMsg,
IsTypeStaticallyDefinable: true,
TypeDesc: "[]int",
IntSliceVal: value,
}
}
func NewInt64SliceParam(errMsg string, value []int64) *JsonParam {
return &JsonParam{
ErrMsg: errMsg,
IsTypeStaticallyDefinable: true,
TypeDesc: "[]int64",
Int64SliceVal: value,
}
}
func NewFloat64SliceParam(errMsg string, value []float64) *JsonParam {
return &JsonParam{
ErrMsg: errMsg,
IsTypeStaticallyDefinable: true,
TypeDesc: "[]float64",
Float64SliceVal: value,
}
}
func NewStringSliceParam(errMsg string, value []string) *JsonParam {
return &JsonParam{
ErrMsg: errMsg,
IsTypeStaticallyDefinable: true,
TypeDesc: "[]string",
StringSliceVal: value,
}
}
// 切片的指针
func NewBoolSlicePtrParam(errMsg string, value *[]bool) *JsonParam {
return &JsonParam{
ErrMsg: errMsg,
IsTypeStaticallyDefinable: true,
TypeDesc: "*[]bool",
BoolSlicePtrVal: value,
}
}
func NewIntSlicePtrParam(errMsg string, value *[]int) *JsonParam {
return &JsonParam{
ErrMsg: errMsg,
IsTypeStaticallyDefinable: true,
TypeDesc: "*[]int",
IntSlicePtrVal: value,
}
}
func NewInt64SlicePtrParam(errMsg string, value *[]int64) *JsonParam {
return &JsonParam{
ErrMsg: errMsg,
IsTypeStaticallyDefinable: true,
TypeDesc: "*[]int64",
Int64SlicePtrVal: value,
}
}
func NewFloat64SlicePtrParam(errMsg string, value *[]float64) *JsonParam {
return &JsonParam{
ErrMsg: errMsg,
IsTypeStaticallyDefinable: true,
TypeDesc: "*[]float64",
Float64SlicePtrVal: value,
}
}
func NewStringSlicePtrParam(errMsg string, value *[]string) *JsonParam {
return &JsonParam{
ErrMsg: errMsg,
IsTypeStaticallyDefinable: true,
TypeDesc: "*[]string",
StringSlicePtrVal: value,
}
}
func NewTypeUnknownParam(errMsg string, value any) *JsonParam {
return &JsonParam{
ErrMsg: errMsg,
IsTypeStaticallyDefinable: false,
Value: value,
}
}
func NewStructParam(errMsg string, value NullableItem) *JsonParam {
return &JsonParam{
ErrMsg: errMsg,
IsTypeStaticallyDefinable: true,
TypeDesc: "struct",
NullableValue: value,
}
}
func NewStructPtrParam(errMsg string, value NullableItem) *JsonParam {
return &JsonParam{
ErrMsg: errMsg,
IsTypeStaticallyDefinable: true,
TypeDesc: "*struct",
NullableValue: value,
}
}
func NewStructSliceParam(errMsg string, len int) *JsonParam {
return &JsonParam{
ErrMsg: errMsg,
IsTypeStaticallyDefinable: true,
TypeDesc: "[]struct",
SliceLen: len,
}
}
func NewStructSlicePtrParam(errMsg string, value any) *JsonParam {
return &JsonParam{
ErrMsg: errMsg,
IsTypeStaticallyDefinable: true,
TypeDesc: "*[]struct",
Value: value,
}
}