Skip to content
GitLab
Explore
Projects
Groups
Topics
Snippets
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
MKCLOS
Core Development Platform
corepkgv2
Commits
977783a2
Commit
977783a2
authored
6 years ago
by
Ajit Jagtap
Browse files
Options
Downloads
Plain Diff
Merge branch 'Rahuls_ValidationMDL_Fixes' into 'devbranch'
Validation module fixes See merge request
!5
parents
2f2b0f0d
bd3e47ab
Branches
Branches containing commit
Tags
Tags containing commit
2 merge requests
!23
Devbranch to Master
,
!5
Validation module fixes
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
validationmdl/validationmdl.go
+3
-13
validationmdl/validationmdl.go
validationmdl/validationmdl_test.go
+8
-23
validationmdl/validationmdl_test.go
with
11 additions
and
36 deletions
validationmdl/validationmdl.go
+
3
−
13
View file @
977783a2
package
validationmdl
import
(
"fmt"
"net/http"
"net/url"
...
...
@@ -11,11 +10,8 @@ import (
//ValidateRequest func validates the given model
func
ValidateRequest
(
httpRequest
*
http
.
Request
,
validationRules
,
validationMessages
govalidator
.
MapData
)
map
[
string
]
interface
{}
{
// fmt.Println("Data received : ", httpRequest.Body)
//Get the content type of the request as validations for content types are different
contentType
:=
httpRequest
.
Header
.
Get
(
"Content-Type"
)
fmt
.
Println
(
"Content type : "
,
contentType
)
//Initialize the validation errors as blank
var
validationErrors
url
.
Values
...
...
@@ -31,22 +27,16 @@ func ValidateRequest(httpRequest *http.Request, validationRules, validationMessa
opts
.
Messages
=
validationMessages
}
data
:=
make
(
map
[
string
]
interface
{},
0
)
//Validate request type json and text (RAW data from request)
if
contentType
==
"application/json"
||
contentType
==
"text/plain"
{
fmt
.
Println
(
"Inside if"
)
//Validate request type json and text (RAW data from request
)
data
:=
make
(
map
[
string
]
interface
{},
0
)
opts
.
Data
=
&
data
validator
:=
govalidator
.
New
(
opts
)
validationErrors
=
validator
.
ValidateJSON
()
}
else
{
fmt
.
Println
(
"Inside else2"
)
opts
.
Data
=
&
data
//Validate request type form-data, form-urlencoded
// loggermdl.LogVars("opts : ", opts)
validator
:=
govalidator
.
New
(
opts
)
validationErrors
=
validator
.
Validate
()
}
...
...
This diff is collapsed.
Click to expand it.
validationmdl/validationmdl_test.go
+
8
−
23
View file @
977783a2
...
...
@@ -205,20 +205,6 @@ func TestValidateRequest(t *testing.T) {
}
// func TestTestingMethod(t *testing.T) {
// blankEmailDataFormEnc := RequestBodyData{Email: "", Password: "ytyttt"}
// blankEmailByteArrayFormEnc, _ := ffjson.Marshal(&blankEmailDataFormEnc)
// blankEmailHTTPRequestFormEnc, _ := http.NewRequest("POST", "test.com", bytes.NewBufferString(string(blankEmailByteArrayFormEnc)))
// blankEmailExpectedResultFormEnc := map[string]interface{}{
// "validationErrors": url.Values{
// "email": []string{"Email required", "Email min len", "Invalid email"},
// },
// }
// got := ValidateRequest(blankEmailHTTPRequestFormEnc, validationRules, validationMessages)
// assert.Equal(t, blankEmailExpectedResultFormEnc, got, "Same pahije ")
// }
func
BenchmarkValidationTest
(
b
*
testing
.
B
)
{
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
...
...
@@ -261,17 +247,16 @@ func BenchmarkValidationTestAgainstYQL(b *testing.B) {
Age
int64
`json:"age"`
}
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
validationRules
:=
govalidator
.
MapData
{
"age"
:
[]
string
{
"required"
,
"min:23"
},
}
validationRules
:=
govalidator
.
MapData
{
"age"
:
[]
string
{
"required"
,
"min:23"
},
}
sunnyDayData
:=
TestData
{
Age
:
24
}
sunnyDayByteArray
,
_
:=
ffjson
.
Marshal
(
&
sunnyDayData
)
sunnyDayHTTPRequest
,
_
:=
http
.
NewRequest
(
"POST"
,
"test.com"
,
bytes
.
NewBufferString
(
string
(
sunnyDayByteArray
)))
sunnyDayHTTPRequest
.
Header
.
Set
(
"Content-Type"
,
"application/json"
)
sunnyDayData
:=
TestData
{
Age
:
24
}
sunnyDayByteArray
,
_
:=
ffjson
.
Marshal
(
&
sunnyDayData
)
sunnyDayHTTPRequest
,
_
:=
http
.
NewRequest
(
"POST"
,
"test.com"
,
bytes
.
NewBufferString
(
string
(
sunnyDayByteArray
)))
sunnyDayHTTPRequest
.
Header
.
Set
(
"Content-Type"
,
"application/json"
)
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
ValidateRequest
(
sunnyDayHTTPRequest
,
validationRules
,
nil
)
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Topics
Snippets