11/*
22 * Swagger Petstore *_/ ' \" =end -- \\r\\n \\n \\r
33 *
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 --
55 *
66 * API version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r
77 * Contact: [email protected] *_/ ' \" =end -- \\r\\n \\n \\r @@ -14,40 +14,37 @@ import (
1414 "bytes"
1515 "encoding/json"
1616 "encoding/xml"
17- "errors"
1817 "fmt"
18+ "errors"
1919 "io"
2020 "mime/multipart"
21+ "golang.org/x/oauth2"
22+ "golang.org/x/net/context"
2123 "net/http"
2224 "net/url"
25+ "time"
2326 "os"
2427 "path/filepath"
2528 "reflect"
2629 "regexp"
27- "strconv"
2830 "strings"
29- "time"
3031 "unicode/utf8"
31-
32- "context"
33-
34- "golang.org/x/oauth2"
32+ "strconv"
3533)
3634
3735var (
3836 jsonCheck = regexp .MustCompile ("(?i:[application|text]/json)" )
39- xmlCheck = regexp .MustCompile ("(?i:[application|text]/xml)" )
37+ xmlCheck = regexp .MustCompile ("(?i:[application|text]/xml)" )
4038)
4139
4240// APIClient manages communication with the Swagger Petstore *_/ ' \" =end -- \\r\\n \\n \\r API v1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r
4341// In most cases there should be only one, shared, APIClient.
4442type 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.
4945
50- FakeApi * FakeApiService
46+ // API Services
47+ FakeApi * FakeApiService
5148}
5249
5350type service struct {
@@ -75,6 +72,7 @@ func atoi(in string) (int, error) {
7572 return strconv .Atoi (in )
7673}
7774
75+
7876// selectHeaderContentType select a content type from the available list.
7977func selectHeaderContentType (contentTypes []string ) string {
8078 if len (contentTypes ) == 0 {
@@ -145,18 +143,18 @@ func parameterToString(obj interface{}, collectionFormat string) string {
145143 return fmt .Sprintf ("%v" , obj )
146144}
147145
148- // callAPI do the request.
146+ // callAPI do the request.
149147func (c * APIClient ) callAPI (request * http.Request ) (* http.Response , error ) {
150- return c .cfg .HTTPClient .Do (request )
148+ return c .cfg .HTTPClient .Do (request )
151149}
152150
153151// Change base path to allow switching to mocks
154- func (c * APIClient ) ChangeBasePath (path string ) {
152+ func (c * APIClient ) ChangeBasePath (path string ) {
155153 c .cfg .BasePath = path
156154}
157155
158156// prepareRequest build the request
159- func (c * APIClient ) prepareRequest (
157+ func (c * APIClient ) prepareRequest (
160158 ctx context.Context ,
161159 path string , method string ,
162160 postBody interface {},
@@ -216,7 +214,7 @@ func (c *APIClient) prepareRequest(
216214 // Set the Boundary in the Content-Type
217215 headerParams ["Content-Type" ] = w .FormDataContentType ()
218216 }
219-
217+
220218 // Set Content-Length
221219 headerParams ["Content-Length" ] = fmt .Sprintf ("%d" , body .Len ())
222220 w .Close ()
@@ -262,9 +260,10 @@ func (c *APIClient) prepareRequest(
262260 if c .cfg .Host != "" {
263261 localVarRequest .Host = c .cfg .Host
264262 }
265-
263+
266264 // Add the user agent to the request.
267265 localVarRequest .Header .Add ("User-Agent" , c .cfg .UserAgent )
266+
268267
269268 if ctx != nil {
270269 // add context to the request
@@ -290,17 +289,18 @@ func (c *APIClient) prepareRequest(
290289
291290 // AccessToken Authentication
292291 if auth , ok := ctx .Value (ContextAccessToken ).(string ); ok {
293- localVarRequest .Header .Add ("Authorization" , "Bearer " + auth )
292+ localVarRequest .Header .Add ("Authorization" , "Bearer " + auth )
294293 }
295294 }
296295
297296 for header , value := range c .cfg .DefaultHeader {
298297 localVarRequest .Header .Add (header , value )
299298 }
300-
299+
301300 return localVarRequest , nil
302301}
303302
303+
304304// Add a file to the multipart request
305305func addFile (w * multipart.Writer , fieldName , path string ) error {
306306 file , err := os .Open (path )
@@ -319,7 +319,7 @@ func addFile(w *multipart.Writer, fieldName, path string) error {
319319}
320320
321321// Prevent trying to import "fmt"
322- func reportError (format string , a ... interface {}) error {
322+ func reportError (format string , a ... interface {}) ( error ) {
323323 return fmt .Errorf (format , a ... )
324324}
325325
@@ -356,7 +356,7 @@ func setBody(body interface{}, contentType string) (bodyBuf *bytes.Buffer, err e
356356func detectContentType (body interface {}) string {
357357 contentType := "text/plain; charset=utf-8"
358358 kind := reflect .TypeOf (body ).Kind ()
359-
359+
360360 switch kind {
361361 case reflect .Struct , reflect .Map , reflect .Ptr :
362362 contentType = "application/json; charset=utf-8"
@@ -373,6 +373,7 @@ func detectContentType(body interface{}) string {
373373 return contentType
374374}
375375
376+
376377// Ripped from https://github.com/gregjones/httpcache/blob/master/httpcache.go
377378type cacheControl map [string ]string
378379
@@ -395,15 +396,15 @@ func parseCacheControl(headers http.Header) cacheControl {
395396}
396397
397398// 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 ) {
399400 // Figure out when the cache expires.
400401 var expires time.Time
401402 now , err := time .Parse (time .RFC1123 , r .Header .Get ("date" ))
402403 if err != nil {
403404 return time .Now ()
404405 }
405406 respCacheControl := parseCacheControl (r .Header )
406-
407+
407408 if maxAge , ok := respCacheControl ["max-age" ]; ok {
408409 lifetime , err := time .ParseDuration (maxAge + "s" )
409410 if err != nil {
@@ -422,6 +423,7 @@ func CacheExpires(r *http.Response) time.Time {
422423 return expires
423424}
424425
425- func strlen (s string ) int {
426+ func strlen (s string ) ( int ) {
426427 return utf8 .RuneCountInString (s )
427428}
429+
0 commit comments