Skip to content

Commit 27f0a94

Browse files
committed
Removed gzip compression, (too buggy). JSONs are twice the size now :/
1 parent a89e7ac commit 27f0a94

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

getvoters/main.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"strconv"
88
"net/http"
99
"database/sql"
10-
"compress/gzip"
1110
"encoding/json"
1211
"encoding/base64"
1312
_ "github.com/lib/pq"
@@ -24,6 +23,10 @@ FROM accounts WHERE inflationdest = $1`
2423
const TOTAL_VOTES_QUERY = `SELECT SUM(balance)
2524
FROM accounts WHERE inflationdest = $1`
2625

26+
// JSON indent strings (https://golang.org/pkg/encoding/json/#Encoder.SetIndent)
27+
const JSON_INDENT_PREFIX = ""
28+
const JSON_INDENT_INDENT = ""
29+
2730
// Data structure for the main page JSON
2831
type Digest struct {
2932
Pool string `json:"address"`
@@ -95,7 +98,8 @@ func init() {
9598
"Parameter to expect in the HTTP GET request URL (example: <URL>?pool=<ADDR>)")
9699

97100
// Stellar flags
98-
flag.StringVar(&defaultPool, "pool", "GCCD6AJOYZCUAQLX32ZJF2MKFFAUJ53PVCFQI3RHWKL3V47QYE2BNAUT",
101+
flag.StringVar(&defaultPool, "pool",
102+
"GCCD6AJOYZCUAQLX32ZJF2MKFFAUJ53PVCFQI3RHWKL3V47QYE2BNAUT",
99103
"Default inflationdest address to use")
100104

101105
flag.StringVar(&donationKey, "key", "lumenaut.net donation%",
@@ -138,18 +142,15 @@ func poolFromParam(r *http.Request) string {
138142
return pool
139143
}
140144

141-
func writeJSON(w http.ResponseWriter, data interface{}, compress bool) {
145+
func writeJSON(w http.ResponseWriter, data interface{}) {
142146
// Inform the user of the content-type in the header
143147
w.Header().Set("Content-Type", "application/json")
144-
if compress {
145-
w.Header().Set("Content-Encoding", "gzip")
146-
}
147148

148149
// Set up the compressing/encoding pipeline
149150
js := json.NewEncoder(w)
150-
if compress {
151-
js = json.NewEncoder(gzip.NewWriter(w))
152-
}
151+
152+
// Set the JSON indentation strings
153+
js.SetIndent(JSON_INDENT_PREFIX, JSON_INDENT_INDENT)
153154

154155
// Marshal data as JSON and send to w
155156
err := js.Encode(data)
@@ -180,8 +181,8 @@ func getTotals(w http.ResponseWriter, r *http.Request) {
180181
http.Error(w, "500 internal server error", 500)
181182
return
182183
}
183-
184-
writeJSON(w, &Digest{Pool: pool, Voters: voters, Votes: votes}, false)
184+
185+
writeJSON(w, &Digest{Pool: pool, Voters: voters, Votes: votes})
185186
}
186187

187188
func getVoters(w http.ResponseWriter, r *http.Request) {
@@ -215,7 +216,7 @@ func getVoters(w http.ResponseWriter, r *http.Request) {
215216
vl.Entries = append(vl.Entries, entry)
216217
}
217218

218-
writeJSON(w, &vl, true)
219+
writeJSON(w, &vl)
219220
}
220221

221222
func getVotersDB(pool string) (Voters, error) {

0 commit comments

Comments
 (0)