summaryrefslogtreecommitdiff
path: root/http.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-10-27 02:29:45 -0500
committerJeff Carr <[email protected]>2024-10-27 02:29:45 -0500
commitd0767eb9843fcdb9ab0e73200d8a9516e28c200c (patch)
treeca89594578c692211753e1d988c01c9aedcd3ba3 /http.go
parent5d1729f99ba8968900eaaaa38f74f327730fffd4 (diff)
validate stuff should be here
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'http.go')
-rw-r--r--http.go42
1 files changed, 25 insertions, 17 deletions
diff --git a/http.go b/http.go
index 684c9a8..d00117b 100644
--- a/http.go
+++ b/http.go
@@ -17,11 +17,11 @@ func cleanURL(url string) string {
}
func okHandler(w http.ResponseWriter, r *http.Request) {
- var tmp string
- tmp = cleanURL(r.URL.Path)
+ var route string
+ route = cleanURL(r.URL.Path)
// is the cluster running what it should?
- if tmp == "/droplets" {
+ if route == "/droplets" {
for _, d := range me.cluster.Droplets {
var msg string
if d.StartState == pb.DropletState_ON {
@@ -40,7 +40,7 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
}
// show only what droplets should be running but are missing
- if tmp == "/missing" {
+ if route == "/missing" {
var count int
var missing int
for _, d := range me.cluster.Droplets {
@@ -63,48 +63,56 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
return
}
- if tmp == "/favicon.ico" {
+ if route == "/favicon.ico" {
// w.Header().Set("Content-Type", "image/svg+xml")
w.Header().Set("Content-Type", "image/png")
writeFile(w, "ipv6.png")
return
}
- if tmp == "/goReference.svg" {
+ if route == "/goReference.svg" {
w.Header().Set("Content-Type", "image/svg+xml")
writeFile(w, "goReference.svg")
return
}
- if tmp == "/dumplibvirtxml" {
+ if route == "/dumplibvirtxml" {
virtigoxml.DumpLibvirtxmlDomainNames()
return
}
- if tmp == "/uptime" {
- b, s := clusterHealthy()
- if b {
- log.Info("Handling URL:", tmp, "cluster is ok", s)
+ if route == "/uptime" {
+ ok, s := clusterHealthy()
+ if ok {
+ log.Info("Handling URL:", route, "cluster is ok", s)
fmt.Fprintln(w, s)
} else {
- log.Info("Handling URL:", tmp, "cluster is not right yet", s)
+ log.Info("Handling URL:", route, "cluster is not right yet", s)
fmt.Fprintln(w, s)
}
return
}
- if tmp == "/start" {
- start := r.URL.Query().Get("start")
+ if route == "/start" {
+ hostname := r.URL.Query().Get("hostname")
+ if hostname == "" {
+ log.Warn("start failed. hostname is blank", cleanURL(r.URL.Path))
+ fmt.Fprintln(w, "start failed. hostname is blank", cleanURL(r.URL.Path))
+ return
+ }
+ log.Warn("hostname is", hostname)
+ fmt.Fprintln(w, "hostname is", hostname)
+
// log.Warn("Handling URL:", tmp, "start droplet", start)
- b, result := Start(start)
+ b, result := Start(hostname)
log.Warn("Start returned =", b, "result =", result)
fmt.Fprintln(w, "Start() returned", b)
fmt.Fprintln(w, "result:", result)
return
}
- log.Warn("BAD URL =", tmp)
- fmt.Fprintln(w, "BAD URL tmp =", tmp)
+ log.Warn("BAD URL =", route)
+ fmt.Fprintln(w, "BAD URL tmp =", route)
}
// write a file out to the http socket