Skip to content

Commit baae5a4

Browse files
committed
Added templates
1 parent 4995cc5 commit baae5a4

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

main.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
package main
22

33
import (
4-
"fmt"
54
"net/http"
65
"github.com/gorilla/mux"
6+
"html/template"
77
)
88

9+
var templates *template.Template
10+
911
func main() {
12+
templates = template.Must(template.ParseGlob("templates/*.html"))
1013
r := mux.NewRouter()
11-
r.HandleFunc("/hello", helloHandler).Methods("GET")
12-
r.HandleFunc("/goodbye", goodbyeHandler).Methods("GET")
14+
r.HandleFunc("/", indexHandler).Methods("GET")
1315
http.Handle("/", r)
1416
http.ListenAndServe(":8080", nil)
1517
}
1618

17-
func helloHandler(w http.ResponseWriter, r *http.Request) {
18-
fmt.Fprint(w, "Hello world!")
19-
}
20-
21-
func goodbyeHandler(w http.ResponseWriter, r *http.Request) {
22-
fmt.Fprint(w, "Goodbye world!")
19+
func indexHandler(w http.ResponseWriter, r *http.Request) {
20+
templates.ExecuteTemplate(w, "index.html", nil)
2321
}

templates/index.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<html>
2+
<head>
3+
<title>Super awesome amazing page</title>
4+
</head>
5+
<body>
6+
<h1>Some basic HTML code</h1>
7+
</body>
8+
</html>

0 commit comments

Comments
 (0)