diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2014-12-25 06:30:20 -0800 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2014-12-25 06:30:20 -0800 |
commit | 4da71624586971c253bfb2625bdd91e121254b22 (patch) | |
tree | 5b9563d6fff428511685854a160b0397a3ded114 /api/rest.go | |
parent | 3234ade75edd5c4b01f817cc127a13feb9c25c7b (diff) |
server: support /neighbors URL
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'api/rest.go')
-rw-r--r-- | api/rest.go | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/api/rest.go b/api/rest.go index fc421805..83dba703 100644 --- a/api/rest.go +++ b/api/rest.go @@ -122,7 +122,7 @@ func NewRestServer(port int, bgpServerCh chan *RestRequest) *RestServer { // -- curl -i -X GET http://<ownIP>:8080/v1/bgp/neighbor/<remote address of target neighbor>/local-rib func (rs *RestServer) Serve() { neighbor := BASE_VERSION + NEIGHBOR - // neighbors := BASE_VERSION + NEIGHBORS + neighbors := BASE_VERSION + NEIGHBORS // adjRibIn := BASE_VERSION + ADJ_RIB_IN // adjRibOut := BASE_VERSION + ADJ_RIB_OUT // adjRibLocal := BASE_VERSION + ADJ_RIB_LOCAL @@ -130,7 +130,7 @@ func (rs *RestServer) Serve() { r := mux.NewRouter() // set URLs - // r.HandleFunc(neighbors, rs.Neighbors).Methods("GET") + r.HandleFunc(neighbors, rs.Neighbors).Methods("GET") r.HandleFunc(neighbor+"/{"+PARAM_REMOTE_PEER_ADDR+"}", rs.Neighbor).Methods("GET") // r.HandleFunc(adjRibIn+"/{"+PARAM_REMOTE_PEER_ADDR+"}", rs.AdjRibIn).Methods("GET") // r.HandleFunc(adjRibOut+"/{"+PARAM_REMOTE_PEER_ADDR+"}", rs.AdjRibOut).Methods("GET") @@ -222,6 +222,25 @@ func (rs *RestServer) NeighborLocalRib(w http.ResponseWriter, r *http.Request) { w.Write(j) } +func (rs *RestServer) Neighbors(w http.ResponseWriter, r *http.Request) { + //Send channel of request parameter. + req := NewRestRequest(REQ_NEIGHBORS, "") + rs.bgpServerCh <- req + + //Wait response + resInf := <-req.ResponseCh + if e := resInf.Err(); e != nil { + log.Debug(e.Error()) + http.Error(w, e.Error(), http.StatusInternalServerError) + return + } + + res := resInf.(*RestResponseDefault) + w.Header().Set("Content-Type", "application/json; charset=utf-8") + j, _ := json.Marshal(res.Data) + w.Write(j) +} + func NotFoundHandler(w http.ResponseWriter, r *http.Request) { http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound) } |