Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to create EchoWrapHandler with specific API ID #39

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions swagger.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,20 @@ func URL(url string) func(c *Config) {
// WrapHandler wraps swaggerFiles.Handler and returns echo.HandlerFunc
var WrapHandler = EchoWrapHandler()

// EchoWrapHandler wraps `http.Handler` into `echo.HandlerFunc`.
// EchoWrapHandler is the same as EchoWrapHandlerName, but uses the default swag ID.
func EchoWrapHandler(confs ...func(c *Config)) echo.HandlerFunc {
return EchoWrapHandlerName(swag.Name, confs...)
}

// EchoWrapHandlerName wraps `http.Handler` into `echo.HandlerFunc` with a specific swag ID.
func EchoWrapHandlerName(swagID string, confs ...func(c *Config)) echo.HandlerFunc {

handler := swaggerFiles.Handler

config := &Config{
URL: "doc.json",
}

for _, c := range confs {
c(config)
}

// create a template with name
t := template.New("swagger_index.html")
index, _ := t.Parse(indexTempl)
Expand All @@ -64,7 +65,7 @@ func EchoWrapHandler(confs ...func(c *Config)) echo.HandlerFunc {

index.Execute(c.Response().Writer, config)
case "doc.json":
doc, _ := swag.ReadDoc()
doc, _ := swag.ReadDocName(swagID)
c.Response().Write([]byte(doc))
default:
handler.ServeHTTP(c.Response().Writer, c.Request())
Expand Down