2020-05-20 10:43:12 +02:00
|
|
|
package route
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2022-08-02 11:48:42 +02:00
|
|
|
"forge.cadoles.com/wpetit/goweb-oidc/internal/config"
|
2020-05-20 10:43:12 +02:00
|
|
|
"github.com/pkg/errors"
|
|
|
|
"gitlab.com/wpetit/goweb/middleware/container"
|
2022-08-02 11:48:42 +02:00
|
|
|
"gitlab.com/wpetit/goweb/service"
|
2020-05-20 10:43:12 +02:00
|
|
|
"gitlab.com/wpetit/goweb/service/template"
|
|
|
|
"gitlab.com/wpetit/goweb/template/html"
|
|
|
|
)
|
|
|
|
|
|
|
|
func extendTemplateData(w http.ResponseWriter, r *http.Request, data template.Data) template.Data {
|
|
|
|
ctn := container.Must(r.Context())
|
|
|
|
data, err := template.Extend(data,
|
|
|
|
html.WithFlashes(w, r, ctn),
|
|
|
|
template.WithBuildInfo(w, r, ctn),
|
2022-08-02 11:48:42 +02:00
|
|
|
withBaseURL(w, r, ctn),
|
2020-05-20 10:43:12 +02:00
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
panic(errors.Wrap(err, "could not extend template data"))
|
|
|
|
}
|
|
|
|
|
|
|
|
return data
|
|
|
|
}
|
2022-08-02 11:48:42 +02:00
|
|
|
|
|
|
|
func withBaseURL(w http.ResponseWriter, r *http.Request, ctn *service.Container) template.DataExtFunc {
|
|
|
|
return func(data template.Data) (template.Data, error) {
|
|
|
|
conf, err := config.From(ctn)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
data["BaseURL"] = conf.HTTP.PublicBaseURL
|
|
|
|
return data, nil
|
|
|
|
}
|
|
|
|
}
|