Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
beego
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
beego
Commits
2389bc72
Commit
2389bc72
authored
Sep 12, 2015
by
astaxie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
golint validation
parent
1d200da4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
11 additions
and
10 deletions
+11
-10
util.go
validation/util.go
+6
-5
util_test.go
validation/util_test.go
+2
-2
validation.go
validation/validation.go
+0
-0
validation_test.go
validation/validation_test.go
+3
-3
validators.go
validation/validators.go
+0
-0
No files found.
validation/util.go
View file @
2389bc72
...
...
@@ -23,7 +23,8 @@ import (
)
const
(
VALIDTAG
=
"valid"
// ValidTag struct tag
ValidTag
=
"valid"
)
var
(
...
...
@@ -55,16 +56,16 @@ func init() {
}
}
// Valid function type
// Valid
Func 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
(
V
ALIDTAG
)
tag
:=
f
.
Tag
.
Get
(
V
alidTag
)
if
len
(
tag
)
==
0
{
return
}
...
...
validation/util_test.go
View file @
2389bc72
...
...
@@ -20,7 +20,7 @@ import (
)
type
user
struct
{
I
d
int
I
D
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
(
"I
d
"
)
f
,
_
:=
tf
.
FieldByName
(
"I
D
"
)
if
vfs
,
err
=
getValidFuncs
(
f
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
validation/validation.go
View file @
2389bc72
This diff is collapsed.
Click to expand it.
validation/validation_test.go
View file @
2389bc72
...
...
@@ -302,7 +302,7 @@ func TestZipCode(t *testing.T) {
func
TestValid
(
t
*
testing
.
T
)
{
type
user
struct
{
I
d
int
I
D
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
{
I
d
int
I
D
int
Name
string
`valid:"Required;Match(/^(test)?\\w*@(/test/);com$/)"`
Age
int
`valid:"Required;Range(1, 140)"`
}
type
AnonymouseUser
struct
{
I
d
2
int
I
D
2
int
Name2
string
`valid:"Required;Match(/^(test)?\\w*@(/test/);com$/)"`
Age2
int
`valid:"Required;Range(1, 140)"`
}
...
...
validation/validators.go
View file @
2389bc72
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment