summaryrefslogtreecommitdiff
path: root/page/default.go
diff options
context:
space:
mode:
Diffstat (limited to 'page/default.go')
-rw-r--r--page/default.go88
1 files changed, 88 insertions, 0 deletions
diff --git a/page/default.go b/page/default.go
new file mode 100644
index 0000000..ea51acc
--- /dev/null
+++ b/page/default.go
@@ -0,0 +1,88 @@
+package page
+
+import (
+ "strings"
+ "text/template"
+)
+
+
+type page struct {
+ Title string
+ Body string
+}
+
+
+func buildPage(p page) (string, error) {
+ t, err := template.New("").Parse(`
+<!doctype html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1">
+ <title>{{ .Title }}</title>
+ </head>
+ <body>
+ {{ .Body }}
+ </body>
+</html>
+ `)
+ 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() (string, error) {
+ return buildPage(page{
+ Title: "Login",
+ Body: `
+ <form method="post">
+ <label for="username">Username</label>
+ <input type="text" id="username" name="username">
+ <br>
+ <label for="password">Password</label>
+ <input type="text" id="password" name="password">
+ <br>
+ <input type="submit" value="Submit">
+ </form>
+ `,
+ })
+}
+
+
+func DefaultLoggedIn() (string, error) {
+ return buildPage(page{
+ Title: "Logged In",
+ Body: `
+ <h1>You are logged in.</h1>
+ <form method="get" action="/phlox/logout">
+ <input type="submit" value="Log Out">
+ </form>
+ `,
+ })
+}
+
+
+func DefaultError404() (string, error) {
+ return buildPage(page{
+ Title: "404 Not Found",
+ Body: "<h1>Error 404: Page not found</h1>",
+ })
+}
+
+
+func DefaultError500() (string, error) {
+ return buildPage(page{
+ Title: "500 Not Found",
+ Body: "<h1>Error 500: Page not found</h1>",
+ })
+}