summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Lemon <y@yulqen.org>2024-02-08 16:54:02 +0000
committerMatthew Lemon <y@yulqen.org>2024-02-08 16:54:02 +0000
commitced9bbed371d7a1d7692c820f80c77f43ebd32a3 (patch)
tree896ef80f261b81049ac18797e7b0c3ae89c0837f
parent4bcba90a1a78cac4ec2ed370bb751d95717b7120 (diff)
Created a /organisations/list route
There is also some basic CSS here. Also introduced a proper structured logger.
-rw-r--r--cmd/web/handlers.go21
-rw-r--r--cmd/web/main.go14
-rw-r--r--cmd/web/routes.go4
-rw-r--r--ui/html/base.tmpl.html3
-rw-r--r--ui/html/pages/home.tmpl.html2
-rw-r--r--ui/html/pages/organisations/list.tmpl.html6
-rw-r--r--ui/static/css/main.css46
7 files changed, 91 insertions, 5 deletions
diff --git a/cmd/web/handlers.go b/cmd/web/handlers.go
index fd70c5e..8df8928 100644
--- a/cmd/web/handlers.go
+++ b/cmd/web/handlers.go
@@ -18,11 +18,30 @@ func (app *application) serverError(w http.ResponseWriter, r *http.Request, err
trace = string(debug.Stack())
)
- // TODO: reintroduce: app.logger.Error(err.Error(), "method", method, "uri", uri, "trace", trace)
+ app.logger.Error(err.Error(), "method", method, "uri", uri, "trace", trace)
log.Printf("Crash! %s %s %s", method, uri, trace)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
}
+func (app *application) listOrganisation(w http.ResponseWriter, r *http.Request) {
+ files := []string{
+ "./ui/html/base.tmpl.html",
+ "./ui/html/pages/organisations/list.tmpl.html",
+ // "./ui/html/partials/nav.tmpl.html",
+ }
+
+ ts, err := template.ParseFiles(files...)
+ if err != nil {
+ app.serverError(w, r, err) // Use the serverError() helper
+ return
+ }
+
+ err = ts.ExecuteTemplate(w, "base", nil)
+ if err != nil {
+ app.serverError(w, r, err) // Use the serverError() helper
+ }
+}
+
func (app *application) home(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/" {
app.notFound(w)
diff --git a/cmd/web/main.go b/cmd/web/main.go
index bd7e500..d388364 100644
--- a/cmd/web/main.go
+++ b/cmd/web/main.go
@@ -2,16 +2,24 @@ package main
import (
"log"
+ "log/slog"
"net/http"
+ "os"
)
-type application struct{}
+type application struct {
+ logger *slog.Logger
+}
func main() {
- app := &application{}
+ logger := slog.New(slog.NewTextHandler(os.Stdout, nil))
+ app := &application{
+ logger: logger,
+ }
// mux := http.NewServeMux()
// mux.HandleFunc("/", home)
- log.Print("starting server on :4000")
+ // log.Print("starting server on :4000")
+ logger.Info("starting server on :4000")
err := http.ListenAndServe(":4000", app.routes())
log.Fatal(err)
}
diff --git a/cmd/web/routes.go b/cmd/web/routes.go
index 2761d99..7e3aabd 100644
--- a/cmd/web/routes.go
+++ b/cmd/web/routes.go
@@ -5,6 +5,10 @@ import "net/http"
func (app *application) routes() *http.ServeMux {
mux := http.NewServeMux()
+ fileServer := http.FileServer(http.Dir("./ui/static/"))
+ mux.Handle("/static/", http.StripPrefix("/static", fileServer))
+
mux.HandleFunc("/", app.home)
+ mux.HandleFunc("/organisation/list", app.listOrganisation)
return mux
}
diff --git a/ui/html/base.tmpl.html b/ui/html/base.tmpl.html
index f7f7e48..cb98c32 100644
--- a/ui/html/base.tmpl.html
+++ b/ui/html/base.tmpl.html
@@ -4,6 +4,9 @@
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width" />
+ <link rel="stylesheet" href="/static/css/main.css">
+ <link rel="shortcut icon" href="/static/img/favicon.ico", type='image/x-icon'>
+ <!-- <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Ubuntu+Mono:400,700"> -->
<title>{{ template "title" .}} - DED</title>
</head>
<body>
diff --git a/ui/html/pages/home.tmpl.html b/ui/html/pages/home.tmpl.html
index 882a3ba..03be3ce 100644
--- a/ui/html/pages/home.tmpl.html
+++ b/ui/html/pages/home.tmpl.html
@@ -1,4 +1,4 @@
-{{define "title"}}Home{{end}}
+{{ define "title"}}Home{{ end }}
{{ define "main" }}
<h2>Data</h2>
diff --git a/ui/html/pages/organisations/list.tmpl.html b/ui/html/pages/organisations/list.tmpl.html
new file mode 100644
index 0000000..b29d7a6
--- /dev/null
+++ b/ui/html/pages/organisations/list.tmpl.html
@@ -0,0 +1,6 @@
+{{ define "title" }}Organisations{{end}}
+
+{{ define "main" }}
+<h2>Organisations</h2>
+<p>There is nothing to see here yet.</p>
+{{ end }}
diff --git a/ui/static/css/main.css b/ui/static/css/main.css
new file mode 100644
index 0000000..3d85763
--- /dev/null
+++ b/ui/static/css/main.css
@@ -0,0 +1,46 @@
+* {
+ box-sizing: border-box;
+ margin: 0;
+ padding: 0;
+ font-size: 18px;
+ /* font-family: "Ubuntu Mono", monospace; */
+}
+
+/* By default, these elements only expand to the height of their content. However, by setting their height to 100%, they will take up the entire height of the viewport, ensuring that they fill the entire visible area of the browser window regardless of the content size. This can be useful for creating layouts where elements need to stretch to the full height of the screen, such as in a full-page background or a layout with a sticky footer. */
+html, body {
+ height: 100%;
+}
+
+body {
+ line-height: 1.2;
+ background-color: #e3f8fc;
+ color: #34495E;
+ overflow-y: scroll;
+}
+
+header, nav, main, footer {
+ padding: 2px 10px 0;
+}
+
+main {
+ margin-top: 54px;
+ margin-bottom: 54px;
+ min-height: calc(100vh - 345px);
+ overflow: auto;
+}
+
+h1 a {
+ font-size: 36px;
+ font-weight: bold;
+ /* background-image: url("/static/img/logo.png"); */
+ background-repeat: no-repeat;
+ background-position: 0px 0px;
+ height: 36px;
+ padding-left: 10px;
+ position: relative;
+}
+
+h1 a:hover {
+ text-decoration: none;
+ color: #34495E;
+}