Inherited templates, staticfiles
All checks were successful
Build and copy to prod / build-and-copy (push) Successful in 43s
All checks were successful
Build and copy to prod / build-and-copy (push) Successful in 43s
This commit is contained in:
parent
27f6d749d3
commit
701544df9c
13
main.go
13
main.go
@ -13,7 +13,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
//go:embed templates/*
|
//go:embed templates/*
|
||||||
var content embed.FS
|
var templates embed.FS
|
||||||
|
|
||||||
|
//go:embed static/*
|
||||||
|
var staticFiles embed.FS
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
db := data.Connect("test.sqlite3")
|
db := data.Connect("test.sqlite3")
|
||||||
@ -33,7 +36,7 @@ func main() {
|
|||||||
|
|
||||||
ping.SendPing(db, failureSite)
|
ping.SendPing(db, failureSite)
|
||||||
|
|
||||||
http.HandleFunc("GET /", func(w http.ResponseWriter, r *http.Request) {
|
http.HandleFunc("GET /{$}", func(w http.ResponseWriter, r *http.Request) {
|
||||||
pings := ping.ListGroupedBySite(db)
|
pings := ping.ListGroupedBySite(db)
|
||||||
|
|
||||||
if _, err := json.Marshal(pings); err != nil {
|
if _, err := json.Marshal(pings); err != nil {
|
||||||
@ -43,14 +46,16 @@ func main() {
|
|||||||
} else {
|
} else {
|
||||||
w.Header().Set("Content-Type", "text/html")
|
w.Header().Set("Content-Type", "text/html")
|
||||||
|
|
||||||
t, _ := template.ParseFS(content, "templates/index.html")
|
t, _ := template.ParseFS(templates, "templates/index.html", "templates/base.html", "templates/head.html")
|
||||||
t.Execute(w, nil)
|
t.Execute(w, nil)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
http.HandleFunc("POST /", func(w http.ResponseWriter, r *http.Request) {
|
http.HandleFunc("POST /{$}", func(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Write([]byte("This was a POST request!"))
|
w.Write([]byte("This was a POST request!"))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
http.Handle("/static/", http.FileServerFS(staticFiles))
|
||||||
|
|
||||||
http.ListenAndServe(":8000", nil)
|
http.ListenAndServe(":8000", nil)
|
||||||
}
|
}
|
||||||
|
80
static/reset.css
Normal file
80
static/reset.css
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
* Modern reset: https://piccalil.li/blog/a-modern-css-reset/ */
|
||||||
|
|
||||||
|
/* Box sizing rules */
|
||||||
|
*,
|
||||||
|
*::before,
|
||||||
|
*::after {
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Remove default margin */
|
||||||
|
body,
|
||||||
|
h1,
|
||||||
|
h2,
|
||||||
|
h3,
|
||||||
|
h4,
|
||||||
|
p,
|
||||||
|
figure,
|
||||||
|
blockquote,
|
||||||
|
dl,
|
||||||
|
dd {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Remove list styles on ul, ol elements with a list role, which suggests default styling will be removed */
|
||||||
|
[role='list']
|
||||||
|
{
|
||||||
|
list-style: none;
|
||||||
|
padding: 0;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set core root defaults */
|
||||||
|
html:focus-within {
|
||||||
|
scroll-behavior: smooth;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set core body defaults */
|
||||||
|
body {
|
||||||
|
min-height: 100vh;
|
||||||
|
min-height: 100dvh; /* safari-specific */
|
||||||
|
text-rendering: optimizeSpeed;
|
||||||
|
line-height: 1.75;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* A elements that don't have a class get default styles */
|
||||||
|
a:not([class]) {
|
||||||
|
text-decoration-skip-ink: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Make images easier to work with */
|
||||||
|
img,
|
||||||
|
picture {
|
||||||
|
max-width: 100%;
|
||||||
|
display: block;
|
||||||
|
height: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Inherit fonts for inputs and buttons */
|
||||||
|
input,
|
||||||
|
button,
|
||||||
|
textarea,
|
||||||
|
select {
|
||||||
|
font: inherit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Remove all animations, transitions and smooth scroll for people that prefer not to see them */
|
||||||
|
@media (prefers-reduced-motion: reduce) {
|
||||||
|
html:focus-within {
|
||||||
|
scroll-behavior: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
*,
|
||||||
|
*::before,
|
||||||
|
*::after {
|
||||||
|
animation-duration: 0.01ms !important;
|
||||||
|
animation-iteration-count: 1 !important;
|
||||||
|
transition-duration: 0.01ms !important;
|
||||||
|
scroll-behavior: auto !important;
|
||||||
|
}
|
||||||
|
}
|
7
templates/base.html
Normal file
7
templates/base.html
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
{{ template "head.html" . }}
|
||||||
|
<body>
|
||||||
|
{{ block "content" . }}{{ end }}
|
||||||
|
</body>
|
||||||
|
</html>
|
5
templates/head.html
Normal file
5
templates/head.html
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<head>
|
||||||
|
<title>Oopsie</title>
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="/static/reset.css" />
|
||||||
|
</head>
|
@ -1,9 +1,5 @@
|
|||||||
<!DOCTYPE html>
|
{{ template "base.html" . }}
|
||||||
<html lang="en">
|
|
||||||
<head>
|
{{ define "content" }}
|
||||||
<title>Oopsie</title>
|
<h1>Oopsie uptime monitoring</h1>
|
||||||
</head>
|
{{ end }}
|
||||||
<body>
|
|
||||||
<h1>Oopsie uptime monitoring</h1>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
Loading…
Reference in New Issue
Block a user