File tree Expand file tree Collapse file tree 3 files changed +11
-8
lines changed Expand file tree Collapse file tree 3 files changed +11
-8
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ package main
77import (
88 "context"
99 "encoding/json"
10+ "html/template"
1011 "log"
1112 "net/http"
1213)
@@ -21,7 +22,15 @@ type server struct {
2122 visitCh chan visit
2223}
2324
25+ var (
26+ xTmpl * template.Template
27+ statsTmpl * template.Template
28+ )
29+
2430func newServer (ctx context.Context ) * server {
31+ xTmpl = template .Must (template .ParseFiles ("public/x.html" ))
32+ statsTmpl = template .Must (template .ParseFiles ("public/stats.html" ))
33+
2534 db , err := newStore (conf .Store )
2635 if err != nil {
2736 log .Fatalf ("cannot establish connection to database, err: %v" , err )
Original file line number Diff line number Diff line change @@ -10,7 +10,6 @@ import (
1010 "encoding/json"
1111 "errors"
1212 "fmt"
13- "html/template"
1413 "log"
1514 "net"
1615 "net/http"
@@ -25,9 +24,9 @@ type op string
2524const (
2625 // opCreate represents a create operation for short link
2726 opCreate op = "create"
28- // opDelete represents a create operation for short link
27+ // opDelete represents a delete operation for short link
2928 opDelete = "delete"
30- // opUpdate represents a create operation for short link
29+ // opUpdate represents a update operation for short link
3130 opUpdate = "update"
3231 // opFetch represents a fetch operation for short link
3332 opFetch = "fetch"
@@ -149,8 +148,6 @@ func (s *server) readIP(r *http.Request) string {
149148 return ip
150149}
151150
152- var statsTmpl = template .Must (template .ParseFiles ("public/stats.html" ))
153-
154151type arecords struct {
155152 Records []arecord
156153}
Original file line number Diff line number Diff line change @@ -7,13 +7,10 @@ package main
77import (
88 "bytes"
99 "fmt"
10- "html/template"
1110 "net/http"
1211 "strings"
1312)
1413
15- var xTmpl = template .Must (template .ParseFiles ("public/x.html" ))
16-
1714type x struct {
1815 ImportRoot string
1916 VCS string
You can’t perform that action at this time.
0 commit comments