Parameter Validation for Golang

Source: Internet
Author: User
This is a created article in which the information may have evolved or changed.

Golang_validator

Freely customizable Golang parameter verifier

About the component:
This component is highly customizable and can be used as an example:

type testValidator struct {    ItemNum int `valid:"PosNO" name:"items" ` // 验证是否是正数    IsCount int `valid:"PosNO"`}

Valid for validation, followed by the name of the function to be validated: This can be written if you want to validate for integers and strings:

`valid:"PosNO,Str"

Name indicates the name of the current field
To extend, verify that the function is in the following format:

 func (this *Validator) CheckPosNO(data int, tag reflect.StructTag) error {     if data <= 0 {         return errors.New(tag.Get("name") + ":不能为负数!")     }     return nil }

The check represents the prefix of the function and is written on the label when called: Posno can

With regard to this component, many of the web frameworks currently Golang are available, but why should the author write it himself for the following reasons:
While many frameworks are available, there is little support for customization. So I wrote one based on the needs of the project.

Download Address:
Https://github.com/yingtianxun/golang_validator/blob/master/README.md

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.