validate

package
v0.2.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 28, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Length

type Length struct {
	Min, Max int
}

Length 长度规则

func (Length) Validate

func (l Length) Validate(value interface{}) error

Validate 验证值的长度是否在范围内

type Option

type Option func(*options)

Option 是验证器选项函数

func WithRule

func WithRule(key string, rule Rule) Option

WithRule 添加验证规则

type Pattern

type Pattern struct {
	Regex string
}

Pattern 模式规则

func (Pattern) Validate

func (p Pattern) Validate(value interface{}) error

Validate 验证值是否匹配正则表达式

type Range

type Range struct {
	Min, Max float64
}

Range 范围规则

func (Range) Validate

func (r Range) Validate(value interface{}) error

Validate 验证值是否在范围内

type Required

type Required struct{}

Required 必填规则

func (Required) Validate

func (r Required) Validate(value interface{}) error

Validate 验证值是否为空

type Rule

type Rule interface {
	// Validate 验证值
	Validate(value interface{}) error
}

Rule 是验证规则接口

type Validator

type Validator interface {
	// Validate 验证配置值
	Validate(value config.Value) error
}

Validator 是配置验证器接口

func New

func New(opts ...Option) Validator

New 创建一个验证器

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL