govalidator
===========
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/asaskevich/govalidator?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) [![GoDoc](https://godoc.org/github.com/asaskevich/govalidator?status.png)](https://godoc.org/github.com/asaskevich/govalidator) [![Coverage Status](https://img.shields.io/coveralls/asaskevich/govalidator.svg)](https://coveralls.io/r/asaskevich/govalidator?branch=master) [![wercker status](https://app.wercker.com/status/1ec990b09ea86c910d5f08b0e02c6043/s "wercker status")](https://app.wercker.com/project/bykey/1ec990b09ea86c910d5f08b0e02c6043)
[![Build Status](https://travis-ci.org/asaskevich/govalidator.svg?branch=master)](https://travis-ci.org/asaskevich/govalidator)
A package of validators and sanitizers for strings, structs and collections. Based on [validator.js](https://github.com/chriso/validator.js).
#### Installation
Make sure that Go is installed on your computer.
Type the following command in your terminal:
go get github.com/asaskevich/govalidator
or you can get specified release of the package with `gopkg.in`:
go get gopkg.in/asaskevich/govalidator.v4
After it the package is ready to use.
#### Import package in your project
Add following line in your `*.go` file:
```go
import "github.com/asaskevich/govalidator"
```
If you are unhappy to use long `govalidator`, you can do something like this:
```go
import (
valid "github.com/asaskevich/govalidator"
)
```
#### Activate behavior to require all fields have a validation tag by default
`SetFieldsRequiredByDefault` causes validation to fail when struct fields do not include validations or are not explicitly marked as exempt (using `valid:"-"` or `valid:"email,optional"`). A good place to activate this is a package init function or the main() function.
```go
import "github.com/asaskevich/govalidator"
func init() {
govalidator.SetFieldsRequiredByDefault(true)
}
```
Here's some code to explain it:
```go
// this struct definition will fail govalidator.ValidateStruct() (and the field values do not matter):
type exampleStruct struct {
Name string ``
Email string `valid:"email"`
}
// this, however, will only fail when Email is empty or an invalid email address:
type exampleStruct2 struct {
Name string `valid:"-"`
Email string `valid:"email"`
}
// lastly, this will only fail when Email is an invalid email address but not when it's empty:
type exampleStruct2 struct {
Name string `valid:"-"`
Email string `valid:"email,optional"`
}
```
#### Recent breaking changes (see [#123](https://github.com/asaskevich/govalidator/pull/123))
##### Custom validator function signature
A context was added as the second parameter, for structs this is the object being validated – this makes dependent validation possible.
```go
import "github.com/asaskevich/govalidator"
// old signature
func(i interface{}) bool
// new signature
func(i interface{}, o interface{}) bool
```
##### Adding a custom validator
This was changed to prevent data races when accessing custom validators.
```go
import "github.com/asaskevich/govalidator"
// before
govalidator.CustomTypeTagMap["customByteArrayValidator"] = CustomTypeValidator(func(i interface{}, o interface{}) bool {
// ...
})
// after
govalidator.CustomTypeTagMap.Set("customByteArrayValidator", CustomTypeValidator(func(i interface{}, o interface{}) bool {
// ...
}))
```
#### List of functions:
```go
func Abs(value float64) float64
func BlackList(str, chars string) string
func ByteLength(str string, params ...string) bool
func StringLength(str string, params ...string) bool
func StringMatches(s string, params ...string) bool
func CamelCaseToUnderscore(str string) string
func Contains(str, substring string) bool
func Count(array []interface{}, iterator ConditionIterator) int
func Each(array []interface{}, iterator Iterator)
func ErrorByField(e error, field string) string
func Filter(array []interface{}, iterator ConditionIterator) []interface{}
func Find(array []interface{}, iterator ConditionIterator) interface{}
func GetLine(s string, index int) (string, error)
func GetLines(s string) []string
func IsHost(s string) bool
func InRange(value, left, right float64) bool
func IsASCII(str string) bool
func IsAlpha(str string) bool
func IsAlphanumeric(str string) bool
func IsBase64(str string) bool
func IsByteLength(str string, min, max int) bool
func IsCreditCard(str string) bool
func IsDataURI(str string) bool
func IsDialString(str string) bool
func IsDNSName(str string) bool
func IsDivisibleBy(str, num string) bool
func IsEmail(str string) bool
func IsFilePath(str string) (bool, int)
func IsFloat(str string) bool
func IsFullWidth(str string) bool
func IsHalfWidth(str string) bool
func IsHexadecimal(str string) bool
func IsHexcolor(str string) bool
func IsIP(str string) bool
func IsIPv4(str string) bool
func IsIPv6(str string) bool
func IsISBN(str string, version int) bool
func IsISBN10(str string) bool
func IsISBN13(str string) bool
func IsISO3166Alpha2(str string) bool
func IsISO3166Alpha3(str string) bool
func IsInt(str string) bool
func IsIn(str string, params ...string) bool
func IsJSON(str string) bool
func IsLatitude(str string) bool
func IsLongitude(str string) bool
func IsLowerCase(str string) bool
func IsMAC(str string) bool
func IsMongoID(str string) bool
func IsMultibyte(str string) bool
func IsNatural(value float64) bool
func IsNegative(value float64) bool
func IsNonNegative(value float64) bool
func IsNonPositive(value float64) bool
func IsNull(str string) bool
func IsNumeric(str string) bool
func IsPort(str string) bool
func IsPositive(value float64) bool
func IsPrintableASCII(str string) bool
func IsRGBcolor(str string) bool
func IsRequestURI(rawurl string) bool
func IsRequestURL(rawurl string) bool
func IsSSN(str string) bool
func IsSemver(str string) bool
func IsURL(str string) bool
func IsUTFDigit(str string) bool
func IsUTFLetter(str string) bool
func IsUTFLetterNumeric(str string) bool
func IsUTFNumeric(str string) bool
func IsUUID(str string) bool
func IsUUIDv3(str string) bool
func IsUUIDv4(str string) bool
func IsUUIDv5(str string) bool
func IsUpperCase(str string) bool
func IsVariableWidth(str string) bool
func IsWhole(value float64) bool
func LeftTrim(str, chars string) string
func Map(array []interface{}, iterator ResultIterator) []interface{}
func Matches(str, pattern string) bool
func NormalizeEmail(str string) (string, error)
func PadBoth(str string, padStr string, padLen int) string
func PadLeft(str string, padStr string, padLen int) string
func PadRight(str string, padStr string, padLen int) string
func RemoveTags(s string) string
func ReplacePattern(str, pattern, replace string) string
func Reverse(s string) string
func RightTrim(str, chars string) string
func SafeFileName(str string) string
func Sign(value float64) float64
func StripLow(str string, keepNewLines bool) string
func ToBoolean(str string) (bool, error)
func ToFloat(str string) (float64, error)
func ToInt(str string) (int64, error)
func ToJSON(obj interface{}) (string, error)
func ToString(obj interface{}) string
func Trim(str, chars string) string
func Truncate(str string, length int, ending string) string
func UnderscoreToCamelCase(s string) string
func ValidateStruct(s interface{}) (bool, error)
func WhiteList(str, chars string) string
type ConditionIterator
type Error
func (e Error) Error() string
type Errors
func (es Errors) Error() string
type ISO3166Entry
type Iterator
type ParamValidator
type ResultIterator
type UnsupportedTypeError
func (e *UnsupportedTypeError) Error() string
type Validator
```
#### Examples
###### IsURL
```go
println(govalidator.IsURL(`http://user@pass:domain.com/path/page`))
```
###### ToString
```go
type User struct {
FirstName string
LastName string
}
str := govalidator.ToString(&User{"John", "Juan"})
println(str)
```
###### Each, Map, Filter, Count for slices
Each iterates over the slice/array and calls Iterator for every item
```go
data := []inter
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
Go 语言被设计成一门应用于搭载 Web 服务器,存储集群或类似用途的巨型中央服务器的系统编程语言。 对于高性能分布式系统领域而言,Go 语言无疑比大多数其它语言有着更高的开发效率。它提供了海量并行的支持,这对于游戏服务端的开发而言是再好不过了。 go语言入门进阶学习资料包:go语言入门,go语言常见问题,beego框架学习资料及项目管理,后台管理等等各种应用范例含源码及MYSQL数据库脚本,值得大家学习。特分享给大家,希望go语言越来越受关注。
资源推荐
资源详情
资源评论
收起资源包目录
GO语言教程+源码范例合集 (1549个子文件)
33483ebad65b55735b1b58c3f3f435b4 2KB
44efb66b703e9e43640a96af0dca60ae 659B
461ebabb503c63703026619df1d59a7a 2KB
4d1ffc72215fcb849387216df236799c 2KB
5c86ba84aa2ae1cad79edf8bd55330e6 2KB
5eaa1cf067fd6a9f6b5b7fb95cbafca1 2KB
666e9da561f31e74b5d07e120fdefca5 1KB
a4eaceb02b8230f0ba6e77ca07b617f6 2KB
a533a79a6e6c1bf22166bdec361188fc 2KB
a7a255a63bfd3a88c908e0e44f2ac562 2KB
a9fee77b35f1e5634087029564a73cf9 2KB
AUTHORS 1KB
build.bat 1014B
bba9f0edfa24b2e5f5e6bd91de5f3794 1KB
.bowerrc 32B
c8d83cc0c276d929b40ab7cc78312228 1KB
CHANGELOG 169B
app.conf 746B
asofdate.conf 566B
app.conf 307B
app.conf 46B
rui.crt 2KB
metro.css 342KB
bootstrap.css 118KB
bootstrap.min.css 118KB
bootstrap.min.css 98KB
style.css 90KB
animate.css 71KB
font-awesome-ie7.min.css 37KB
jquery-ui-1.10.3.css 35KB
swagger-ui.css 25KB
bootstrap-table-group-by.css 24KB
bootstrap-theme.min.css 23KB
font-awesome.min.css 22KB
font-awesome.css 21KB
default.css 20KB
font-awesome.min.css 17KB
datetimepicker-custom.css 12KB
datetimepicker.css 12KB
datetimepicker.css 12KB
screen.css 12KB
demo_table.css 11KB
grid.css 10KB
demo_table_jui.css 8KB
fileinput.css 7KB
bootstrap-table.css 7KB
bootstrap-switch.min.css 6KB
clndr.css 6KB
laydate.css 6KB
bootstrap-table.min.css 6KB
fileinput.min.css 5KB
common.css 5KB
style-responsive.css 5KB
datepicker-custom.css 5KB
screen.css 5KB
jquery.dataTables_themeroller.css 4KB
jquery.dataTables.css 4KB
datepicker.css 4KB
cropper.min.css 4KB
lightbox.css 4KB
DT_bootstrap.css 4KB
bootstrap-reset.css 3KB
laydate.css 3KB
laydate.css 3KB
laydate.css 3KB
laydate.css 3KB
laydate.css 3KB
laydate.css 3KB
laydate.css 3KB
typography.css 3KB
qq.css 3KB
table-responsive.css 3KB
bootstrap-fileupload.min.css 3KB
lightbox.min.css 3KB
index.css 3KB
index.css 3KB
index.css 3KB
index.css 3KB
ie.css 3KB
screen.css 2KB
simple.css 2KB
screen.css 2KB
ie.css 2KB
print.css 2KB
forms.css 2KB
demo_page.css 2KB
jquery.stepy.css 1KB
nprogress.css 1KB
screen.css 1KB
print.css 1KB
reset.css 1KB
style.css 1KB
prettify.css 960B
bootstrap-table-reorder-rows.css 819B
bootstrap-table-tree-column.css 582B
webuploader.css 515B
bootstrap-table-sticky-header.css 416B
bootstrap-table-multiple-selection-row.css 306B
bootstrap-table-click-edit-row.css 287B
bootstrap-table-filter-control.css 190B
共 1549 条
- 1
- 2
- 3
- 4
- 5
- 6
- 16
资源评论
Rocky006
- 粉丝: 5880
- 资源: 1332
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于esp8266和dht11温湿度传感器制作的远程温湿度监控程序,温度、湿度通过mqtt协议方式上传OneNet平台
- 人染色体长度表(数据来自bilibili:基因学苑)
- 基于ASP.NET简易博客网站的设计与实现(源代码+论文).rar
- 在PyCharm中配置Python环境步骤
- 在PyCharm中配置Python环境步骤
- Lightroom-Premium-v9.2.2_build_710902200-Mod.apk
- 拾放机构3D 拾放机构3D
- Spring整合Mybatis+Spring事务快速入门(纯注解)
- 1990-2024年1月上证 深证指数日线行情
- html/css练习作业摇晃的桃子
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功