11//
22// DISCLAIMER
33//
4- // Copyright 2020-2024 ArangoDB GmbH, Cologne, Germany
4+ // Copyright 2020-2025 ArangoDB GmbH, Cologne, Germany
55//
66// Licensed under the Apache License, Version 2.0 (the "License");
77// you may not use this file except in compliance with the License.
@@ -74,23 +74,24 @@ func (c collectionDocumentRead) ReadDocument(ctx context.Context, key string, re
7474func (c collectionDocumentRead ) ReadDocumentWithOptions (ctx context.Context , key string , result interface {}, opts * CollectionDocumentReadOptions ) (DocumentMeta , error ) {
7575 url := c .collection .url ("document" , key )
7676
77- var response struct {
78- shared.ResponseStruct `json:",inline"`
79- DocumentMeta `json:",inline"`
80- }
81-
82- data := newUnmarshalInto (result )
77+ var response Unmarshal [shared.ResponseStruct , Unmarshal [DocumentMeta , UnmarshalData ]]
8378
84- resp , err := connection .CallGet (ctx , c .collection .connection (), url , newMultiUnmarshaller ( & response , data ) , c .collection .withModifiers (opts .modifyRequest )... )
79+ resp , err := connection .CallGet (ctx , c .collection .connection (), url , & response , c .collection .withModifiers (opts .modifyRequest )... )
8580 if err != nil {
8681 return DocumentMeta {}, err
8782 }
8883
8984 switch code := resp .Code (); code {
9085 case http .StatusOK :
91- return response .DocumentMeta , nil
86+ if err := response .Object .Object .Inject (result ); err != nil {
87+ return DocumentMeta {}, err
88+ }
89+ if z := response .Object .Current ; z != nil {
90+ return * z , nil
91+ }
92+ return DocumentMeta {}, nil
9293 default :
93- return DocumentMeta {}, response .AsArangoErrorWithCode (code )
94+ return DocumentMeta {}, response .Current . AsArangoErrorWithCode (code )
9495 }
9596}
9697
@@ -112,18 +113,32 @@ func (c *collectionDocumentReadResponseReader) Read(i interface{}) (CollectionDo
112113 return CollectionDocumentReadResponse {}, shared.NoMoreDocumentsError {}
113114 }
114115
115- var meta CollectionDocumentReadResponse
116+ var response Unmarshal [shared. ResponseStruct , Unmarshal [ DocumentMeta , UnmarshalData ]]
116117
117- if err := c .array .Unmarshal (newMultiUnmarshaller ( & meta , newUnmarshalInto ( i )) ); err != nil {
118+ if err := c .array .Unmarshal (& response ); err != nil {
118119 if err == io .EOF {
119120 return CollectionDocumentReadResponse {}, shared.NoMoreDocumentsError {}
120121 }
121122 return CollectionDocumentReadResponse {}, err
122123 }
123124
125+ var meta CollectionDocumentReadResponse
126+
127+ if q := response .Current ; q != nil {
128+ meta .ResponseStruct = * q
129+ }
130+
131+ if q := response .Object .Current ; q != nil {
132+ meta .DocumentMeta = * q
133+ }
134+
124135 if meta .Error != nil && * meta .Error {
125136 return meta , meta .AsArangoError ()
126137 }
127138
139+ if err := response .Object .Object .Inject (i ); err != nil {
140+ return CollectionDocumentReadResponse {}, err
141+ }
142+
128143 return meta , nil
129144}
0 commit comments