Skip to content

Commit af3d862

Browse files
committed
update go samples
1 parent 8cc7bef commit af3d862

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

samples/openapi3/client/petstore/go/go-petstore/client.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ import (
1717
"errors"
1818
"fmt"
1919
"io"
20+
"log"
2021
"mime/multipart"
2122
"net/http"
23+
"net/http/httputil"
2224
"net/url"
2325
"os"
2426
"path/filepath"
@@ -175,7 +177,25 @@ func parameterToJson(obj interface{}) (string, error) {
175177

176178
// callAPI do the request.
177179
func (c *APIClient) callAPI(request *http.Request) (*http.Response, error) {
178-
return c.cfg.HTTPClient.Do(request)
180+
if c.cfg.Debug {
181+
dump, err := httputil.DumpRequestOut(request, true)
182+
if err != nil {
183+
return nil, err
184+
}
185+
log.Printf("\n%s\n", string(dump))
186+
}
187+
188+
resp, err := c.cfg.HTTPClient.Do(request)
189+
190+
if c.cfg.Debug {
191+
dump, err := httputil.DumpResponse(resp, true)
192+
if err != nil {
193+
return resp, err
194+
}
195+
log.Printf("\n%s\n", string(dump))
196+
}
197+
198+
return resp, err
179199
}
180200

181201
// ChangeBasePath changes base path to allow switching to mocks

samples/openapi3/client/petstore/go/go-petstore/configuration.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ type Configuration struct {
5656
Scheme string `json:"scheme,omitempty"`
5757
DefaultHeader map[string]string `json:"defaultHeader,omitempty"`
5858
UserAgent string `json:"userAgent,omitempty"`
59+
Debug bool `json:"debug,omitempty"`
5960
HTTPClient *http.Client
6061
}
6162

@@ -65,6 +66,7 @@ func NewConfiguration() *Configuration {
6566
BasePath: "http://petstore.swagger.io:80/v2",
6667
DefaultHeader: make(map[string]string),
6768
UserAgent: "OpenAPI-Generator/1.0.0/go",
69+
Debug: false,
6870
}
6971
return cfg
7072
}

0 commit comments

Comments
 (0)