-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathpins_handler.go
More file actions
34 lines (26 loc) · 792 Bytes
/
Copy pathpins_handler.go
File metadata and controls
34 lines (26 loc) · 792 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package main
import (
"fmt"
"net/http"
)
type PinsHandler HandlerWithDBConnection
func (hd *PinsHandler) ServeHTTP(resp http.ResponseWriter, request *http.Request) {
db := hd.db
resp.Header().Add("Content-Type", "text/csv; charset=utf-8")
resp.Header().Add("Cache-Control", "public")
rows, err := db.Query("select pubkey, lat, lon from users where lat is not null and lon is not null")
defer rows.Close()
for rows.Next() {
var lat, lon float64
var pubkey []byte
err = rows.Scan(&pubkey, &lat, &lon)
fingerprint := pubkeyFingerprintMD5(pubkey)
fmt.Fprintf(resp, "%s,%.6f,%.6f\n", fingerprint, lat, lon)
}
err = rows.Err()
if err != nil {
fmt.Println("listing pins:", err)
http.Error(resp, "Internal server error", http.StatusInternalServerError)
return
}
}