added Configuration struct for GO

This commit is contained in:
Guo Huang 2016-04-07 22:16:31 -07:00
parent d84f848831
commit 316c2cb136
4 changed files with 59 additions and 4 deletions

View File

@ -131,6 +131,7 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig {
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore"));
supportingFiles.add(new SupportingFile("configuration.mustache", packageName, "Configuration.go"));
}
@Override

View File

@ -12,18 +12,22 @@ import (
)
type {{classname}} struct {
basePath string
Configuration Configuration
}
func New{{classname}}() *{{classname}}{
configuration := NewConfiguration()
return &{{classname}} {
basePath: "{{basePath}}",
Configuration: *configuration,
}
}
func New{{classname}}WithBasePath(basePath string) *{{classname}}{
configuration := NewConfiguration()
configuration.BasePath = basePath
return &{{classname}} {
basePath: basePath,
Configuration: *configuration,
}
}
@ -37,7 +41,7 @@ func New{{classname}}WithBasePath(basePath string) *{{classname}}{
//func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) ({{#returnType}}{{{returnType}}}, {{/returnType}}error) {
func (a {{classname}}) {{nickname}} ({{#allParams}}{{paramName}} {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) ({{#returnType}}{{{returnType}}}, {{/returnType}}error) {
_sling := sling.New().{{httpMethod}}(a.basePath)
_sling := sling.New().{{httpMethod}}(a.Configuration.BasePath)
// create path and map variables
path := "{{basePathWithoutHost}}{{path}}"

View File

@ -0,0 +1,25 @@
package {{packageName}}
import (
)
type Configuration struct {
UserName string `json:"userName,omitempty"`
ApiKey string `json:"apiKey,omitempty"`
Debug bool `json:"debug,omitempty"`
DebugFile string `json:"debugFile,omitempty"`
OAuthToken string `json:"oAuthToken,omitempty"`
Timeout int `json:"timeout,omitempty"`
BasePath string `json:"basePath,omitempty"`
Host string `json:"host,omitempty"`
Scheme string `json:"scheme,omitempty"`
}
func NewConfiguration() *Configuration {
return &Configuration{
BasePath: "{{basePath}}",
UserName: "",
Debug: false,
}
}

View File

@ -0,0 +1,25 @@
package swagger
import (
)
type Configuration struct {
UserName string `json:"userName,omitempty"`
ApiKey string `json:"apiKey,omitempty"`
Debug bool `json:"debug,omitempty"`
DebugFile string `json:"debugFile,omitempty"`
OAuthToken string `json:"oAuthToken,omitempty"`
Timeout int `json:"timeout,omitempty"`
BasePath string `json:"basePath,omitempty"`
Host string `json:"host,omitempty"`
Scheme string `json:"scheme,omitempty"`
}
func NewConfiguration() *Configuration {
return &Configuration{
BasePath: "http://petstore.swagger.io/v2",
UserName: "",
Debug: false,
}
}