Commit 2389bc72 authored by astaxie's avatar astaxie

golint validation

parent 1d200da4
......@@ -23,7 +23,8 @@ import (
)
const (
VALIDTAG = "valid"
// ValidTag struct tag
ValidTag = "valid"
)
var (
......@@ -55,16 +56,16 @@ func init() {
}
}
// Valid function type
// ValidFunc Valid function type
type ValidFunc struct {
Name string
Params []interface{}
}
// Validate function map
// Funcs Validate function map
type Funcs map[string]reflect.Value
// validate values with named type string
// Call validate values with named type string
func (f Funcs) Call(name string, params ...interface{}) (result []reflect.Value, err error) {
defer func() {
if r := recover(); r != nil {
......@@ -96,7 +97,7 @@ func isStructPtr(t reflect.Type) bool {
}
func getValidFuncs(f reflect.StructField) (vfs []ValidFunc, err error) {
tag := f.Tag.Get(VALIDTAG)
tag := f.Tag.Get(ValidTag)
if len(tag) == 0 {
return
}
......
......@@ -20,7 +20,7 @@ import (
)
type user struct {
Id int
ID int
Tag string `valid:"Maxx(aa)"`
Name string `valid:"Required;"`
Age int `valid:"Required;Range(1, 140)"`
......@@ -33,7 +33,7 @@ func TestGetValidFuncs(t *testing.T) {
var vfs []ValidFunc
var err error
f, _ := tf.FieldByName("Id")
f, _ := tf.FieldByName("ID")
if vfs, err = getValidFuncs(f); err != nil {
t.Fatal(err)
}
......
This diff is collapsed.
......@@ -302,7 +302,7 @@ func TestZipCode(t *testing.T) {
func TestValid(t *testing.T) {
type user struct {
Id int
ID int
Name string `valid:"Required;Match(/^(test)?\\w*@(/test/);com$/)"`
Age int `valid:"Required;Range(1, 140)"`
}
......@@ -352,13 +352,13 @@ func TestValid(t *testing.T) {
func TestRecursiveValid(t *testing.T) {
type User struct {
Id int
ID int
Name string `valid:"Required;Match(/^(test)?\\w*@(/test/);com$/)"`
Age int `valid:"Required;Range(1, 140)"`
}
type AnonymouseUser struct {
Id2 int
ID2 int
Name2 string `valid:"Required;Match(/^(test)?\\w*@(/test/);com$/)"`
Age2 int `valid:"Required;Range(1, 140)"`
}
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment