Skip to content

Commit e78fbd2

Browse files
committed
fix race condition
1 parent ca07540 commit e78fbd2

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

swagger.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"html/template"
66
"net/http"
77
"regexp"
8+
"sync"
89

910
"github.com/gobuffalo/buffalo"
1011
"github.com/swaggo/swag"
@@ -13,6 +14,8 @@ import (
1314

1415
// WrapHandler wraps `http.Handler` into `buffalo.Handler`.
1516
func WrapHandler(h *webdav.Handler) buffalo.Handler {
17+
var once sync.Once
18+
1619
//create a template with name
1720
t := template.New("swagger_index.html")
1821
index, _ := t.Parse(swagger_index_templ)
@@ -29,8 +32,10 @@ func WrapHandler(h *webdav.Handler) buffalo.Handler {
2932
return c.Error(http.StatusNotFound, errors.New("404 page not found"))
3033
}
3134
path := matches[2]
32-
prefix := matches[1]
33-
h.Prefix = prefix
35+
36+
once.Do(func() {
37+
h.Prefix = matches[1]
38+
})
3439

3540
switch path {
3641
case "index.html":
@@ -51,8 +56,8 @@ func WrapHandler(h *webdav.Handler) buffalo.Handler {
5156
h.ServeHTTP(c.Response(), c.Request())
5257
default:
5358
h.ServeHTTP(c.Response(), c.Request())
54-
5559
}
60+
5661
return nil
5762
}
5863
return fn

0 commit comments

Comments
 (0)