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 1
1
package main
2
2
3
3
import (
4
- "fmt"
5
4
"net/http"
6
5
"github.com/gorilla/mux"
6
+ "html/template"
7
7
)
8
8
9
+ var templates * template.Template
10
+
9
11
func main () {
12
+ templates = template .Must (template .ParseGlob ("templates/*.html" ))
10
13
r := mux .NewRouter ()
11
- r .HandleFunc ("/hello" , helloHandler ).Methods ("GET" )
12
- r .HandleFunc ("/goodbye" , goodbyeHandler ).Methods ("GET" )
14
+ r .HandleFunc ("/" , indexHandler ).Methods ("GET" )
13
15
http .Handle ("/" , r )
14
16
http .ListenAndServe (":8080" , nil )
15
17
}
16
18
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 )
23
21
}
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