示例#1
0
文件: route.go 项目: nanopack/portal
func putRoutes(rw http.ResponseWriter, req *http.Request) {
	var routes []core.Route
	err := parseBody(req, &routes)
	if err != nil {
		writeError(rw, req, err, http.StatusBadRequest)
		return
	}

	// save to cluster
	err = cluster.SetRoutes(routes)
	if err != nil {
		writeError(rw, req, err, http.StatusInternalServerError)
		return
	}

	writeBody(rw, req, routes, http.StatusOK)
}
示例#2
0
func TestNoneSetRoutes(t *testing.T) {
	routes := []core.Route{testRoute}

	if err := cluster.SetRoutes(routes); err != nil {
		t.Errorf("Failed to SET routes - %v", err)
		t.FailNow()
	}

	// don't use cluster.GetRoutes()
	routes, err := database.GetRoutes()
	if err != nil {
		t.Error(err)
	}

	if len(routes) != 1 || routes[0].Domain != testRoute.Domain {
		t.Errorf("Read route differs from written route")
	}
}