From 0f0ca89ac4baeaf95dfa6f730a4d268ac5e450d9 Mon Sep 17 00:00:00 2001 From: jackdaw Date: Wed, 30 Nov 2016 14:44:35 +0900 Subject: [PATCH] remove result channel --- communicate_test.go | 4 ++-- communicator.go | 12 +++++++++--- events/event.go | 9 ++++----- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/communicate_test.go b/communicate_test.go index 4c90e13..9bb6b65 100644 --- a/communicate_test.go +++ b/communicate_test.go @@ -50,9 +50,9 @@ func TestSend(t *testing.T) { })) defer ts.Close() for i := 0; i < 10; i++ { - e := events.NewEvent(events.CENTRAL_EVENT, events.CollectorInstallEvent{Message: "Test"}) + e := events.NewEvent(events.CENTRAL_EVENT, events.CollectorInstallEvent{Version: "Test"}) Send(e) - t.Log(e.GetResult()) + // t.Log(e.GetResult()) } } diff --git a/communicator.go b/communicator.go index 676ace0..8419ded 100644 --- a/communicator.go +++ b/communicator.go @@ -5,7 +5,6 @@ import ( "encoding/json" "loafle.com/commons/communicate/events" "net/http" - "strconv" ) type communicator struct { @@ -27,8 +26,15 @@ func (c *communicator) start() { go func(event *events.Event) { m := event.Data.(events.URLMaker) data, _ := json.Marshal(event) - r, _ := http.Post(GetRootURL()+m.GetUrl(), "application/json", bytes.NewBuffer(data)) - e.Result <- events.Result{Message: strconv.Itoa(r.StatusCode)} + res, err := http.Post(GetRootURL()+m.GetUrl(), "application/json", bytes.NewBuffer(data)) + + // todo timeout,error + if err != nil { + + } + if res.StatusCode != 200 && res.StatusCode != 201 { + + } }(e) } }() diff --git a/events/event.go b/events/event.go index f74c261..b60b2f2 100644 --- a/events/event.go +++ b/events/event.go @@ -30,12 +30,12 @@ type Event struct { Time Timestamp EventType string Data interface{} - Result chan Result `json:"-"` + //Result chan Result `json:"-"` } -func (e *Event) GetResult() Result { - return <-e.Result -} +//func (e *Event) GetResult() Result { +// return <-e.Result +//} func NewEvent(dataType string, data interface{}) *Event { return &Event{ @@ -43,6 +43,5 @@ func NewEvent(dataType string, data interface{}) *Event { Time: Now(), EventType: dataType, Data: data, - Result: make(chan Result), } }