func ClusterList(w http.ResponseWriter, r *http.Request) { if err := common("GET", r); err != nil { http.Error(w, err.Error(), 400) return } // We are sending json data w.Header().Add("Content-Type", "application/json") var RootPath = DefaultRootPath if root := r.Form.Get("root"); root != "" { RootPath = root } var ClusterSize = DefaultListClusterSize if projSizeStr := r.Form.Get("size"); projSizeStr != "" { projSize, err := strconv.ParseInt(projSizeStr, 10, 0) if err == nil { ClusterSize = int(projSize) } } var ClusterNodes = &Clusters{ Root: RootPath, Size: ClusterSize, Nodes: make([]string, 0, ClusterSize), } kAPI, _ := disc.NewKeysAPI(etcd.Config{ Endpoints: disc.Endpoints(), }) work, abort := ctx.WithTimeout(ctx.Background(), 3*time.Second) defer abort() resp, err := kAPI.Get(work, RootPath, &etcd.GetOptions{ Recursive: true, }) if err != nil { json.NewEncoder(w).Encode(ClusterNodes) return } // Go traverse the discovery tree for _, node := range resp.Node.Nodes { checkCluster(ClusterNodes, node) } ClusterNodes.Size = len(ClusterNodes.Nodes) json.NewEncoder(w).Encode(ClusterNodes) return }
func followBootStrap() { kAPI, err := disc.NewKeysAPI(etcd.Config{Endpoints: disc.Endpoints()}) if err != nil { log.WithFields(log.Fields{"err": err}).Warning("bootstrap") return } resp, err := kAPI.Get(RootContext, ProxyConfigKey, nil) if err != nil { log.WithFields(log.Fields{"err": err}).Warning("bootstrap") reload(make([]*Info, 0)) } else if resp.Node.Dir { log.WithFields(log.Fields{"key": resp.Node.Key}).Warning("not a valid node") reload(make([]*Info, 0)) } else { log.WithFields(log.Fields{"key": resp.Node.Key, "val": resp.Node.Value}).Debug("cfgkey") if pxycfg := get(resp.Node.Value); pxycfg != nil { reload(pxycfg) } else { reload(make([]*Info, 0)) } } }