Skip to content

Commit 4bf8c58

Browse files
committed
added patch 28
1 parent 22e9bfc commit 4bf8c58

File tree

5 files changed

+48
-24
lines changed

5 files changed

+48
-24
lines changed

handlers.go

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package main
2+
3+
import "net/http"
4+
5+
// Home is the handler for the home page
6+
func Home(w http.ResponseWriter, r *http.Request) {
7+
rendernTemplate(w, "home-page.tpml")
8+
}
9+
10+
// About is the handler for the about page
11+
func About(w http.ResponseWriter, r *http.Request) {
12+
rendernTemplate(w, "about-page.tpml")
13+
}

main.go

-22
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,10 @@ package main
33
import (
44
"fmt"
55
"net/http"
6-
"text/template"
76
)
87

98
const portNumber = ":8080"
109

11-
// Home is the handler for the home page
12-
func Home(w http.ResponseWriter, r *http.Request) {
13-
rendernTemplate(w, "home-page.tpml")
14-
}
15-
16-
// About is the handler for the about page
17-
func About(w http.ResponseWriter, r *http.Request) {
18-
rendernTemplate(w, "about-page.tpml")
19-
20-
}
21-
22-
// rendernTemplate serves as a wrapper and renders
23-
// a template from folder /templates to a desired writer
24-
func rendernTemplate(w http.ResponseWriter, tpml string) {
25-
parsedTemplate, _ := template.ParseFiles("./templates/" + tpml)
26-
err := parsedTemplate.Execute(w, nil)
27-
if err != nil {
28-
fmt.Println("error parsing template:", err)
29-
}
30-
}
31-
3210
// main is the main function
3311
func main() {
3412
http.HandleFunc("/", Home)

render.go

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"html/template"
6+
"net/http"
7+
)
8+
9+
// rendernTemplate serves as a wrapper and renders
10+
// a template from folder /templates to a desired writer
11+
func rendernTemplate(w http.ResponseWriter, tpml string) {
12+
parsedTemplate, _ := template.ParseFiles("./templates/" + tpml)
13+
err := parsedTemplate.Execute(w, nil)
14+
if err != nil {
15+
fmt.Println("error parsing template:", err)
16+
}
17+
}

templates/about-page.tpml

+9-1
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,17 @@
44
<meta charset="UTF-8">
55
<meta http-equiv="X-UA-Compatible" content="IE=edge">
66
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
78
<title>Document</title>
89
</head>
910
<body>
10-
<h1>This is the about page</h1>
11+
<div class="container">
12+
<div class="row">
13+
<div class="col">
14+
<h1>This is the about page</h1>
15+
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sapiente ducimus possimus praesentium quaerat libero omnis rem eius quas qui iure id tenetur autem est eum, commodi ipsa sit labore nam!
16+
</div>
17+
</div>
18+
</div>
1119
</body>
1220
</html>

templates/home-page.tpml

+9-1
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,17 @@
44
<meta charset="UTF-8">
55
<meta http-equiv="X-UA-Compatible" content="IE=edge">
66
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
78
<title>Document</title>
89
</head>
910
<body>
10-
<h1>This is the home page</h1>
11+
<div class="container">
12+
<div class="row">
13+
<div class="col">
14+
<h1>This is the home page</h1>
15+
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sapiente ducimus possimus praesentium quaerat libero omnis rem eius quas qui iure id tenetur autem est eum, commodi ipsa sit labore nam!
16+
</div>
17+
</div>
18+
</div>
1119
</body>
1220
</html>

0 commit comments

Comments
 (0)