summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2014-12-25 06:09:06 -0800
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2014-12-25 06:09:06 -0800
commit3234ade75edd5c4b01f817cc127a13feb9c25c7b (patch)
tree99653f09b515c2f52f64f8ea5d95ce6835974a2c
parentd9d527a65dd068e0a093ed94ad5effc13567a5e1 (diff)
rest: use interface{} for REST response
Then rest.go can use an appropriate format. Likelly we support only JSON though. Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--api/rest.go13
-rw-r--r--server/peer.go3
2 files changed, 4 insertions, 12 deletions
diff --git a/api/rest.go b/api/rest.go
index 909fd541..fc421805 100644
--- a/api/rest.go
+++ b/api/rest.go
@@ -80,7 +80,7 @@ type RestResponse interface {
type RestResponseDefault struct {
ResponseErr error
- Data []byte
+ Data interface{}
}
func (r *RestResponseDefault) Err() error {
@@ -96,14 +96,6 @@ type RestResponseNeighbor struct {
UpdateCount int
}
-// Response struct for Rib
-type RestResponseRib struct {
- RestResponseDefault
- RemoteAddr string
- RemoteAs uint32
- RibInfo []string
-}
-
type RestServer struct {
port int
bgpServerCh chan *RestRequest
@@ -226,7 +218,8 @@ func (rs *RestServer) NeighborLocalRib(w http.ResponseWriter, r *http.Request) {
res := resInf.(*RestResponseDefault)
w.Header().Set("Content-Type", "application/json; charset=utf-8")
- w.Write(res.Data)
+ j, _ := json.Marshal(res.Data)
+ w.Write(j)
}
func NotFoundHandler(w http.ResponseWriter, r *http.Request) {
diff --git a/server/peer.go b/server/peer.go
index 3aa87e9d..f3a23d5b 100644
--- a/server/peer.go
+++ b/server/peer.go
@@ -106,8 +106,7 @@ func (peer *Peer) path2update(pathList []table.Path) []*bgp.BGPMessage {
func (peer *Peer) handleREST(restReq *api.RestRequest) {
result := &api.RestResponseDefault{}
- j, _ := json.Marshal(peer.rib.Tables[bgp.RF_IPv4_UC])
- result.Data = j
+ result.Data = peer.rib.Tables[bgp.RF_IPv4_UC]
restReq.ResponseCh <- result
close(restReq.ResponseCh)
}