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
dcdfaf36
Commit
dcdfaf36
authored
Jul 28, 2013
by
miraclesu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Accept parameters more types
parent
ae7e3171
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
30 deletions
+32
-30
validation.go
validation/validation.go
+29
-26
validation_test.go
validation/validation_test.go
+2
-2
validators.go
validation/validators.go
+1
-2
No files found.
validation/validation.go
View file @
dcdfaf36
...
...
@@ -84,16 +84,19 @@ func (v *Validation) Required(obj interface{}, key string) *ValidationResult {
return
v
.
apply
(
Required
{
key
},
obj
)
}
func
(
v
*
Validation
)
Min
(
n
int
,
min
int
,
key
string
)
*
ValidationResult
{
return
v
.
apply
(
Min
{
min
,
key
},
n
)
// Test that the obj is greater than min if obj's type is int
func
(
v
*
Validation
)
Min
(
obj
interface
{},
min
int
,
key
string
)
*
ValidationResult
{
return
v
.
apply
(
Min
{
min
,
key
},
obj
)
}
func
(
v
*
Validation
)
Max
(
n
int
,
max
int
,
key
string
)
*
ValidationResult
{
return
v
.
apply
(
Max
{
max
,
key
},
n
)
// Test that the obj is less than max if obj's type is int
func
(
v
*
Validation
)
Max
(
obj
interface
{},
max
int
,
key
string
)
*
ValidationResult
{
return
v
.
apply
(
Max
{
max
,
key
},
obj
)
}
func
(
v
*
Validation
)
Range
(
n
,
min
,
max
int
,
key
string
)
*
ValidationResult
{
return
v
.
apply
(
Range
{
Min
{
Min
:
min
},
Max
{
Max
:
max
},
key
},
n
)
// Test that the obj is between mni and max if obj's type is int
func
(
v
*
Validation
)
Range
(
obj
interface
{},
min
,
max
int
,
key
string
)
*
ValidationResult
{
return
v
.
apply
(
Range
{
Min
{
Min
:
min
},
Max
{
Max
:
max
},
key
},
obj
)
}
func
(
v
*
Validation
)
MinSize
(
obj
interface
{},
min
int
,
key
string
)
*
ValidationResult
{
...
...
@@ -120,45 +123,45 @@ func (v *Validation) AlphaNumeric(obj interface{}, key string) *ValidationResult
return
v
.
apply
(
AlphaNumeric
{
key
},
obj
)
}
func
(
v
*
Validation
)
Match
(
str
string
,
regex
*
regexp
.
Regexp
,
key
string
)
*
ValidationResult
{
return
v
.
apply
(
Match
{
regex
,
key
},
str
)
func
(
v
*
Validation
)
Match
(
obj
interface
{}
,
regex
*
regexp
.
Regexp
,
key
string
)
*
ValidationResult
{
return
v
.
apply
(
Match
{
regex
,
key
},
obj
)
}
func
(
v
*
Validation
)
NoMatch
(
str
string
,
regex
*
regexp
.
Regexp
,
key
string
)
*
ValidationResult
{
return
v
.
apply
(
NoMatch
{
Match
{
Regexp
:
regex
},
key
},
str
)
func
(
v
*
Validation
)
NoMatch
(
obj
interface
{}
,
regex
*
regexp
.
Regexp
,
key
string
)
*
ValidationResult
{
return
v
.
apply
(
NoMatch
{
Match
{
Regexp
:
regex
},
key
},
obj
)
}
func
(
v
*
Validation
)
AlphaDash
(
str
string
,
key
string
)
*
ValidationResult
{
return
v
.
apply
(
AlphaDash
{
NoMatch
{
Match
:
Match
{
Regexp
:
alphaDashPattern
}},
key
},
str
)
func
(
v
*
Validation
)
AlphaDash
(
obj
interface
{}
,
key
string
)
*
ValidationResult
{
return
v
.
apply
(
AlphaDash
{
NoMatch
{
Match
:
Match
{
Regexp
:
alphaDashPattern
}},
key
},
obj
)
}
func
(
v
*
Validation
)
Email
(
str
string
,
key
string
)
*
ValidationResult
{
return
v
.
apply
(
Email
{
Match
{
Regexp
:
emailPattern
},
key
},
str
)
func
(
v
*
Validation
)
Email
(
obj
interface
{}
,
key
string
)
*
ValidationResult
{
return
v
.
apply
(
Email
{
Match
{
Regexp
:
emailPattern
},
key
},
obj
)
}
func
(
v
*
Validation
)
IP
(
str
string
,
key
string
)
*
ValidationResult
{
return
v
.
apply
(
IP
{
Match
{
Regexp
:
ipPattern
},
key
},
str
)
func
(
v
*
Validation
)
IP
(
obj
interface
{}
,
key
string
)
*
ValidationResult
{
return
v
.
apply
(
IP
{
Match
{
Regexp
:
ipPattern
},
key
},
obj
)
}
func
(
v
*
Validation
)
Base64
(
str
string
,
key
string
)
*
ValidationResult
{
return
v
.
apply
(
Base64
{
Match
{
Regexp
:
base64Pattern
},
key
},
str
)
func
(
v
*
Validation
)
Base64
(
obj
interface
{}
,
key
string
)
*
ValidationResult
{
return
v
.
apply
(
Base64
{
Match
{
Regexp
:
base64Pattern
},
key
},
obj
)
}
func
(
v
*
Validation
)
Mobile
(
str
string
,
key
string
)
*
ValidationResult
{
return
v
.
apply
(
Mobile
{
Match
{
Regexp
:
mobilePattern
},
key
},
str
)
func
(
v
*
Validation
)
Mobile
(
obj
interface
{}
,
key
string
)
*
ValidationResult
{
return
v
.
apply
(
Mobile
{
Match
{
Regexp
:
mobilePattern
},
key
},
obj
)
}
func
(
v
*
Validation
)
Tel
(
str
string
,
key
string
)
*
ValidationResult
{
return
v
.
apply
(
Tel
{
Match
{
Regexp
:
telPattern
},
key
},
str
)
func
(
v
*
Validation
)
Tel
(
obj
interface
{}
,
key
string
)
*
ValidationResult
{
return
v
.
apply
(
Tel
{
Match
{
Regexp
:
telPattern
},
key
},
obj
)
}
func
(
v
*
Validation
)
Phone
(
str
string
,
key
string
)
*
ValidationResult
{
func
(
v
*
Validation
)
Phone
(
obj
interface
{}
,
key
string
)
*
ValidationResult
{
return
v
.
apply
(
Phone
{
Mobile
{
Match
:
Match
{
Regexp
:
mobilePattern
}},
Tel
{
Match
:
Match
{
Regexp
:
telPattern
}},
key
},
str
)
Tel
{
Match
:
Match
{
Regexp
:
telPattern
}},
key
},
obj
)
}
func
(
v
*
Validation
)
ZipCode
(
str
string
,
key
string
)
*
ValidationResult
{
return
v
.
apply
(
ZipCode
{
Match
{
Regexp
:
zipCodePattern
},
key
},
str
)
func
(
v
*
Validation
)
ZipCode
(
obj
interface
{}
,
key
string
)
*
ValidationResult
{
return
v
.
apply
(
ZipCode
{
Match
{
Regexp
:
zipCodePattern
},
key
},
obj
)
}
func
(
v
*
Validation
)
apply
(
chk
Validator
,
obj
interface
{})
*
ValidationResult
{
...
...
validation/validation_test.go
View file @
dcdfaf36
...
...
@@ -61,10 +61,10 @@ func TestRange(t *testing.T) {
valid
:=
Validation
{}
if
valid
.
Range
(
-
1
,
0
,
1
,
"range0_1"
)
.
Ok
{
t
.
Error
(
"-1 is bet
t
ween 0 and 1 should be false"
)
t
.
Error
(
"-1 is between 0 and 1 should be false"
)
}
if
!
valid
.
Range
(
1
,
0
,
1
,
"range0_1"
)
.
Ok
{
t
.
Error
(
"1 is bet
t
ween 0 and 1 should be true"
)
t
.
Error
(
"1 is between 0 and 1 should be true"
)
}
}
...
...
validation/validators.go
View file @
dcdfaf36
...
...
@@ -264,8 +264,7 @@ type Match struct {
}
func
(
m
Match
)
IsSatisfied
(
obj
interface
{})
bool
{
str
:=
obj
.
(
string
)
return
m
.
Regexp
.
MatchString
(
str
)
return
m
.
Regexp
.
MatchString
(
fmt
.
Sprintf
(
"%v"
,
obj
))
}
func
(
m
Match
)
DefaultMessage
()
string
{
...
...
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