Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2a388c0108 | |||
| 268f040e48 | |||
| b56effc83d |
+9
-2
@@ -291,8 +291,11 @@ func DoRequest(request *Request, requestRuntime map[string]interface{}) (respons
|
||||
for key, value := range request.Headers {
|
||||
if value == "" || key == "content-length" {
|
||||
continue
|
||||
} else if key == "host" {
|
||||
httpRequest.Header["Host"] = []string{value}
|
||||
} else {
|
||||
httpRequest.Header[key] = []string{value}
|
||||
}
|
||||
httpRequest.Header[key] = []string{value}
|
||||
debugLog("> %s: %s", key, value)
|
||||
}
|
||||
contentlength, _ := strconv.Atoi(request.Headers["content-length"])
|
||||
@@ -845,7 +848,11 @@ func checkMaxLength(valueField reflect.Value, tag string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if maxLength < valueField.Len() {
|
||||
length := valueField.Len()
|
||||
if valueField.Kind().String() == "string" {
|
||||
length = strings.Count(valueField.String(), "") - 1
|
||||
}
|
||||
if maxLength < length {
|
||||
errMsg := fmt.Sprintf("Length of %s is more than %d", valueField.String(), maxLength)
|
||||
return errors.New(errMsg)
|
||||
}
|
||||
|
||||
+6
-1
@@ -47,6 +47,7 @@ var runtimeObj = map[string]interface{}{
|
||||
|
||||
type validateTest struct {
|
||||
Num *int `json:"num" require:"true"`
|
||||
Name *string `json:"name" maxLength:"4"`
|
||||
Str *string `json:"str" pattern:"^[a-d]*$" maxLength:"4"`
|
||||
Test *errLength `json:"test"`
|
||||
List []*string `json:"list" pattern:"^[a-d]*$" maxLength:"4"`
|
||||
@@ -541,7 +542,7 @@ func Test_validate(t *testing.T) {
|
||||
utils.AssertNil(t, err)
|
||||
|
||||
num := 1
|
||||
str0, str1 := "acc", "abcddd"
|
||||
str0, str1 := "abc", "abcddd"
|
||||
val := &validateTest{
|
||||
Num: &num,
|
||||
Str: &str0,
|
||||
@@ -559,6 +560,10 @@ func Test_validate(t *testing.T) {
|
||||
err = validate(reflect.ValueOf(val))
|
||||
utils.AssertEqual(t, "num should be setted", err.Error())
|
||||
|
||||
val.Name = String("最大长度")
|
||||
err = validate(reflect.ValueOf(val))
|
||||
utils.AssertEqual(t, "num should be setted", err.Error())
|
||||
|
||||
val.Num = &num
|
||||
val.Str = &str0
|
||||
val.List = []*string{&str1}
|
||||
|
||||
Reference in New Issue
Block a user