Skip to content

Commit 78dc320

Browse files
committed
Added static file handler
1 parent 536b01c commit 78dc320

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

Diff for: main.go

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ func main() {
1818
r := mux.NewRouter()
1919
r.HandleFunc("/", indexGetHandler).Methods("GET")
2020
r.HandleFunc("/", indexPostHandler).Methods("POST")
21+
fs := http.FileServer(http.Dir("./static/"))
22+
r.PathPrefix("/static/").Handler(http.StripPrefix("/static/", fs))
2123
http.Handle("/", r)
2224
http.ListenAndServe(":8080", nil)
2325
}

Diff for: static/index.css

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
body > div {
2+
padding: 0.5em;
3+
width: 200px;
4+
margin: 1em 0em;
5+
background: #ccc;
6+
border: 1px solid #aaa;
7+
}

Diff for: templates/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<html>
22
<head>
33
<title>Comments</title>
4+
<link rel="stylesheet" type="text/css" href="/static/index.css">
45
</head>
56
<body>
67
<h1>Comments</h1>

0 commit comments

Comments
 (0)