File tree Expand file tree Collapse file tree 2 files changed +15
-9
lines changed
Expand file tree Collapse file tree 2 files changed +15
-9
lines changed Original file line number Diff line number Diff line change 11package main
22
33import (
4- "fmt"
54 "net/http"
65 "github.com/gorilla/mux"
6+ "html/template"
77)
88
9+ var templates * template.Template
10+
911func 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}
Original file line number Diff line number Diff line change 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 >
You can’t perform that action at this time.
0 commit comments