remove result channel

This commit is contained in:
jackdaw 2016-11-30 14:44:35 +09:00
parent c22eae51c6
commit 0f0ca89ac4
3 changed files with 15 additions and 10 deletions

View File

@ -50,9 +50,9 @@ func TestSend(t *testing.T) {
})) }))
defer ts.Close() defer ts.Close()
for i := 0; i < 10; i++ { 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) Send(e)
t.Log(e.GetResult()) // t.Log(e.GetResult())
} }
} }

View File

@ -5,7 +5,6 @@ import (
"encoding/json" "encoding/json"
"loafle.com/commons/communicate/events" "loafle.com/commons/communicate/events"
"net/http" "net/http"
"strconv"
) )
type communicator struct { type communicator struct {
@ -27,8 +26,15 @@ func (c *communicator) start() {
go func(event *events.Event) { go func(event *events.Event) {
m := event.Data.(events.URLMaker) m := event.Data.(events.URLMaker)
data, _ := json.Marshal(event) data, _ := json.Marshal(event)
r, _ := http.Post(GetRootURL()+m.GetUrl(), "application/json", bytes.NewBuffer(data)) res, err := http.Post(GetRootURL()+m.GetUrl(), "application/json", bytes.NewBuffer(data))
e.Result <- events.Result{Message: strconv.Itoa(r.StatusCode)}
// todo timeout,error
if err != nil {
}
if res.StatusCode != 200 && res.StatusCode != 201 {
}
}(e) }(e)
} }
}() }()

View File

@ -30,12 +30,12 @@ type Event struct {
Time Timestamp Time Timestamp
EventType string EventType string
Data interface{} Data interface{}
Result chan Result `json:"-"` //Result chan Result `json:"-"`
} }
func (e *Event) GetResult() Result { //func (e *Event) GetResult() Result {
return <-e.Result // return <-e.Result
} //}
func NewEvent(dataType string, data interface{}) *Event { func NewEvent(dataType string, data interface{}) *Event {
return &Event{ return &Event{
@ -43,6 +43,5 @@ func NewEvent(dataType string, data interface{}) *Event {
Time: Now(), Time: Now(),
EventType: dataType, EventType: dataType,
Data: data, Data: data,
Result: make(chan Result),
} }
} }