forked from loafle/openapi-generator-original
update go samples
This commit is contained in:
parent
8cc7befbf3
commit
af3d862c5b
@ -17,8 +17,10 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"log"
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/http/httputil"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -175,7 +177,25 @@ func parameterToJson(obj interface{}) (string, error) {
|
|||||||
|
|
||||||
// callAPI do the request.
|
// callAPI do the request.
|
||||||
func (c *APIClient) callAPI(request *http.Request) (*http.Response, error) {
|
func (c *APIClient) callAPI(request *http.Request) (*http.Response, error) {
|
||||||
return c.cfg.HTTPClient.Do(request)
|
if c.cfg.Debug {
|
||||||
|
dump, err := httputil.DumpRequestOut(request, true)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
log.Printf("\n%s\n", string(dump))
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := c.cfg.HTTPClient.Do(request)
|
||||||
|
|
||||||
|
if c.cfg.Debug {
|
||||||
|
dump, err := httputil.DumpResponse(resp, true)
|
||||||
|
if err != nil {
|
||||||
|
return resp, err
|
||||||
|
}
|
||||||
|
log.Printf("\n%s\n", string(dump))
|
||||||
|
}
|
||||||
|
|
||||||
|
return resp, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// ChangeBasePath changes base path to allow switching to mocks
|
// ChangeBasePath changes base path to allow switching to mocks
|
||||||
|
@ -56,6 +56,7 @@ type Configuration struct {
|
|||||||
Scheme string `json:"scheme,omitempty"`
|
Scheme string `json:"scheme,omitempty"`
|
||||||
DefaultHeader map[string]string `json:"defaultHeader,omitempty"`
|
DefaultHeader map[string]string `json:"defaultHeader,omitempty"`
|
||||||
UserAgent string `json:"userAgent,omitempty"`
|
UserAgent string `json:"userAgent,omitempty"`
|
||||||
|
Debug bool `json:"debug,omitempty"`
|
||||||
HTTPClient *http.Client
|
HTTPClient *http.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,6 +66,7 @@ func NewConfiguration() *Configuration {
|
|||||||
BasePath: "http://petstore.swagger.io:80/v2",
|
BasePath: "http://petstore.swagger.io:80/v2",
|
||||||
DefaultHeader: make(map[string]string),
|
DefaultHeader: make(map[string]string),
|
||||||
UserAgent: "OpenAPI-Generator/1.0.0/go",
|
UserAgent: "OpenAPI-Generator/1.0.0/go",
|
||||||
|
Debug: false,
|
||||||
}
|
}
|
||||||
return cfg
|
return cfg
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user