huaweicloud-sdk-go-v3
huaweicloud-sdk-go-v3 copied to clipboard
bug when list images
version: 0ccecf224744f8b6c09b940efec9b50dcd23f5c0
svc, err := this.getImsClient()
if err != nil {
return nil, err
}
x := imsmodel.GetListImagesRequestImagetypeEnum().GOLD
req := imsmodel.ListImagesRequest{
Imagetype: &x,
}
seelog.Infof("%v", req)
resp, err := svc.ListImages(&req)
if err != nil {
seelog.Error(err)
return nil, err
}
}
response err
{"status_code":400,"request_id":"ac61c67ed03c22c83cb7435064ef70e3","error_code":"IMG.0024","error_message":"The image type in the request is incorrect."}
req debug log
ListImagesRequest {"__imagetype":"gold"}
error happens when convert struct enum to string gold
become gold%22%0A
in url
err code in core/hc_http_client.go
func flattenEnumStruct(value reflect.Value) (reflect.Value, error) {
if value.Kind() == reflect.Struct {
v, e := jsoniter.Marshal(value.Interface())
if e == nil {
if strings.HasPrefix(string(v), "\"") {
return reflect.ValueOf(strings.Trim(string(v), "\"")), nil
} else {
return reflect.ValueOf(string(v)), nil
}
}
return reflect.ValueOf(nil), e
}
return value, nil
}
fix code may be
func flattenEnumStruct(value reflect.Value) (reflect.Value, error) {
if value.Kind() == reflect.Struct {
v, e := jsoniter.Marshal(value.Interface())
if e == nil {
s := string(v)
s = strings.TrimSpace(s)
if strings.HasPrefix(s, "\"") {
return reflect.ValueOf(strings.Trim(s, "\"")), nil
} else {
return reflect.ValueOf(s), nil
}
}
return reflect.ValueOf(nil), e
}
return value, nil
}
I tried v0.0.71 and the result was ok.
I checked the value of this string and there are no spaces in it.
func GetListImagesRequestImagetypeEnum() ListImagesRequestImagetypeEnum {
return ListImagesRequestImagetypeEnum{
GOLD: ListImagesRequestImagetype{
value: "gold",
},
PRIVATE: ListImagesRequestImagetype{
value: "private",
},
SHARED: ListImagesRequestImagetype{
value: "shared",
},
}
}
I want to know which version of SDK you are using?
可能是json-iterator的问题吧,但是你的代码是不能兼容处理的
jsoniter.Marshal(value.Interface()) 不同版本可能得出不同结果
好的,我看下这个问题
长时间未收到回复,自动关闭问题。如有疑问,请重新打开问题或者创建新的问题。 If no reply is received for a long time, the issue is automatically closed. If you have any questions, please reopen the issue or create a new issue.