From 5e7b35bf12ce6a97bf02197eef7ffa19eb2209a6 Mon Sep 17 00:00:00 2001 From: WofWca Date: Wed, 13 Nov 2024 21:10:11 +0400 Subject: [PATCH] refactor: use named returns for some funcs This should make the functions easier to use, harder to confuse the return values with the same type. --- common/messages/proxy.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/common/messages/proxy.go b/common/messages/proxy.go index e30dbf9..6fe02be 100644 --- a/common/messages/proxy.go +++ b/common/messages/proxy.go @@ -198,7 +198,7 @@ func EncodePollResponseWithRelayURL(offer string, success bool, natType, relayUR Status: failReason, }) } -func DecodePollResponse(data []byte) (string, string, error) { +func DecodePollResponse(data []byte) (offer string, natType string, err error) { offer, natType, relayURL, err := DecodePollResponseWithRelayURL(data) if relayURL != "" { return "", "", ErrExtraInfo @@ -208,7 +208,12 @@ func DecodePollResponse(data []byte) (string, string, error) { // Decodes a poll response from the broker and returns an offer and the client's NAT type // If there is a client match, the returned offer string will be non-empty -func DecodePollResponseWithRelayURL(data []byte) (string, string, string, error) { +func DecodePollResponseWithRelayURL(data []byte) ( + offer string, + natType string, + relayURL string, + err_ error, +) { var message ProxyPollResponse err := json.Unmarshal(data, &message) @@ -231,7 +236,7 @@ func DecodePollResponseWithRelayURL(data []byte) (string, string, string, error) } } - natType := message.NAT + natType = message.NAT if natType == "" { natType = "unknown" } @@ -254,10 +259,10 @@ func EncodeAnswerRequest(answer string, sid string) ([]byte, error) { } // Returns the sdp answer and proxy sid -func DecodeAnswerRequest(data []byte) (string, string, error) { +func DecodeAnswerRequest(data []byte) (answer string, sid string, err error) { var message ProxyAnswerRequest - err := json.Unmarshal(data, &message) + err = json.Unmarshal(data, &message) if err != nil { return "", "", err }