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.
This commit is contained in:
WofWca 2024-11-13 21:10:11 +04:00 committed by Shelikhoo
parent e6555e4a1e
commit 5e7b35bf12
No known key found for this signature in database
GPG key ID: 4C9764E9FE80A3DC

View file

@ -198,7 +198,7 @@ func EncodePollResponseWithRelayURL(offer string, success bool, natType, relayUR
Status: failReason, 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) offer, natType, relayURL, err := DecodePollResponseWithRelayURL(data)
if relayURL != "" { if relayURL != "" {
return "", "", ErrExtraInfo 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 // 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 // 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 var message ProxyPollResponse
err := json.Unmarshal(data, &message) 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 == "" { if natType == "" {
natType = "unknown" natType = "unknown"
} }
@ -254,10 +259,10 @@ func EncodeAnswerRequest(answer string, sid string) ([]byte, error) {
} }
// Returns the sdp answer and proxy sid // 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 var message ProxyAnswerRequest
err := json.Unmarshal(data, &message) err = json.Unmarshal(data, &message)
if err != nil { if err != nil {
return "", "", err return "", "", err
} }