This commit is contained in:
src committed 2026-09-28 11:17:52 +03:00
1 parent d340d1b2ad
commit 0a9202c7c0
100 files changed
+2064 -330

No files matched your search

+25 -10
View File
@@ -20,16 +20,7 @@ func (c *Client) Decode(v any, body []byte, contentType string) (err error) {
if len(body) == 0 {
return nil
}
if stringValue, ok := v.(*string); ok {
*stringValue = string(body)
return nil
}
if xmlCheck.MatchString(contentType) {
if err = xml.Unmarshal(body, v); err != nil {
return err
}
return nil
}
if jsonCheck.MatchString(contentType) {
if actualObj, ok := v.(interface{ GetActualInstance() any }); ok {
if unmarshalObj, ok := actualObj.(interface{ UnmarshalJSON([]byte) error }); ok {
@@ -42,11 +33,26 @@ func (c *Client) Decode(v any, body []byte, contentType string) (err error) {
} else if err = json.Unmarshal(body, v); err != nil {
return err
}
if err = populateEmbeddedAnyMap(v, body); err != nil {
return err
}
return nil
}
if stringValue, ok := v.(*string); ok {
*stringValue = string(body)
return nil
}
if xmlCheck.MatchString(contentType) {
if err = xml.Unmarshal(body, v); err != nil {
return err
}
return nil
}
return fmt.Errorf("undefined response type: %v", contentType)
}
@@ -59,6 +65,7 @@ func decodeFileResponseError(body []byte) error {
if err := json.Unmarshal(body, &responseError); err != nil || !responseError.Error {
return nil
}
return &core.BackendError{
Code: responseError.ErrorCode,
Message: responseError.Message,
@@ -86,6 +93,7 @@ func (c *Client) FileResponse(resp *http.Response) (io.ReadCloser, error) {
if err := decodeFileResponseError(body); err != nil {
return nil, err
}
return io.NopCloser(bytes.NewReader(body)), nil
}
@@ -97,6 +105,7 @@ func populateEmbeddedAnyMapValue(value reflect.Value, data []byte) error {
if !value.IsValid() {
return nil
}
for value.Kind() == reflect.Ptr || value.Kind() == reflect.Interface {
if value.IsNil() {
return nil
@@ -115,14 +124,17 @@ func populateEmbeddedAnyMapValue(value reflect.Value, data []byte) error {
return nil
}
return populateEmbeddedAnyMapStruct(value, trimmed)
case reflect.Slice, reflect.Array:
if trimmed[0] != '[' {
return nil
}
var rawItems []json.RawMessage
if err := json.Unmarshal(trimmed, &rawItems); err != nil {
return err
}
for i := 0; i < value.Len() && i < len(rawItems); i++ {
if err := populateEmbeddedAnyMapValue(value.Index(i), rawItems[i]); err != nil {
return err
@@ -158,10 +170,12 @@ func populateEmbeddedAnyMapStruct(value reflect.Value, data []byte) error {
if fieldType.PkgPath != "" {
continue
}
rawField, ok := rawJSONField(rawObject, fieldType)
if !ok {
continue
}
if err := populateEmbeddedAnyMapValue(value.Field(i), rawField); err != nil {
return err
}
@@ -236,5 +250,6 @@ func hasJSONKeyFold(rawObject map[string]json.RawMessage, name string) bool {
return true
}
}
return false
}