Explorar o código

Infer API type from encoder type, rather than passing it separately

Evan Huus %!s(int64=13) %!d(string=hai) anos
pai
achega
ddf95c5718
Modificáronse 2 ficheiros con 10 adicións e 2 borrados
  1. 9 1
      broker.go
  2. 1 1
      brokerManager.go

+ 9 - 1
broker.go

@@ -143,9 +143,17 @@ func (b *broker) rcvResponseLoop() {
 	}
 }
 
-func (b *broker) sendRequest(clientID *string, api API, body encoder) (chan []byte, error) {
+func (b *broker) sendRequest(clientID *string, body encoder) (chan []byte, error) {
 	var prepEnc prepEncoder
 	var realEnc realEncoder
+	var api API
+
+	switch body.(type) {
+	case *metadataRequest:
+		api = REQUEST_METADATA
+	default:
+		return nil, EncodingError{}
+	}
 
 	req := request{api, b.correlation_id, clientID, body}
 

+ 1 - 1
brokerManager.go

@@ -62,7 +62,7 @@ func (bm *brokerManager) refreshTopics(topics []*string) error {
 		return OutOfBrokers{}
 	}
 
-	responseChan, err := b.sendRequest(bm.client.id, REQUEST_METADATA, &metadataRequest{topics})
+	responseChan, err := b.sendRequest(bm.client.id, &metadataRequest{topics})
 	if err != nil {
 		return err
 	}