router_static.go: use a common path string
This commit is contained in:
parent
03f075e75a
commit
a565f34842
@ -72,23 +72,21 @@ func initStaticRouter(router *mux.Router) error {
|
|||||||
|
|
||||||
t, err := template.New(page).Delims("<<<", ">>>").Parse(string(contents))
|
t, err := template.New(page).Delims("<<<", ">>>").Parse(string(contents))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Errorf("cannot parse %s.html template: %v", page, err)
|
logger.Errorf("cannot parse /%s template: %v", page, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
t.Execute(&buf, &staticHtmlPlugs{CdnPrefix: os.Getenv("CDN_PREFIX")})
|
t.Execute(&buf, &staticHtmlPlugs{CdnPrefix: os.Getenv("CDN_PREFIX")})
|
||||||
|
|
||||||
html[page] = buf.String()
|
html["/" + page] = buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, page := range pages {
|
for _, page := range pages {
|
||||||
router.HandleFunc("/"+page, func(w http.ResponseWriter, r *http.Request) {
|
router.HandleFunc("/" + page, func(w http.ResponseWriter, r *http.Request) {
|
||||||
fmt.Fprintf(w, html[page])
|
fmt.Fprint(w, html[r.URL.Path])
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
router.HandleFunc("/", redirectLogin).Methods("GET")
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user