Pass obj type to functions

This commit is contained in:
Soam Vasani
2016-12-12 08:46:19 -08:00
parent b7906905c2
commit 5c6dcca19d
2 changed files with 11 additions and 3 deletions
+1 -1
View File
@@ -194,6 +194,6 @@ func (ws *watchSubscription) eventDispatchLoop(poster *Poster) {
if err != nil { if err != nil {
log.Println("Failed to serialize object: %v", err) log.Println("Failed to serialize object: %v", err)
} }
poster.Post(string(ev.Type), ws.Watch.Url, &buf) poster.Post(string(ev.Type), ws.Watch.ObjType, ws.Watch.Url, &buf)
} }
} }
+10 -2
View File
@@ -18,6 +18,7 @@ package kubewatcher
import ( import (
"io" "io"
"io/ioutil"
"log" "log"
"net/http" "net/http"
"strings" "strings"
@@ -30,6 +31,7 @@ type (
} }
postRequest struct { postRequest struct {
eventType string eventType string
objType string
relativeUrl string relativeUrl string
body io.Reader body io.Reader
} }
@@ -56,6 +58,7 @@ func (p *Poster) svc() {
} }
req.Header.Add("Content-Type", "application/json") req.Header.Add("Content-Type", "application/json")
req.Header.Add("X-Kubernetes-Event-Type", r.eventType) req.Header.Add("X-Kubernetes-Event-Type", r.eventType)
req.Header.Add("X-Kubernetes-Object-Type", r.objType)
resp, err := http.DefaultClient.Do(req) resp, err := http.DefaultClient.Do(req)
if err != nil { if err != nil {
@@ -63,17 +66,22 @@ func (p *Poster) svc() {
// TODO retries, persistence, etc. // TODO retries, persistence, etc.
} }
resp.Body.Close()
if resp.StatusCode != 200 { if resp.StatusCode != 200 {
log.Printf("request failed: %v", resp.StatusCode) log.Printf("request failed: %v", resp.StatusCode)
body, err := ioutil.ReadAll(resp.Body)
if err == nil {
log.Printf("request error: %v", body)
}
// TODO retries etc. // TODO retries etc.
} }
resp.Body.Close()
} }
} }
func (p *Poster) Post(eventType, relativeUrl string, body io.Reader) { func (p *Poster) Post(eventType, objType, relativeUrl string, body io.Reader) {
p.requestChannel <- &postRequest{ p.requestChannel <- &postRequest{
eventType: eventType, eventType: eventType,
objType: objType,
relativeUrl: relativeUrl, relativeUrl: relativeUrl,
body: body, body: body,
} }