1
0
mirror of https://github.com/oauth2-proxy/oauth2-proxy.git synced 2025-11-27 22:38:39 +02:00

support (optional) custom templates

This commit is contained in:
Jehiah Czebotar
2015-03-17 18:06:06 -04:00
parent b2dfbd8564
commit 2b2324e410
6 changed files with 27 additions and 6 deletions

View File

@@ -3,8 +3,21 @@ package main
import (
"html/template"
"log"
"path"
)
func loadTemplates(dir string) *template.Template {
if dir == "" {
return getTemplates()
}
log.Printf("using custom template directory %q", dir)
t, err := template.New("").ParseFiles(path.Join(dir, "sign_in.html"), path.Join(dir, "error.html"))
if err != nil {
log.Fatalf("failed parsing template %s", err)
}
return t
}
func getTemplates() *template.Template {
t, err := template.New("foo").Parse(`{{define "sign_in.html"}}
<!DOCTYPE html>
@@ -123,7 +136,7 @@ func getTemplates() *template.Template {
</html>
{{end}}`)
if err != nil {
log.Fatalf("failed parsing template %s", err.Error())
log.Fatalf("failed parsing template %s", err)
}
t, err = t.Parse(`{{define "error.html"}}
@@ -141,7 +154,7 @@ func getTemplates() *template.Template {
</body>
</html>{{end}}`)
if err != nil {
log.Fatalf("failed parsing template %s", err.Error())
log.Fatalf("failed parsing template %s", err)
}
return t
}