summaryrefslogtreecommitdiff
path: root/http.go
diff options
context:
space:
mode:
Diffstat (limited to 'http.go')
-rw-r--r--http.go36
1 files changed, 17 insertions, 19 deletions
diff --git a/http.go b/http.go
index 452ff74..6afff8b 100644
--- a/http.go
+++ b/http.go
@@ -21,8 +21,8 @@ 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)
+ // log.HttpMode(w)
+ // defer log.HttpMode(nil)
msg, err := ioutil.ReadAll(r.Body) // Read the body as []byte
if err != nil {
@@ -70,26 +70,24 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
return
}
- if route == "/start" {
- hostname := r.URL.Query().Get("hostname")
- if hostname == "" {
- log.Warn("start failed. hostname is blank", cleanURL(r.URL.Path))
+ if route == "/event" {
+ var e *virtpb.Event
+ e = new(virtpb.Event)
+ if err := e.Unmarshal(msg); err != nil {
+ log.Info("proto.Unmarshal() failed on wire message len", len(msg))
+ log.Info("error =", err)
return
}
- log.Warn("hostname is", hostname)
-
- // log.Warn("Handling URL:", tmp, "start droplet", start)
- result, err := Start(hostname)
- if err == nil {
- 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 {
- log.Info(result)
- log.Info(err)
- log.Info(hostname, "start failed")
+ log.Info("/event proto.Unmarshal() worked on msg len", len(msg), "hostname =", e.DropletUuid)
+ result := doEvent(e)
+ data, err := result.Marshal()
+ if err != nil {
+ log.Info("/event marshal failed", err, "len(data) =", len(data))
+ fmt.Fprintln(w, "/event failed", err)
+ return
}
+ w.Write(data)
+ // fmt.Fprintln("droplet marshal failed", err)
return
}