virtigo/doList.go

103 lines
2.7 KiB
Go

// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0
package main
// An app to submit patches for the 30 GO GUI repos
import (
"fmt"
"net/http"
"net/url"
"time"
"go.wit.com/lib/protobuf/virtpb"
"go.wit.com/log"
)
// refresh the windows & tables the user has open
func doListDroplets() {
/*
// update the droplet list
if data, err := postData(admin.url.String()+"/DropletsPB", msg); err != nil {
log.Info("/DropletsPB Error:", err)
} else {
fmt.Println("DropletsPB Response len:", len(data))
admin.droplets = new(virtpb.Droplets)
if err := admin.droplets.Unmarshal(data); err != nil {
fmt.Println("droplets marshal failed", err)
return
}
fmt.Println("Droplet len=", admin.droplets.Len())
}
// update the hypervisor list
if data, err := postData(admin.url.String()+"/HypervisorsPB", msg); err != nil {
log.Info("Error:", err)
} else {
fmt.Println("HypervisorsPB Response len:", len(data))
admin.hypervisors = new(virtpb.Hypervisors)
if err := admin.hypervisors.Unmarshal(data); err != nil {
fmt.Println("hypervisors marshal failed", err)
return
}
fmt.Println("Hypervisors len=", admin.hypervisors.Len())
}
// update the events list
if data, err := postData(admin.url.String()+"/EventsPB", msg); err != nil {
log.Info("Error:", err)
} else {
fmt.Println("EventsPB Response len:", len(data))
admin.events = new(virtpb.Events)
if err := admin.events.Unmarshal(data); err != nil {
fmt.Println("events marshal failed", err)
return
}
fmt.Println("Events len=", admin.events.Len())
}
*/
}
// var client *http.Client
func doList() {
msg := []byte(`{"message": "Hello"}`)
// Initialize a persistent client with a custom Transport
client = &http.Client{
Transport: &http.Transport{
DisableKeepAlives: false, // Ensure Keep-Alive is enabled
},
Timeout: 10 * time.Second, // Set a reasonable timeout
}
me.cmap = make(map[*virtpb.Cluster]*adminT)
for c := range me.clusters.IterAll() {
var err error
admin := new(adminT)
me.cmap[c] = admin
log.Info("found in the config file", c.URL)
// a.makeClusterGroup(c)
admin.url, err = url.Parse(c.URL)
if err != nil {
badExit(err)
}
// update the droplet list
if data, err := postData(admin.url.String()+"/DropletsPB", msg); err != nil {
log.Info("/DropletsPB Error:", err)
} else {
fmt.Println("DropletsPB Response len:", len(data))
admin.droplets = new(virtpb.Droplets)
if err := admin.droplets.Unmarshal(data); err != nil {
fmt.Println("droplets marshal failed", err)
return
}
fmt.Println("Droplet len=", admin.droplets.Len())
}
}
// sit here forever refreshing the GUI
}