rules

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package rules 一些通用的验证规则

Index

Constants

This section is empty.

Variables

View Source
var (
	Required = server.NewRuleFunc(locales.Required, func(a any) bool {
		if a == nil {
			return false
		}
		return !reflect.ValueOf(a).IsZero()
	})

	Strength = server.NewRule(locales.StrengthInvalid, validator.Strength(8, 1, 0, 1))

	// Avatar 头像验证规则,可以为空或是 URL
	Avatar = server.NewRule(locales.InvalidValue, validator.OrFunc(validator.URL, func(a any) bool {
		if a == nil {
			return true
		}
		switch v := a.(type) {
		case string:
			return v == ""
		case []byte:
			return len(v) == 0
		case []rune:
			return len(v) == 0
		default:
			return false
		}
	}))
)

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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