go fmt [ci skip]

This commit is contained in:
Jimmy Zelinskie
2013-11-24 00:49:20 -05:00
parent cf36519c5e
commit 6549f49e26
10 changed files with 1735 additions and 1735 deletions
+57 -57
View File
@@ -5,72 +5,72 @@
package server
import (
"errors"
"io"
"log"
"net/http"
"path"
"errors"
"io"
"log"
"net/http"
"path"
"github.com/pushrax/chihaya/storage"
"github.com/pushrax/chihaya/storage"
)
func (s *Server) serveScrape(w http.ResponseWriter, r *http.Request) {
// Parse the query
pq, err := parseQuery(r.URL.RawQuery)
if err != nil {
fail(errors.New("Error parsing query"), w, r)
return
}
// Parse the query
pq, err := parseQuery(r.URL.RawQuery)
if err != nil {
fail(errors.New("Error parsing query"), w, r)
return
}
// Get a connection to the tracker db
conn, err := s.dbConnPool.Get()
if err != nil {
log.Fatal(err)
}
// Get a connection to the tracker db
conn, err := s.dbConnPool.Get()
if err != nil {
log.Fatal(err)
}
// Find and validate the user
passkey, _ := path.Split(r.URL.Path)
_, err = validateUser(conn, passkey)
if err != nil {
fail(err, w, r)
return
}
// Find and validate the user
passkey, _ := path.Split(r.URL.Path)
_, err = validateUser(conn, passkey)
if err != nil {
fail(err, w, r)
return
}
io.WriteString(w, "d")
writeBencoded(w, "files")
if pq.Infohashes != nil {
for _, infohash := range pq.Infohashes {
torrent, exists, err := conn.FindTorrent(infohash)
if err != nil {
log.Panicf("server: %s", err)
}
if exists {
writeBencoded(w, infohash)
writeScrapeInfo(w, torrent)
}
}
} else if infohash, exists := pq.Params["info_hash"]; exists {
torrent, exists, err := conn.FindTorrent(infohash)
if err != nil {
log.Panicf("server: %s", err)
}
if exists {
writeBencoded(w, infohash)
writeScrapeInfo(w, torrent)
}
}
io.WriteString(w, "e")
io.WriteString(w, "d")
writeBencoded(w, "files")
if pq.Infohashes != nil {
for _, infohash := range pq.Infohashes {
torrent, exists, err := conn.FindTorrent(infohash)
if err != nil {
log.Panicf("server: %s", err)
}
if exists {
writeBencoded(w, infohash)
writeScrapeInfo(w, torrent)
}
}
} else if infohash, exists := pq.Params["info_hash"]; exists {
torrent, exists, err := conn.FindTorrent(infohash)
if err != nil {
log.Panicf("server: %s", err)
}
if exists {
writeBencoded(w, infohash)
writeScrapeInfo(w, torrent)
}
}
io.WriteString(w, "e")
w.(http.Flusher).Flush()
w.(http.Flusher).Flush()
}
func writeScrapeInfo(w io.Writer, torrent *storage.Torrent) {
io.WriteString(w, "d")
writeBencoded(w, "complete")
writeBencoded(w, len(torrent.Seeders))
writeBencoded(w, "downloaded")
writeBencoded(w, torrent.Snatches)
writeBencoded(w, "incomplete")
writeBencoded(w, len(torrent.Leechers))
io.WriteString(w, "e")
io.WriteString(w, "d")
writeBencoded(w, "complete")
writeBencoded(w, len(torrent.Seeders))
writeBencoded(w, "downloaded")
writeBencoded(w, torrent.Snatches)
writeBencoded(w, "incomplete")
writeBencoded(w, len(torrent.Leechers))
io.WriteString(w, "e")
}