validator

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: May 5, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitValidator

func InitValidator()

InitValidator 初始化验证器

Types

type CanCheck

type CanCheck interface {
	Check() error
}

CanCheck 如果需要特殊校验,可以实现验证接口,或者通过自定义tag标签实现

type ConfigResp

type ConfigResp struct {
	Name          string `json:"name"`
	Prefix        string `json:"prefix"`
	UserModelName string `json:"user_model_name"`
}

type DeleteReq

type DeleteReq struct {
	Ids string `json:"ids" comment:"标识符列表" validate:"required,min=1"`
}

type GetCurrentUserResp

type GetCurrentUserResp struct {
	Name   string `json:"name"`
	Avatar string `json:"avatar"`
	UserId string `json:"userid"`
}

type GlobalResp

type GlobalResp struct {
	Code    uint16      `json:"code"`    // 状态码
	Message string      `json:"message"` // 消息
	Data    interface{} `json:"data"`
}

所有返回必须包裹一层resp

type MyValidator

type MyValidator struct {
	Validate *validator.Validate
	Trans    ut.Translator
}

MyValidator 自定义验证器

var GlobalValidator MyValidator

GlobalValidator 全局验证器

func (*MyValidator) Check

func (m *MyValidator) Check(value interface{}) error

Check 验证器通用验证方法

type UserChangePasswordReq

type UserChangePasswordReq struct {
	Id       uint64 `json:"id" comment:"id" validate:"required"`
	UserName string `json:"user_name" comment:"用户名" validate:"required,max=20,min=3"`
	Password string `json:"password" comment:"密码" validate:"required,min=3,max=20"`
}

用户变更密码

type UserChangeRolesReq

type UserChangeRolesReq struct {
	Id   uint64 `json:"id" comment:"id" validate:"required"`
	Role string `json:"role" comment:"群组名" validate:"required"`
	Add  bool   `json:"add" comment:"添加"`
}

admin 变更用户群组

type UserLoginReq

type UserLoginReq struct {
	UserName string `json:"user_name" comment:"用户名" validate:"required,max=20,min=3"`
	Password string `json:"password" comment:"密码" validate:"required,min=3,max=20"`
}

用户登录

type UserLoginResp

type UserLoginResp struct {
	Token    string   `json:"token"`
	UserName string   `json:"user_name"`
	Roles    []string `json:"roles"`
}

Jump to

Keyboard shortcuts

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