@@ -8,7 +8,6 @@ package http
88
99import (
1010 "context"
11- "net/url"
1211 "path"
1312 "strconv"
1413
@@ -46,15 +45,16 @@ func NewReadingClientWithUrlCallback(baseUrlFunc clients.ClientBaseUrlFunc, auth
4645}
4746
4847func (rc readingClient ) AllReadings (ctx context.Context , offset , limit int ) (responses.MultiReadingsResponse , errors.EdgeX ) {
49- requestParams := url.Values {}
50- requestParams .Set (common .Offset , strconv .Itoa (offset ))
51- requestParams .Set (common .Limit , strconv .Itoa (limit ))
48+ return rc .AllReadingsWithQueryParams (ctx , offset , limit , nil )
49+ }
50+
51+ func (rc readingClient ) AllReadingsWithQueryParams (ctx context.Context , offset , limit int , queryParams map [string ]string ) (responses.MultiReadingsResponse , errors.EdgeX ) {
5252 res := responses.MultiReadingsResponse {}
5353 baseUrl , err := clients .GetBaseUrl (rc .baseUrlFunc )
5454 if err != nil {
5555 return res , errors .NewCommonEdgeXWrapper (err )
5656 }
57- err = utils .GetRequest (ctx , & res , baseUrl , common .ApiAllReadingRoute , requestParams , rc .authInjector )
57+ err = utils .GetRequest (ctx , & res , baseUrl , common .ApiAllReadingRoute , utils . ToRequestParameters ( offset , limit , queryParams ) , rc .authInjector )
5858 if err != nil {
5959 return res , errors .NewCommonEdgeXWrapper (err )
6060 }
@@ -89,51 +89,54 @@ func (rc readingClient) ReadingCountByDeviceName(ctx context.Context, name strin
8989}
9090
9191func (rc readingClient ) ReadingsByDeviceName (ctx context.Context , name string , offset , limit int ) (responses.MultiReadingsResponse , errors.EdgeX ) {
92+ return rc .ReadingsByDeviceNameWithQueryParams (ctx , name , offset , limit , nil )
93+ }
94+
95+ func (rc readingClient ) ReadingsByDeviceNameWithQueryParams (ctx context.Context , name string , offset , limit int , queryParams map [string ]string ) (responses.MultiReadingsResponse , errors.EdgeX ) {
9296 requestPath := path .Join (common .ApiReadingRoute , common .Device , common .Name , name )
93- requestParams := url.Values {}
94- requestParams .Set (common .Offset , strconv .Itoa (offset ))
95- requestParams .Set (common .Limit , strconv .Itoa (limit ))
9697 res := responses.MultiReadingsResponse {}
9798 baseUrl , err := clients .GetBaseUrl (rc .baseUrlFunc )
9899 if err != nil {
99100 return res , errors .NewCommonEdgeXWrapper (err )
100101 }
101- err = utils .GetRequest (ctx , & res , baseUrl , requestPath , requestParams , rc .authInjector )
102+ err = utils .GetRequest (ctx , & res , baseUrl , requestPath , utils . ToRequestParameters ( offset , limit , queryParams ) , rc .authInjector )
102103 if err != nil {
103104 return res , errors .NewCommonEdgeXWrapper (err )
104105 }
105106 return res , nil
106107}
107108
108109func (rc readingClient ) ReadingsByResourceName (ctx context.Context , name string , offset , limit int ) (responses.MultiReadingsResponse , errors.EdgeX ) {
110+ return rc .ReadingsByResourceNameWithQueryParams (ctx , name , offset , limit , nil )
111+ }
112+
113+ func (rc readingClient ) ReadingsByResourceNameWithQueryParams (ctx context.Context , name string , offset , limit int , queryParams map [string ]string ) (responses.MultiReadingsResponse , errors.EdgeX ) {
109114 requestPath := common .NewPathBuilder ().EnableNameFieldEscape (rc .enableNameFieldEscape ).
110115 SetPath (common .ApiReadingRoute ).SetPath (common .ResourceName ).SetNameFieldPath (name ).BuildPath ()
111- requestParams := url.Values {}
112- requestParams .Set (common .Offset , strconv .Itoa (offset ))
113- requestParams .Set (common .Limit , strconv .Itoa (limit ))
114116 res := responses.MultiReadingsResponse {}
115117 baseUrl , err := clients .GetBaseUrl (rc .baseUrlFunc )
116118 if err != nil {
117119 return res , errors .NewCommonEdgeXWrapper (err )
118120 }
119- err = utils .GetRequest (ctx , & res , baseUrl , requestPath , requestParams , rc .authInjector )
121+ err = utils .GetRequest (ctx , & res , baseUrl , requestPath , utils . ToRequestParameters ( offset , limit , queryParams ) , rc .authInjector )
120122 if err != nil {
121123 return res , errors .NewCommonEdgeXWrapper (err )
122124 }
123125 return res , nil
124126}
125127
126128func (rc readingClient ) ReadingsByTimeRange (ctx context.Context , start , end int64 , offset , limit int ) (responses.MultiReadingsResponse , errors.EdgeX ) {
129+ return rc .ReadingsByTimeRangeWithQueryParams (ctx , start , end , offset , limit , nil )
130+ }
131+
132+ func (rc readingClient ) ReadingsByTimeRangeWithQueryParams (ctx context.Context , start , end int64 , offset , limit int , queryParams map [string ]string ) (responses.MultiReadingsResponse , errors.EdgeX ) {
127133 requestPath := path .Join (common .ApiReadingRoute , common .Start , strconv .FormatInt (start , 10 ), common .End , strconv .FormatInt (end , 10 ))
128- requestParams := url.Values {}
129- requestParams .Set (common .Offset , strconv .Itoa (offset ))
130- requestParams .Set (common .Limit , strconv .Itoa (limit ))
131134 res := responses.MultiReadingsResponse {}
132135 baseUrl , err := clients .GetBaseUrl (rc .baseUrlFunc )
133136 if err != nil {
134137 return res , errors .NewCommonEdgeXWrapper (err )
135138 }
136- err = utils .GetRequest (ctx , & res , baseUrl , requestPath , requestParams , rc .authInjector )
139+ err = utils .GetRequest (ctx , & res , baseUrl , requestPath , utils . ToRequestParameters ( offset , limit , queryParams ) , rc .authInjector )
137140 if err != nil {
138141 return res , errors .NewCommonEdgeXWrapper (err )
139142 }
@@ -142,68 +145,71 @@ func (rc readingClient) ReadingsByTimeRange(ctx context.Context, start, end int6
142145
143146// ReadingsByResourceNameAndTimeRange returns readings by resource name and specified time range. Readings are sorted in descending order of origin time.
144147func (rc readingClient ) ReadingsByResourceNameAndTimeRange (ctx context.Context , name string , start , end int64 , offset , limit int ) (responses.MultiReadingsResponse , errors.EdgeX ) {
148+ return rc .ReadingsByResourceNameAndTimeRangeWithQueryParams (ctx , name , start , end , offset , limit , nil )
149+ }
150+
151+ func (rc readingClient ) ReadingsByResourceNameAndTimeRangeWithQueryParams (ctx context.Context , name string , start , end int64 , offset , limit int , queryParams map [string ]string ) (responses.MultiReadingsResponse , errors.EdgeX ) {
145152 requestPath := common .NewPathBuilder ().EnableNameFieldEscape (rc .enableNameFieldEscape ).
146153 SetPath (common .ApiReadingRoute ).SetPath (common .ResourceName ).SetNameFieldPath (name ).SetPath (common .Start ).SetPath (strconv .FormatInt (start , 10 )).SetPath (common .End ).SetPath (strconv .FormatInt (end , 10 )).BuildPath ()
147- requestParams := url.Values {}
148- requestParams .Set (common .Offset , strconv .Itoa (offset ))
149- requestParams .Set (common .Limit , strconv .Itoa (limit ))
150154 res := responses.MultiReadingsResponse {}
151155 baseUrl , err := clients .GetBaseUrl (rc .baseUrlFunc )
152156 if err != nil {
153157 return res , errors .NewCommonEdgeXWrapper (err )
154158 }
155- err = utils .GetRequest (ctx , & res , baseUrl , requestPath , requestParams , rc .authInjector )
159+ err = utils .GetRequest (ctx , & res , baseUrl , requestPath , utils . ToRequestParameters ( offset , limit , queryParams ) , rc .authInjector )
156160 if err != nil {
157161 return res , errors .NewCommonEdgeXWrapper (err )
158162 }
159163 return res , nil
160164}
161165
162166func (rc readingClient ) ReadingsByDeviceNameAndResourceName (ctx context.Context , deviceName , resourceName string , offset , limit int ) (responses.MultiReadingsResponse , errors.EdgeX ) {
167+ return rc .ReadingsByDeviceNameAndResourceNameWithQueryParams (ctx , deviceName , resourceName , offset , limit , nil )
168+ }
169+
170+ func (rc readingClient ) ReadingsByDeviceNameAndResourceNameWithQueryParams (ctx context.Context , deviceName , resourceName string , offset , limit int , queryParams map [string ]string ) (responses.MultiReadingsResponse , errors.EdgeX ) {
163171 requestPath := common .NewPathBuilder ().EnableNameFieldEscape (rc .enableNameFieldEscape ).
164172 SetPath (common .ApiReadingRoute ).SetPath (common .Device ).SetPath (common .Name ).SetNameFieldPath (deviceName ).SetPath (common .ResourceName ).SetNameFieldPath (resourceName ).BuildPath ()
165- requestParams := url.Values {}
166- requestParams .Set (common .Offset , strconv .Itoa (offset ))
167- requestParams .Set (common .Limit , strconv .Itoa (limit ))
168173 res := responses.MultiReadingsResponse {}
169174 baseUrl , err := clients .GetBaseUrl (rc .baseUrlFunc )
170175 if err != nil {
171176 return res , errors .NewCommonEdgeXWrapper (err )
172177 }
173- err = utils .GetRequest (ctx , & res , baseUrl , requestPath , requestParams , rc .authInjector )
178+ err = utils .GetRequest (ctx , & res , baseUrl , requestPath , utils . ToRequestParameters ( offset , limit , queryParams ) , rc .authInjector )
174179 if err != nil {
175180 return res , errors .NewCommonEdgeXWrapper (err )
176181 }
177182 return res , nil
178-
179183}
180184
181185func (rc readingClient ) ReadingsByDeviceNameAndResourceNameAndTimeRange (ctx context.Context , deviceName , resourceName string , start , end int64 , offset , limit int ) (responses.MultiReadingsResponse , errors.EdgeX ) {
186+ return rc .ReadingsByDeviceNameAndResourceNameAndTimeRangeWithQueryParams (ctx , deviceName , resourceName , start , end , offset , limit , nil )
187+ }
188+
189+ func (rc readingClient ) ReadingsByDeviceNameAndResourceNameAndTimeRangeWithQueryParams (ctx context.Context , deviceName , resourceName string , start , end int64 , offset , limit int , queryParams map [string ]string ) (responses.MultiReadingsResponse , errors.EdgeX ) {
182190 requestPath := common .NewPathBuilder ().EnableNameFieldEscape (rc .enableNameFieldEscape ).
183191 SetPath (common .ApiReadingRoute ).SetPath (common .Device ).SetPath (common .Name ).SetNameFieldPath (deviceName ).SetPath (common .ResourceName ).SetNameFieldPath (resourceName ).
184192 SetPath (common .Start ).SetPath (strconv .FormatInt (start , 10 )).SetPath (common .End ).SetPath (strconv .FormatInt (end , 10 )).BuildPath ()
185- requestParams := url.Values {}
186- requestParams .Set (common .Offset , strconv .Itoa (offset ))
187- requestParams .Set (common .Limit , strconv .Itoa (limit ))
188193 res := responses.MultiReadingsResponse {}
189194 baseUrl , err := clients .GetBaseUrl (rc .baseUrlFunc )
190195 if err != nil {
191196 return res , errors .NewCommonEdgeXWrapper (err )
192197 }
193- err = utils .GetRequest (ctx , & res , baseUrl , requestPath , requestParams , rc .authInjector )
198+ err = utils .GetRequest (ctx , & res , baseUrl , requestPath , utils . ToRequestParameters ( offset , limit , queryParams ) , rc .authInjector )
194199 if err != nil {
195200 return res , errors .NewCommonEdgeXWrapper (err )
196201 }
197202 return res , nil
198203}
199204
200205func (rc readingClient ) ReadingsByDeviceNameAndResourceNamesAndTimeRange (ctx context.Context , deviceName string , resourceNames []string , start , end int64 , offset , limit int ) (responses.MultiReadingsResponse , errors.EdgeX ) {
206+ return rc .ReadingsByDeviceNameAndResourceNamesAndTimeRangeWithQueryParams (ctx , deviceName , resourceNames , start , end , offset , limit , nil )
207+ }
208+
209+ func (rc readingClient ) ReadingsByDeviceNameAndResourceNamesAndTimeRangeWithQueryParams (ctx context.Context , deviceName string , resourceNames []string , start , end int64 , offset , limit int , queryParams map [string ]string ) (responses.MultiReadingsResponse , errors.EdgeX ) {
201210 requestPath := common .NewPathBuilder ().EnableNameFieldEscape (rc .enableNameFieldEscape ).
202211 SetPath (common .ApiReadingRoute ).SetPath (common .Device ).SetPath (common .Name ).SetNameFieldPath (deviceName ).
203212 SetPath (common .Start ).SetPath (strconv .FormatInt (start , 10 )).SetPath (common .End ).SetPath (strconv .FormatInt (end , 10 )).BuildPath ()
204- requestParams := url.Values {}
205- requestParams .Set (common .Offset , strconv .Itoa (offset ))
206- requestParams .Set (common .Limit , strconv .Itoa (limit ))
207213 var queryPayload map [string ]interface {}
208214 if len (resourceNames ) > 0 { // gosimple S1009: len(nil slice) == 0
209215 queryPayload = make (map [string ]interface {}, 1 )
@@ -214,7 +220,7 @@ func (rc readingClient) ReadingsByDeviceNameAndResourceNamesAndTimeRange(ctx con
214220 if err != nil {
215221 return res , errors .NewCommonEdgeXWrapper (err )
216222 }
217- err = utils .GetRequestWithBodyRawData (ctx , & res , baseUrl , requestPath , requestParams , queryPayload , rc .authInjector )
223+ err = utils .GetRequestWithBodyRawData (ctx , & res , baseUrl , requestPath , utils . ToRequestParameters ( offset , limit , queryParams ) , queryPayload , rc .authInjector )
218224 if err != nil {
219225 return res , errors .NewCommonEdgeXWrapper (err )
220226 }
0 commit comments