1
1
/*
2
2
* Swagger Petstore *_/ ' \" =end -- \\r\\n \\n \\r
3
3
*
4
- * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ *_/ ' \" =end --
4
+ * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ *_/ ' \" =end --
5
5
*
6
6
* API version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r
7
7
* Contact: [email protected] *_/ ' \" =end -- \\r\\n \\n \\r
@@ -14,40 +14,37 @@ import (
14
14
"bytes"
15
15
"encoding/json"
16
16
"encoding/xml"
17
- "errors"
18
17
"fmt"
18
+ "errors"
19
19
"io"
20
20
"mime/multipart"
21
+ "golang.org/x/oauth2"
22
+ "golang.org/x/net/context"
21
23
"net/http"
22
24
"net/url"
25
+ "time"
23
26
"os"
24
27
"path/filepath"
25
28
"reflect"
26
29
"regexp"
27
- "strconv"
28
30
"strings"
29
- "time"
30
31
"unicode/utf8"
31
-
32
- "context"
33
-
34
- "golang.org/x/oauth2"
32
+ "strconv"
35
33
)
36
34
37
35
var (
38
36
jsonCheck = regexp .MustCompile ("(?i:[application|text]/json)" )
39
- xmlCheck = regexp .MustCompile ("(?i:[application|text]/xml)" )
37
+ xmlCheck = regexp .MustCompile ("(?i:[application|text]/xml)" )
40
38
)
41
39
42
40
// APIClient manages communication with the Swagger Petstore *_/ ' \" =end -- \\r\\n \\n \\r API v1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r
43
41
// In most cases there should be only one, shared, APIClient.
44
42
type APIClient struct {
45
- cfg * Configuration
46
- common service // Reuse a single struct instead of allocating one for each service on the heap.
47
-
48
- // API Services
43
+ cfg * Configuration
44
+ common service // Reuse a single struct instead of allocating one for each service on the heap.
49
45
50
- FakeApi * FakeApiService
46
+ // API Services
47
+ FakeApi * FakeApiService
51
48
}
52
49
53
50
type service struct {
@@ -75,6 +72,7 @@ func atoi(in string) (int, error) {
75
72
return strconv .Atoi (in )
76
73
}
77
74
75
+
78
76
// selectHeaderContentType select a content type from the available list.
79
77
func selectHeaderContentType (contentTypes []string ) string {
80
78
if len (contentTypes ) == 0 {
@@ -145,18 +143,18 @@ func parameterToString(obj interface{}, collectionFormat string) string {
145
143
return fmt .Sprintf ("%v" , obj )
146
144
}
147
145
148
- // callAPI do the request.
146
+ // callAPI do the request.
149
147
func (c * APIClient ) callAPI (request * http.Request ) (* http.Response , error ) {
150
- return c .cfg .HTTPClient .Do (request )
148
+ return c .cfg .HTTPClient .Do (request )
151
149
}
152
150
153
151
// Change base path to allow switching to mocks
154
- func (c * APIClient ) ChangeBasePath (path string ) {
152
+ func (c * APIClient ) ChangeBasePath (path string ) {
155
153
c .cfg .BasePath = path
156
154
}
157
155
158
156
// prepareRequest build the request
159
- func (c * APIClient ) prepareRequest (
157
+ func (c * APIClient ) prepareRequest (
160
158
ctx context.Context ,
161
159
path string , method string ,
162
160
postBody interface {},
@@ -216,7 +214,7 @@ func (c *APIClient) prepareRequest(
216
214
// Set the Boundary in the Content-Type
217
215
headerParams ["Content-Type" ] = w .FormDataContentType ()
218
216
}
219
-
217
+
220
218
// Set Content-Length
221
219
headerParams ["Content-Length" ] = fmt .Sprintf ("%d" , body .Len ())
222
220
w .Close ()
@@ -262,9 +260,10 @@ func (c *APIClient) prepareRequest(
262
260
if c .cfg .Host != "" {
263
261
localVarRequest .Host = c .cfg .Host
264
262
}
265
-
263
+
266
264
// Add the user agent to the request.
267
265
localVarRequest .Header .Add ("User-Agent" , c .cfg .UserAgent )
266
+
268
267
269
268
if ctx != nil {
270
269
// add context to the request
@@ -290,17 +289,18 @@ func (c *APIClient) prepareRequest(
290
289
291
290
// AccessToken Authentication
292
291
if auth , ok := ctx .Value (ContextAccessToken ).(string ); ok {
293
- localVarRequest .Header .Add ("Authorization" , "Bearer " + auth )
292
+ localVarRequest .Header .Add ("Authorization" , "Bearer " + auth )
294
293
}
295
294
}
296
295
297
296
for header , value := range c .cfg .DefaultHeader {
298
297
localVarRequest .Header .Add (header , value )
299
298
}
300
-
299
+
301
300
return localVarRequest , nil
302
301
}
303
302
303
+
304
304
// Add a file to the multipart request
305
305
func addFile (w * multipart.Writer , fieldName , path string ) error {
306
306
file , err := os .Open (path )
@@ -319,7 +319,7 @@ func addFile(w *multipart.Writer, fieldName, path string) error {
319
319
}
320
320
321
321
// Prevent trying to import "fmt"
322
- func reportError (format string , a ... interface {}) error {
322
+ func reportError (format string , a ... interface {}) ( error ) {
323
323
return fmt .Errorf (format , a ... )
324
324
}
325
325
@@ -356,7 +356,7 @@ func setBody(body interface{}, contentType string) (bodyBuf *bytes.Buffer, err e
356
356
func detectContentType (body interface {}) string {
357
357
contentType := "text/plain; charset=utf-8"
358
358
kind := reflect .TypeOf (body ).Kind ()
359
-
359
+
360
360
switch kind {
361
361
case reflect .Struct , reflect .Map , reflect .Ptr :
362
362
contentType = "application/json; charset=utf-8"
@@ -373,6 +373,7 @@ func detectContentType(body interface{}) string {
373
373
return contentType
374
374
}
375
375
376
+
376
377
// Ripped from https://github.com/gregjones/httpcache/blob/master/httpcache.go
377
378
type cacheControl map [string ]string
378
379
@@ -395,15 +396,15 @@ func parseCacheControl(headers http.Header) cacheControl {
395
396
}
396
397
397
398
// CacheExpires helper function to determine remaining time before repeating a request.
398
- func CacheExpires (r * http.Response ) time.Time {
399
+ func CacheExpires (r * http.Response ) ( time.Time ) {
399
400
// Figure out when the cache expires.
400
401
var expires time.Time
401
402
now , err := time .Parse (time .RFC1123 , r .Header .Get ("date" ))
402
403
if err != nil {
403
404
return time .Now ()
404
405
}
405
406
respCacheControl := parseCacheControl (r .Header )
406
-
407
+
407
408
if maxAge , ok := respCacheControl ["max-age" ]; ok {
408
409
lifetime , err := time .ParseDuration (maxAge + "s" )
409
410
if err != nil {
@@ -422,6 +423,7 @@ func CacheExpires(r *http.Response) time.Time {
422
423
return expires
423
424
}
424
425
425
- func strlen (s string ) int {
426
+ func strlen (s string ) ( int ) {
426
427
return utf8 .RuneCountInString (s )
427
428
}
429
+
0 commit comments