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()
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())
}
}

View File

@ -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)
}
}()

View File

@ -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),
}
}