Skip to content

Commit d5c35e8

Browse files
authored
Homepage (#2)
1 parent 98cb3e6 commit d5c35e8

File tree

6 files changed

+93
-0
lines changed

6 files changed

+93
-0
lines changed

server/routes.go

+8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package server
22

33
import (
4+
"io/fs"
45
"net/http"
56

67
"github.com/julienschmidt/httprouter"
@@ -24,6 +25,13 @@ func (s *Server) setupRoutes() (err error) {
2425
// Status/Heartbeat endpoint
2526
s.addRoute(http.MethodGet, "/v1/status", s.Status, middleware...)
2627

28+
// Application Routes
29+
static, _ := fs.Sub(content, "static")
30+
s.router.ServeFiles("/static/*filepath", http.FS(static))
31+
s.addRoute(http.MethodGet, "/", s.HomePage(), middleware...)
32+
33+
// Golang Vanity Handling
34+
2735
return nil
2836
}
2937

server/static/css/style.css

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
.text-white {
2+
color: #FFF;
3+
}
4+
5+
.text-center {
6+
text-align: center;
7+
}
8+
9+
.bg-lapis {
10+
background-color: #1D65A6;
11+
}
12+
13+
.bg-slate {
14+
background-color: #2F4858;
15+
}
16+
17+
body {
18+
font-family: Arial, sans-serif;
19+
height: 100%;
20+
width: 100%;
21+
margin: 0;
22+
padding: 0;
23+
}
24+
25+
header div {
26+
margin: 0;
27+
}
28+
29+
.logo {
30+
padding: 32px 0;
31+
}
32+
33+
.page-title h1 {
34+
padding: 24px;
35+
margin: 0;
36+
font-size: 24px;
37+
}

server/static/img/favicon.ico

15 KB
Binary file not shown.

server/static/img/logo.png

7.72 KB
Loading

server/templates/index.html

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<meta name="robots" content="noindex,follow">
7+
8+
<title>Rotational Go Packages</title>
9+
10+
<link rel="icon" type="image/ico" href="/static/img/favicon.ico">
11+
<link rel="stylesheet" href="/static/css/style.css" />
12+
</head>
13+
<body>
14+
<header>
15+
<div class="text-white text-center bg-lapis">
16+
<img src="/static/img/logo.png" class="logo" />
17+
</div>
18+
<div class="bg-slate text-center page-title">
19+
<h1 class="text-white">Rotational Go Packages</h1>
20+
</div>
21+
</header>
22+
</body>
23+
</html>

server/web.go

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package server
2+
3+
import (
4+
"embed"
5+
"html/template"
6+
"io/fs"
7+
"net/http"
8+
9+
"github.com/julienschmidt/httprouter"
10+
)
11+
12+
//go:embed all:templates
13+
//go:embed all:static
14+
var content embed.FS
15+
16+
func (s *Server) HomePage() httprouter.Handle {
17+
// Compile the template for serving the home page.
18+
templates, _ := fs.Sub(content, "templates")
19+
index := template.Must(template.ParseFS(templates, "*.html"))
20+
return func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
21+
if err := index.ExecuteTemplate(w, "index.html", nil); err != nil {
22+
http.Error(w, err.Error(), http.StatusInternalServerError)
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)