func finalizeReq(reqDone network.Request) { if reqDone.To != "" { err := sendMessageToSpecificService(reqDone.ID, reqDone.To) if err != nil { log.Println("Cannot dispatch message to service", reqDone.To) return } addRequestToHistory(reqDone) } else { if len(destinations) > 0 { errCounter := sendMessageToDestinations(reqDone.ID) if errCounter < len(destinations) { // This is for requests to multiple destinations // because I have to wait till every destination // responde me before consider the request complete reqCounter := len(destinations) - errCounter reqDone.Counter = reqCounter addRequestToHistory(reqDone) } if errCounter > 0 { log.Println("Cannot dispatch message to all the destinations") if errCounter == len(destinations) { respondeToRequest(reqDone.From, reqDone.ID, "done") } return } } else { respondeToRequest(reqDone.From, reqDone.ID, "done") } } }