get_log.go 853 字节
package query

import (
	"fmt"
	"reflect"
	"strings"

	"github.com/beego/beego/v2/core/validation"
)

type GetLogQuery struct {
	// 日志ID
	LogId int `cname:"日志ID" json:"logId" valid:"Required"`
}

func (getLogQuery *GetLogQuery) Valid(validation *validation.Validation) {
	validation.SetError("CustomValid", "未实现的自定义认证")
}

func (getLogQuery *GetLogQuery) ValidateQuery() error {
	valid := validation.Validation{}
	b, err := valid.Valid(getLogQuery)
	if err != nil {
		return err
	}
	if !b {
		elem := reflect.TypeOf(getLogQuery).Elem()
		for _, validErr := range valid.Errors {
			field, isExist := elem.FieldByName(validErr.Field)
			if isExist {
				return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
			} else {
				return fmt.Errorf(validErr.Message)
			}
		}
	}
	return nil
}