Reworked interface to router so we split setting up the initial list from beginning to make connections - we shouldn't do that until after router.Start().
30 lines
877 B
Go
30 lines
877 B
Go
package router
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/gorilla/mux"
|
|
"github.com/weaveworks/weave/common"
|
|
)
|
|
|
|
func (router *NetworkRouter) HandleHTTP(muxRouter *mux.Router) {
|
|
|
|
muxRouter.Methods("POST").Path("/connect").HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
if err := r.ParseForm(); err != nil {
|
|
http.Error(w, fmt.Sprint("unable to parse form: ", err), http.StatusBadRequest)
|
|
}
|
|
if errors := router.InitiateConnections(r.Form["peer"], r.FormValue("replace") == "true"); len(errors) > 0 {
|
|
http.Error(w, common.ErrorMessages(errors), http.StatusBadRequest)
|
|
}
|
|
})
|
|
|
|
muxRouter.Methods("POST").Path("/forget").HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
if err := r.ParseForm(); err != nil {
|
|
http.Error(w, fmt.Sprint("unable to parse form: ", err), http.StatusBadRequest)
|
|
}
|
|
router.ForgetConnections(r.Form["peer"])
|
|
})
|
|
|
|
}
|