File tree 2 files changed +15
-3
lines changed
2 files changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -3,12 +3,17 @@ package main
3
3
import (
4
4
"net/http"
5
5
"github.com/gorilla/mux"
6
+ "github.com/go-redis/redis"
6
7
"html/template"
7
8
)
8
9
10
+ var client * redis.Client
9
11
var templates * template.Template
10
12
11
13
func main () {
14
+ client = redis .NewClient (& redis.Options {
15
+ Addr : "localhost:6379" ,
16
+ })
12
17
templates = template .Must (template .ParseGlob ("templates/*.html" ))
13
18
r := mux .NewRouter ()
14
19
r .HandleFunc ("/" , indexHandler ).Methods ("GET" )
@@ -17,5 +22,9 @@ func main() {
17
22
}
18
23
19
24
func indexHandler (w http.ResponseWriter , r * http.Request ) {
20
- templates .ExecuteTemplate (w , "index.html" , nil )
25
+ comments , err := client .LRange ("comments" , 0 , 10 ).Result ()
26
+ if err != nil {
27
+ return
28
+ }
29
+ templates .ExecuteTemplate (w , "index.html" , comments )
21
30
}
Original file line number Diff line number Diff line change 1
1
< html >
2
2
< head >
3
- < title > Super awesome amazing page </ title >
3
+ < title > Comments </ title >
4
4
</ head >
5
5
< body >
6
- < h1 > Some basic HTML code</ h1 >
6
+ < h1 > Comments</ h1 >
7
+ {{ range . }}
8
+ < div > {{ . }}</ div >
9
+ {{ end }}
7
10
</ body >
8
11
</ html >
You can’t perform that action at this time.
0 commit comments