implemented some API funcs, added whitelist API

This commit is contained in:
Jimmy Zelinskie 2014-07-07 22:23:01 -04:00
parent d8bcbd1dde
commit 9e94643379

View file

@ -5,15 +5,98 @@
package http package http
import ( import (
"encoding/json"
"net/http" "net/http"
"github.com/julienschmidt/httprouter" "github.com/julienschmidt/httprouter"
"github.com/chihaya/chihaya/drivers/tracker"
) )
func (t *Tracker) getTorrent(w http.ResponseWriter, r *http.Request, p httprouter.Params) int {} func (t *Tracker) getTorrent(w http.ResponseWriter, r *http.Request, p httprouter.Params) int {
func (t *Tracker) putTorrent(w http.ResponseWriter, r *http.Request, p httprouter.Params) int {} conn, err := t.tp.Get()
func (t *Tracker) delTorrent(w http.ResponseWriter, r *http.Request, p httprouter.Params) int {} if err != nil {
return http.StatusInternalServerError
}
func (t *Tracker) getUser(w http.ResponseWriter, r *http.Request, p httprouter.Params) int {} torrent, err := conn.FindTorrent(p.ByName("infohash"))
func (t *Tracker) putUser(w http.ResponseWriter, r *http.Request, p httprouter.Params) int {} if err == tracker.ErrTorrentDNE {
func (t *Tracker) delUser(w http.ResponseWriter, r *http.Request, p httprouter.Params) int {} return http.StatusNotFound
} else if err != nil {
return http.StatusInternalServerError
}
e := json.NewEncoder(w)
err = e.Encode(torrent)
if err != nil {
return http.StatusInternalServerError
}
return http.StatusOK
}
func (t *Tracker) putTorrent(w http.ResponseWriter, r *http.Request, p httprouter.Params) int {
return http.StatusOK
}
func (t *Tracker) delTorrent(w http.ResponseWriter, r *http.Request, p httprouter.Params) int {
return http.StatusOK
}
func (t *Tracker) getUser(w http.ResponseWriter, r *http.Request, p httprouter.Params) int {
conn, err := t.tp.Get()
if err != nil {
return http.StatusInternalServerError
}
user, err := conn.FindUser(p.ByName("passkey"))
if err == tracker.ErrUserDNE {
return http.StatusNotFound
} else if err != nil {
return http.StatusInternalServerError
}
e := json.NewEncoder(w)
err = e.Encode(user)
if err != nil {
return http.StatusInternalServerError
}
return http.StatusOK
}
func (t *Tracker) putUser(w http.ResponseWriter, r *http.Request, p httprouter.Params) int {
return http.StatusOK
}
func (t *Tracker) delUser(w http.ResponseWriter, r *http.Request, p httprouter.Params) int {
return http.StatusOK
}
func (t *Tracker) putClient(w http.ResponseWriter, r *http.Request, p httprouter.Params) int {
conn, err := t.tp.Get()
if err != nil {
return http.StatusInternalServerError
}
err = conn.WhitelistClient(p.ByName("clientID"))
if err != nil {
return http.StatusInternalServerError
}
return http.StatusOK
}
func (t *Tracker) delClient(w http.ResponseWriter, r *http.Request, p httprouter.Params) int {
conn, err := t.tp.Get()
if err != nil {
return http.StatusInternalServerError
}
err = conn.UnWhitelistClient(p.ByName("clientID"))
if err != nil {
return http.StatusInternalServerError
}
return http.StatusOK
}