Merge pull request #97 from cygnushan/fix-UnpackHTTPRequest-panic

Fix unpack http request panic
This commit is contained in:
Simon 2018-06-01 14:21:45 +08:00 committed by GitHub
commit 05aacd4b8c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 2 deletions

View File

@ -81,8 +81,8 @@ func (u *Unpacker) parseError() error {
retCodeValue := u.output.Elem().FieldByName("RetCode")
messageValue := u.output.Elem().FieldByName("Message")
if retCodeValue.IsValid() && retCodeValue.Type().String() == "*int" &&
messageValue.IsValid() && messageValue.Type().String() == "*string" &&
if retCodeValue.Elem().IsValid() && retCodeValue.Type().String() == "*int" &&
messageValue.Elem().IsValid() && messageValue.Type().String() == "*string" &&
retCodeValue.Elem().Int() != 0 {
return &errors.QingCloudError{

View File

@ -79,6 +79,7 @@ func TestUnpackerUnpackHTTPRequest(t *testing.T) {
RetCode *int `json:"ret_code" name:"ret_code"`
TotalCount *int `json:"total_count" name:"total_count"`
VolumeSet []*Volume `json:"volume_set" name:"volume_set"`
Message *string `json:"message" name:"message"`
}
httpResponse := &http.Response{Header: http.Header{}}