added debug setter and getter in Go configuration

This commit is contained in:
Guo Huang 2016-04-20 22:36:32 -07:00
parent a2002d9148
commit e555b3ad34
5 changed files with 25 additions and 7 deletions

View File

@ -56,7 +56,7 @@ func (c *ApiClient) CallApi(path string, method string,
//set debug flag //set debug flag
configuration := NewConfiguration() configuration := NewConfiguration()
resty.SetDebug(configuration.Debug) resty.SetDebug(configuration.GetDebug())
request := prepareRequest(postBody, headerParams, queryParams, formParams,fileName,fileBytes) request := prepareRequest(postBody, headerParams, queryParams, formParams,fileName,fileBytes)

View File

@ -9,7 +9,7 @@ type Configuration struct {
Password string `json:"password,omitempty"` Password string `json:"password,omitempty"`
ApiKeyPrefix map[string] string `json:"apiKeyPrefix,omitempty"` ApiKeyPrefix map[string] string `json:"apiKeyPrefix,omitempty"`
ApiKey map[string] string `json:"apiKey,omitempty"` ApiKey map[string] string `json:"apiKey,omitempty"`
Debug bool `json:"debug,omitempty"` debug bool `json:"debug,omitempty"`
DebugFile string `json:"debugFile,omitempty"` DebugFile string `json:"debugFile,omitempty"`
OAuthToken string `json:"oAuthToken,omitempty"` OAuthToken string `json:"oAuthToken,omitempty"`
Timeout int `json:"timeout,omitempty"` Timeout int `json:"timeout,omitempty"`
@ -26,7 +26,7 @@ func NewConfiguration() *Configuration {
return &Configuration{ return &Configuration{
BasePath: "{{basePath}}", BasePath: "{{basePath}}",
UserName: "", UserName: "",
Debug: false, debug: false,
DefaultHeader: make(map[string]string), DefaultHeader: make(map[string]string),
ApiKey: make(map[string]string), ApiKey: make(map[string]string),
ApiKeyPrefix: make(map[string]string), ApiKeyPrefix: make(map[string]string),
@ -48,4 +48,12 @@ func (c *Configuration) GetApiKeyWithPrefix(apiKeyIdentifier string) string {
} }
return c.ApiKey[apiKeyIdentifier] return c.ApiKey[apiKeyIdentifier]
}
func (c *Configuration) SetDebug(enable bool){
c.debug = enable
}
func (c *Configuration) GetDebug() bool {
return c.debug
} }

View File

@ -56,7 +56,7 @@ func (c *ApiClient) CallApi(path string, method string,
//set debug flag //set debug flag
configuration := NewConfiguration() configuration := NewConfiguration()
resty.SetDebug(configuration.Debug) resty.SetDebug(configuration.GetDebug())
request := prepareRequest(postBody, headerParams, queryParams, formParams,fileName,fileBytes) request := prepareRequest(postBody, headerParams, queryParams, formParams,fileName,fileBytes)
@ -134,7 +134,7 @@ func prepareRequest(postBody interface{},
} }
if len(fileBytes) > 0 && fileName != "" { if len(fileBytes) > 0 && fileName != "" {
_, fileNm := filepath.Split(fileName) _, fileNm := filepath.Split(fileName)
request.SetFileReader("file", fileNm, bytes.NewReader(fileBytes)) request.SetFileReader("file", fileNm, bytes.NewReader(fileBytes))
} }
return request return request

View File

@ -9,7 +9,7 @@ type Configuration struct {
Password string `json:"password,omitempty"` Password string `json:"password,omitempty"`
ApiKeyPrefix map[string] string `json:"apiKeyPrefix,omitempty"` ApiKeyPrefix map[string] string `json:"apiKeyPrefix,omitempty"`
ApiKey map[string] string `json:"apiKey,omitempty"` ApiKey map[string] string `json:"apiKey,omitempty"`
Debug bool `json:"debug,omitempty"` debug bool `json:"debug,omitempty"`
DebugFile string `json:"debugFile,omitempty"` DebugFile string `json:"debugFile,omitempty"`
OAuthToken string `json:"oAuthToken,omitempty"` OAuthToken string `json:"oAuthToken,omitempty"`
Timeout int `json:"timeout,omitempty"` Timeout int `json:"timeout,omitempty"`
@ -26,7 +26,7 @@ func NewConfiguration() *Configuration {
return &Configuration{ return &Configuration{
BasePath: "http://petstore.swagger.io/v2", BasePath: "http://petstore.swagger.io/v2",
UserName: "", UserName: "",
Debug: false, debug: false,
DefaultHeader: make(map[string]string), DefaultHeader: make(map[string]string),
ApiKey: make(map[string]string), ApiKey: make(map[string]string),
ApiKeyPrefix: make(map[string]string), ApiKeyPrefix: make(map[string]string),
@ -48,4 +48,12 @@ func (c *Configuration) GetApiKeyWithPrefix(apiKeyIdentifier string) string {
} }
return c.ApiKey[apiKeyIdentifier] return c.ApiKey[apiKeyIdentifier]
}
func (c *Configuration) SetDebug(enable bool){
c.debug = enable
}
func (c *Configuration) GetDebug() bool {
return c.debug
} }

View File

@ -25,4 +25,6 @@ func main() {
resp, err, apiResponse := s.GetPetById(12830) resp, err, apiResponse := s.GetPetById(12830)
fmt.Println("GetPetById: ", resp, err, apiResponse) fmt.Println("GetPetById: ", resp, err, apiResponse)
err2, apiResponse2 := s.DeletePet(12830, "")
fmt.Println("DeletePet: ", err2, apiResponse2)
} }