-
Notifications
You must be signed in to change notification settings - Fork 426
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from swagger-api/master
Update fork
- v1.0.55
- v1.0.54
- v1.0.52
- v1.0.51
- v1.0.50
- v1.0.49
- v1.0.48
- v1.0.47
- v1.0.46
- v1.0.45
- v1.0.44
- v1.0.43
- v1.0.42
- v1.0.41
- v1.0.40
- v1.0.39
- v1.0.38
- v1.0.37
- v1.0.36
- v1.0.35
- v1.0.34
- v1.0.32
- v1.0.31
- v1.0.30
- v1.0.29
- v1.0.28
- v1.0.27
- v1.0.26
- v1.0.25
- v1.0.24
- v1.0.23
- v1.0.22
- v1.0.21
- v1.0.20
- v1.0.19
- v1.0.18
- v1.0.17
- V1.0.53
Showing
25 changed files
with
1,128 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
530 changes: 530 additions & 0 deletions
530
src/main/java/io/swagger/codegen/v3/generators/go/AbstractGoCodegen.java
Large diffs are not rendered by default.
Oops, something went wrong.
163 changes: 163 additions & 0 deletions
163
src/main/java/io/swagger/codegen/v3/generators/go/GoServerCodegen.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
package io.swagger.codegen.v3.generators.go; | ||
|
||
import io.swagger.codegen.v3.CodegenConstants; | ||
import io.swagger.codegen.v3.CodegenProperty; | ||
import io.swagger.codegen.v3.CodegenType; | ||
import io.swagger.codegen.v3.SupportingFile; | ||
import io.swagger.v3.oas.models.media.ArraySchema; | ||
import io.swagger.v3.oas.models.media.MapSchema; | ||
import io.swagger.v3.oas.models.media.Schema; | ||
|
||
import java.io.File; | ||
import java.util.Arrays; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
|
||
public class GoServerCodegen extends AbstractGoCodegen { | ||
|
||
protected String apiVersion = "1.0.0"; | ||
protected int serverPort = 8080; | ||
protected String projectName = "swagger-server"; | ||
protected String apiPath = "go"; | ||
|
||
public GoServerCodegen() { | ||
super(); | ||
|
||
// set the output folder here | ||
outputFolder = "generated-code/go"; | ||
|
||
/* | ||
* Models. You can write model files using the modelTemplateFiles map. | ||
* if you want to create one template for file, you can do so here. | ||
* for multiple files for model, just put another entry in the `modelTemplateFiles` with | ||
* a different extension | ||
*/ | ||
modelTemplateFiles.put( | ||
"model.mustache", | ||
".go"); | ||
|
||
/* | ||
* Api classes. You can write classes for each Api file with the apiTemplateFiles map. | ||
* as with models, add multiple entries with different extensions for multiple files per | ||
* class | ||
*/ | ||
apiTemplateFiles.put( | ||
"controller-api.mustache", // the template to use | ||
".go"); // the extension for each file to write | ||
|
||
/* | ||
* Reserved words. Override this with reserved words specific to your language | ||
*/ | ||
setReservedWordsLowerCase( | ||
Arrays.asList( | ||
// data type | ||
"string", "bool", "uint", "uint8", "uint16", "uint32", "uint64", | ||
"int", "int8", "int16", "int32", "int64", "float32", "float64", | ||
"complex64", "complex128", "rune", "byte", "uintptr", | ||
|
||
"break", "default", "func", "interface", "select", | ||
"case", "defer", "go", "map", "struct", | ||
"chan", "else", "goto", "package", "switch", | ||
"const", "fallthrough", "if", "range", "type", | ||
"continue", "for", "import", "return", "var", "error", "nil") | ||
// Added "error" as it's used so frequently that it may as well be a keyword | ||
); | ||
} | ||
|
||
@Override | ||
public String getDefaultTemplateDir() { | ||
return "go-server"; | ||
} | ||
|
||
@Override | ||
public void processOpts() { | ||
super.processOpts(); | ||
|
||
if (StringUtils.isBlank(templateDir)) { | ||
embeddedTemplateDir = templateDir = getTemplateDir(); | ||
} | ||
|
||
if (additionalProperties.containsKey(CodegenConstants.PACKAGE_NAME)) { | ||
setPackageName((String) additionalProperties.get(CodegenConstants.PACKAGE_NAME)); | ||
} | ||
else { | ||
setPackageName("swagger"); | ||
} | ||
|
||
/* | ||
* Additional Properties. These values can be passed to the templates and | ||
* are available in models, apis, and supporting files | ||
*/ | ||
additionalProperties.put("apiVersion", apiVersion); | ||
additionalProperties.put("serverPort", serverPort); | ||
additionalProperties.put("apiPath", apiPath); | ||
additionalProperties.put(CodegenConstants.PACKAGE_NAME, packageName); | ||
|
||
modelPackage = packageName; | ||
apiPackage = packageName; | ||
|
||
/* | ||
* Supporting Files. You can write single files for the generator with the | ||
* entire object tree available. If the input file has a suffix of `.mustache | ||
* it will be processed by the template engine. Otherwise, it will be copied | ||
*/ | ||
supportingFiles.add(new SupportingFile("swagger.mustache", "api", "swagger.yaml")); | ||
supportingFiles.add(new SupportingFile("main.mustache", "", "main.go")); | ||
supportingFiles.add(new SupportingFile("routers.mustache", apiPath, "routers.go")); | ||
supportingFiles.add(new SupportingFile("logger.mustache", apiPath, "logger.go")); | ||
writeOptional(outputFolder, new SupportingFile("README.mustache", apiPath, "README.md")); | ||
} | ||
|
||
@Override | ||
public String apiPackage() { | ||
return apiPath; | ||
} | ||
|
||
/** | ||
* Configures the type of generator. | ||
* | ||
* @return the CodegenType for this generator | ||
* @see io.swagger.codegen.CodegenType | ||
*/ | ||
@Override | ||
public CodegenType getTag() { | ||
return CodegenType.SERVER; | ||
} | ||
|
||
/** | ||
* Configures a friendly name for the generator. This will be used by the generator | ||
* to select the library with the -l flag. | ||
* | ||
* @return the friendly name for the generator | ||
*/ | ||
@Override | ||
public String getName() { | ||
return "go-server"; | ||
} | ||
|
||
/** | ||
* Returns human-friendly help for the generator. Provide the consumer with help | ||
* tips, parameters here | ||
* | ||
* @return A string value for the help message | ||
*/ | ||
@Override | ||
public String getHelp() { | ||
return "Generates a Go server library using the swagger-tools project. By default, " + | ||
"it will also generate service classes--which you can disable with the `-Dnoservice` environment variable."; | ||
} | ||
|
||
/** | ||
* Location to write api files. You can use the apiPackage() as defined when the class is | ||
* instantiated | ||
*/ | ||
@Override | ||
public String apiFileFolder() { | ||
return outputFolder + File.separator + apiPackage().replace('.', File.separatorChar); | ||
} | ||
|
||
@Override | ||
public String modelFileFolder() { | ||
return outputFolder + File.separator + apiPackage().replace('.', File.separatorChar); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
src/main/resources/META-INF/services/io.swagger.codegen.v3.CodegenConfig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Go API Server for {{packageName}} | ||
|
||
{{#appDescription}} | ||
{{{appDescription}}} | ||
{{/appDescription}} | ||
|
||
## Overview | ||
This server was generated by the [swagger-codegen] | ||
(https://github.com/swagger-api/swagger-codegen) project. | ||
By using the [OpenAPI-Spec](https://github.com/OAI/OpenAPI-Specification) from a remote server, you can easily generate a server stub. | ||
- | ||
|
||
To see how to make this your own, look here: | ||
|
||
[README](https://github.com/swagger-api/swagger-codegen/blob/master/README.md) | ||
|
||
- API version: {{appVersion}}{{^hideGenerationTimestamp}} | ||
- Build date: {{generatedDate}}{{/hideGenerationTimestamp}} | ||
{{#infoUrl}} | ||
For more information, please visit [{{{infoUrl}}}]({{{infoUrl}}}) | ||
{{/infoUrl}} | ||
|
||
|
||
### Running the server | ||
To run the server, follow these simple steps: | ||
|
||
``` | ||
go run main.go | ||
``` | ||
|
12 changes: 12 additions & 0 deletions
12
src/main/resources/handlebars/go-server/controller-api.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{{>partial_header}} | ||
package {{packageName}} | ||
|
||
{{#operations}} | ||
import ( | ||
"net/http" | ||
){{#operation}} | ||
|
||
func {{nickname}}(w http.ResponseWriter, r *http.Request) { | ||
w.Header().Set("Content-Type", "application/json; charset=UTF-8") | ||
w.WriteHeader(http.StatusOK) | ||
}{{/operation}}{{/operations}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{{>partial_header}} | ||
package {{packageName}} | ||
|
||
import ( | ||
"log" | ||
"net/http" | ||
"time" | ||
) | ||
|
||
func Logger(inner http.Handler, name string) http.Handler { | ||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
start := time.Now() | ||
inner.ServeHTTP(w, r) | ||
log.Printf( | ||
"%s %s %s %s", | ||
r.Method, | ||
r.RequestURI, | ||
name, | ||
time.Since(start), | ||
) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{{>partial_header}} | ||
package main | ||
|
||
import ( | ||
"log" | ||
"net/http" | ||
|
||
// WARNING! | ||
// Change this to a fully-qualified import path | ||
// once you place this file into your project. | ||
// For example, | ||
// | ||
// sw "github.com/myname/myrepo/{{apiPath}}" | ||
// | ||
sw "./{{apiPath}}" | ||
) | ||
|
||
func main() { | ||
log.Printf("Server started") | ||
router := sw.NewRouter() | ||
log.Fatal(http.ListenAndServe(":{{serverPort}}", router)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{{>partial_header}} | ||
package {{packageName}} | ||
{{#models}}{{#imports}} | ||
import ({{/imports}}{{#imports}} | ||
"{{import}}"{{/imports}}{{#imports}} | ||
) | ||
{{/imports}}{{#model}}{{#isEnum}}{{#description}}// {{{classname}}} : {{{description}}}{{/description}} | ||
type {{{name}}} {{^format}}{{dataType}}{{/format}}{{#format}}{{{format}}}{{/format}} | ||
|
||
// List of {{{name}}} | ||
const ( | ||
{{#allowableValues}} | ||
{{#enumVars}} | ||
{{name}} {{{classname}}} = "{{{value}}}" | ||
{{/enumVars}} | ||
{{/allowableValues}} | ||
){{/isEnum}}{{^isEnum}}{{#description}} | ||
// {{{description}}}{{/description}} | ||
type {{classname}} struct { | ||
{{#vars}}{{#description}} | ||
// {{{description}}}{{/description}} | ||
{{name}} {{^isEnum}}{{^isPrimitiveType}}{{^isContainer}}{{^isDateTime}}*{{/isDateTime}}{{/isContainer}}{{/isPrimitiveType}}{{/isEnum}}{{{datatype}}} `json:"{{baseName}}{{^required}},omitempty{{/required}}"` | ||
{{/vars}} | ||
}{{/isEnum}}{{/model}}{{/models}} |
17 changes: 17 additions & 0 deletions
17
src/main/resources/handlebars/go-server/partial_header.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
{{#appName}} | ||
* {{{appName}}} | ||
* | ||
{{/appName}} | ||
{{#appDescription}} | ||
* {{{appDescription}}} | ||
* | ||
{{/appDescription}} | ||
{{#version}} | ||
* API version: {{{version}}} | ||
{{/version}} | ||
{{#infoEmail}} | ||
* Contact: {{{infoEmail}}} | ||
{{/infoEmail}} | ||
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
{{>partial_header}} | ||
package {{packageName}} | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"strings" | ||
|
||
"github.com/gorilla/mux" | ||
) | ||
|
||
type Route struct { | ||
Name string | ||
Method string | ||
Pattern string | ||
HandlerFunc http.HandlerFunc | ||
} | ||
|
||
type Routes []Route | ||
|
||
func NewRouter() *mux.Router { | ||
router := mux.NewRouter().StrictSlash(true) | ||
for _, route := range routes { | ||
var handler http.Handler | ||
handler = route.HandlerFunc | ||
handler = Logger(handler, route.Name) | ||
router. | ||
Methods(route.Method). | ||
Path(route.Pattern). | ||
Name(route.Name). | ||
Handler(handler) | ||
} | ||
|
||
return router | ||
} | ||
|
||
func Index(w http.ResponseWriter, r *http.Request) { | ||
fmt.Fprintf(w, "Hello World!") | ||
} | ||
|
||
var routes = Routes{ | ||
Route{ | ||
"Index", | ||
"GET", | ||
"{{{basePathWithoutHost}}}/", | ||
Index, | ||
},{{#apiInfo}}{{#apis}}{{#operations}}{{#operation}} | ||
|
||
Route{ | ||
"{{operationId}}", | ||
strings.ToUpper("{{httpMethod}}"), | ||
"{{{basePathWithoutHost}}}{{{path}}}", | ||
{{operationId}}, | ||
},{{/operation}}{{/operations}}{{/apis}}{{/apiInfo}} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{{{swagger-yaml}}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Go API Server for {{packageName}} | ||
|
||
{{#appDescription}} | ||
{{{appDescription}}} | ||
{{/appDescription}} | ||
|
||
## Overview | ||
This server was generated by the [swagger-codegen] | ||
(https://github.com/swagger-api/swagger-codegen) project. | ||
By using the [OpenAPI-Spec](https://github.com/OAI/OpenAPI-Specification) from a remote server, you can easily generate a server stub. | ||
- | ||
|
||
To see how to make this your own, look here: | ||
|
||
[README](https://github.com/swagger-api/swagger-codegen/blob/master/README.md) | ||
|
||
- API version: {{appVersion}}{{^hideGenerationTimestamp}} | ||
- Build date: {{generatedDate}}{{/hideGenerationTimestamp}} | ||
{{#infoUrl}} | ||
For more information, please visit [{{{infoUrl}}}]({{{infoUrl}}}) | ||
{{/infoUrl}} | ||
|
||
|
||
### Running the server | ||
To run the server, follow these simple steps: | ||
|
||
``` | ||
go run main.go | ||
``` | ||
|
12 changes: 12 additions & 0 deletions
12
src/main/resources/mustache/go-server/controller-api.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{{>partial_header}} | ||
package {{packageName}} | ||
|
||
{{#operations}} | ||
import ( | ||
"net/http" | ||
){{#operation}} | ||
|
||
func {{nickname}}(w http.ResponseWriter, r *http.Request) { | ||
w.Header().Set("Content-Type", "application/json; charset=UTF-8") | ||
w.WriteHeader(http.StatusOK) | ||
}{{/operation}}{{/operations}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{{>partial_header}} | ||
package {{packageName}} | ||
|
||
import ( | ||
"log" | ||
"net/http" | ||
"time" | ||
) | ||
|
||
func Logger(inner http.Handler, name string) http.Handler { | ||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
start := time.Now() | ||
inner.ServeHTTP(w, r) | ||
log.Printf( | ||
"%s %s %s %s", | ||
r.Method, | ||
r.RequestURI, | ||
name, | ||
time.Since(start), | ||
) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{{>partial_header}} | ||
package main | ||
|
||
import ( | ||
"log" | ||
"net/http" | ||
|
||
// WARNING! | ||
// Change this to a fully-qualified import path | ||
// once you place this file into your project. | ||
// For example, | ||
// | ||
// sw "github.com/myname/myrepo/{{apiPath}}" | ||
// | ||
sw "./{{apiPath}}" | ||
) | ||
|
||
func main() { | ||
log.Printf("Server started") | ||
router := sw.NewRouter() | ||
log.Fatal(http.ListenAndServe(":{{serverPort}}", router)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{{>partial_header}} | ||
package {{packageName}} | ||
{{#models}}{{#imports}} | ||
import ({{/imports}}{{#imports}} | ||
"{{import}}"{{/imports}}{{#imports}} | ||
) | ||
{{/imports}}{{#model}}{{#isEnum}}{{#description}}// {{{classname}}} : {{{description}}}{{/description}} | ||
type {{{name}}} {{^format}}{{dataType}}{{/format}}{{#format}}{{{format}}}{{/format}} | ||
|
||
// List of {{{name}}} | ||
const ( | ||
{{#allowableValues}} | ||
{{#enumVars}} | ||
{{name}} {{{classname}}} = "{{{value}}}" | ||
{{/enumVars}} | ||
{{/allowableValues}} | ||
){{/isEnum}}{{^isEnum}}{{#description}} | ||
// {{{description}}}{{/description}} | ||
type {{classname}} struct { | ||
{{#vars}}{{#description}} | ||
// {{{description}}}{{/description}} | ||
{{name}} {{^isEnum}}{{^isPrimitiveType}}{{^isContainer}}{{^isDateTime}}*{{/isDateTime}}{{/isContainer}}{{/isPrimitiveType}}{{/isEnum}}{{{datatype}}} `json:"{{baseName}}{{^required}},omitempty{{/required}}"` | ||
{{/vars}} | ||
}{{/isEnum}}{{/model}}{{/models}} |
17 changes: 17 additions & 0 deletions
17
src/main/resources/mustache/go-server/partial_header.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
{{#appName}} | ||
* {{{appName}}} | ||
* | ||
{{/appName}} | ||
{{#appDescription}} | ||
* {{{appDescription}}} | ||
* | ||
{{/appDescription}} | ||
{{#version}} | ||
* API version: {{{version}}} | ||
{{/version}} | ||
{{#infoEmail}} | ||
* Contact: {{{infoEmail}}} | ||
{{/infoEmail}} | ||
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
{{>partial_header}} | ||
package {{packageName}} | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"strings" | ||
|
||
"github.com/gorilla/mux" | ||
) | ||
|
||
type Route struct { | ||
Name string | ||
Method string | ||
Pattern string | ||
HandlerFunc http.HandlerFunc | ||
} | ||
|
||
type Routes []Route | ||
|
||
func NewRouter() *mux.Router { | ||
router := mux.NewRouter().StrictSlash(true) | ||
for _, route := range routes { | ||
var handler http.Handler | ||
handler = route.HandlerFunc | ||
handler = Logger(handler, route.Name) | ||
router. | ||
Methods(route.Method). | ||
Path(route.Pattern). | ||
Name(route.Name). | ||
Handler(handler) | ||
} | ||
|
||
return router | ||
} | ||
|
||
func Index(w http.ResponseWriter, r *http.Request) { | ||
fmt.Fprintf(w, "Hello World!") | ||
} | ||
|
||
var routes = Routes{ | ||
Route{ | ||
"Index", | ||
"GET", | ||
"{{{basePathWithoutHost}}}/", | ||
Index, | ||
},{{#apiInfo}}{{#apis}}{{#operations}}{{#operation}} | ||
|
||
Route{ | ||
"{{operationId}}", | ||
strings.ToUpper("{{httpMethod}}"), | ||
"{{{basePathWithoutHost}}}{{{path}}}", | ||
{{operationId}}, | ||
},{{/operation}}{{/operations}}{{/apis}}{{/apiInfo}} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{{{swagger-yaml}}} |