Skip to content

Commit

Permalink
fix race condition
Browse files Browse the repository at this point in the history
fix race condition
  • Loading branch information
ubogdan authored Oct 12, 2021
2 parents ca07540 + e78fbd2 commit d563780
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions swagger.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"html/template"
"net/http"
"regexp"
"sync"

"github.com/gobuffalo/buffalo"
"github.com/swaggo/swag"
Expand All @@ -13,6 +14,8 @@ import (

// WrapHandler wraps `http.Handler` into `buffalo.Handler`.
func WrapHandler(h *webdav.Handler) buffalo.Handler {
var once sync.Once

//create a template with name
t := template.New("swagger_index.html")
index, _ := t.Parse(swagger_index_templ)
Expand All @@ -29,8 +32,10 @@ func WrapHandler(h *webdav.Handler) buffalo.Handler {
return c.Error(http.StatusNotFound, errors.New("404 page not found"))
}
path := matches[2]
prefix := matches[1]
h.Prefix = prefix

once.Do(func() {
h.Prefix = matches[1]
})

switch path {
case "index.html":
Expand All @@ -51,8 +56,8 @@ func WrapHandler(h *webdav.Handler) buffalo.Handler {
h.ServeHTTP(c.Response(), c.Request())
default:
h.ServeHTTP(c.Response(), c.Request())

}

return nil
}
return fn
Expand Down

0 comments on commit d563780

Please sign in to comment.