package page
import (
"strings"
"text/template"
"sanine.net/git/phlox/config"
)
type page struct {
Title string
Head string
FormMethod string
FormAction string
FormBody string
}
func buildPage(p page) (string, error) {
t, err := template.New("").Parse(`
{{ .Title }}
{{ .Head }}
{{ if .FormBody }}
{{ end }}
`)
if err != nil {
return "", err
}
var b strings.Builder
err = t.Execute(&b, p)
if err != nil {
return "", err
}
return b.String(), nil
}
func DefaultLogin(api config.Api) (string, error) {
return buildPage(page{
Title: "Login",
Head : "Log In",
FormMethod: "POST",
FormAction: api.Prefix + api.Login,
FormBody: `
`,
})
}
func DefaultLoggedIn(api config.Api) (string, error) {
return buildPage(page{
Title: "Logged In",
Head: "You are logged in.",
FormMethod: "GET",
FormAction: api.Prefix + api.Logout,
FormBody: ``,
})
}
func DefaultError404(api config.Api) (string, error) {
return buildPage(page{
Title: "404 Not Found",
Head: "Error 404: Page not found",
})
}
func DefaultError500(api config.Api) (string, error) {
return buildPage(page{
Title: "500 Internal Server Error",
Head: "Error 500: Internal server error",
})
}