File tree Expand file tree Collapse file tree 2 files changed +15
-3
lines changed Expand file tree Collapse file tree 2 files changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -3,12 +3,17 @@ package main
33import (
44 "net/http"
55 "github.com/gorilla/mux"
6+ "github.com/go-redis/redis"
67 "html/template"
78)
89
10+ var client * redis.Client
911var templates * template.Template
1012
1113func main () {
14+ client = redis .NewClient (& redis.Options {
15+ Addr : "localhost:6379" ,
16+ })
1217 templates = template .Must (template .ParseGlob ("templates/*.html" ))
1318 r := mux .NewRouter ()
1419 r .HandleFunc ("/" , indexHandler ).Methods ("GET" )
@@ -17,5 +22,9 @@ func main() {
1722}
1823
1924func 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 )
2130}
Original file line number Diff line number Diff line change 11< html >
22 < head >
3- < title > Super awesome amazing page </ title >
3+ < title > Comments </ title >
44 </ head >
55 < body >
6- < h1 > Some basic HTML code</ h1 >
6+ < h1 > Comments</ h1 >
7+ {{ range . }}
8+ < div > {{ . }}</ div >
9+ {{ end }}
710 </ body >
811</ html >
You can’t perform that action at this time.
0 commit comments