debug changes

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-11-12 09:49:42 -06:00
parent 4883c26547
commit a4a2d7a01f
1 changed files with 14 additions and 21 deletions

35
http.go
View File

@ -19,15 +19,16 @@ func cleanURL(url string) string {
func okHandler(w http.ResponseWriter, r *http.Request) {
var route string
route = cleanURL(r.URL.Path)
log.HttpMode(w)
defer log.HttpMode(nil)
if route == "/uptime" {
ok, s := uptimeCheck()
log.Info(s)
if ok {
log.Info("Handling URL:", route, "cluster is ok", s)
fmt.Fprintln(w, s)
log.Info("Handling URL:", route, "cluster is ok")
} else {
log.Info("Handling URL:", route, "cluster is not right yet", s)
fmt.Fprintln(w, s)
log.Info("Handling URL:", route, "cluster is not right yet")
}
return
}
@ -36,50 +37,44 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
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)
result, err := Start(hostname)
if err == nil {
fmt.Fprintln(w, result)
fmt.Fprintln(w, hostname, "started output ok")
fmt.Fprintln(w, hostname, "need to parse the output here")
fmt.Fprintln(w, hostname, "todo: switch to protobuf here")
log.Info(result)
log.Info(hostname, "started output ok")
log.Info(hostname, "need to parse the output here")
log.Info(hostname, "todo: switch to protobuf here")
} else {
fmt.Fprintln(w, result)
fmt.Fprintln(w, err)
fmt.Fprintln(w, hostname, "start failed")
log.Info(result)
log.Info(err)
log.Info(hostname, "start failed")
}
return
}
if route == "/import" {
log.Info("virtigo import starts here")
fmt.Fprintln(w, "virtigo import starts here")
result, err := importDomain(w, r)
if err != nil {
log.Info("virtigo import failed")
log.Info(result)
fmt.Fprintln(w, "virtigo import failed")
fmt.Fprintln(w, result)
return
}
log.Info("virtigo import worked")
fmt.Fprintln(w, "virtigo import worked")
return
}
// toggle poll logging
if route == "/poll" {
if POLL.Get() {
fmt.Fprintln(w, "POLL is true")
log.Info("POLL is true")
POLL.SetBool(false)
} else {
fmt.Fprintln(w, "POLL is false")
log.Info("POLL is false")
POLL.SetBool(true)
}
return
@ -117,7 +112,6 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
if route == "/quit" {
log.Warn("writing out config file and exiting virtigo")
fmt.Fprintln(w, "writing out config file and exiting virtigo")
if err := me.cluster.ConfigSave(); err != nil {
log.Info("configsave error", err)
} else {
@ -140,7 +134,6 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
}
log.Warn("BAD URL =", route)
fmt.Fprintln(w, "BAD URL tmp =", route)
}
// write a file out to the http socket