From 316c2cb136e02ae325572f987f469fe2ac8cbfd0 Mon Sep 17 00:00:00 2001 From: Guo Huang Date: Thu, 7 Apr 2016 22:16:31 -0700 Subject: [PATCH] added Configuration struct for GO --- .../codegen/languages/GoClientCodegen.java | 1 + .../src/main/resources/go/api.mustache | 12 ++++++--- .../main/resources/go/configuration.mustache | 25 +++++++++++++++++++ .../petstore/go/swagger/Configuration.go | 25 +++++++++++++++++++ 4 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 modules/swagger-codegen/src/main/resources/go/configuration.mustache create mode 100644 samples/client/petstore/go/swagger/Configuration.go diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/GoClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/GoClientCodegen.java index 007b3a8f36b8..234bda9adb78 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/GoClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/GoClientCodegen.java @@ -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 diff --git a/modules/swagger-codegen/src/main/resources/go/api.mustache b/modules/swagger-codegen/src/main/resources/go/api.mustache index 49b7f92693e3..d1cf877cd439 100644 --- a/modules/swagger-codegen/src/main/resources/go/api.mustache +++ b/modules/swagger-codegen/src/main/resources/go/api.mustache @@ -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}}" diff --git a/modules/swagger-codegen/src/main/resources/go/configuration.mustache b/modules/swagger-codegen/src/main/resources/go/configuration.mustache new file mode 100644 index 000000000000..bf3a8f92bed0 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/go/configuration.mustache @@ -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, + } +} \ No newline at end of file diff --git a/samples/client/petstore/go/swagger/Configuration.go b/samples/client/petstore/go/swagger/Configuration.go new file mode 100644 index 000000000000..7535db5e67f6 --- /dev/null +++ b/samples/client/petstore/go/swagger/Configuration.go @@ -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, + } +} \ No newline at end of file