mirror of
https://github.com/pion/stun.git
synced 2025-10-07 08:40:53 +08:00
attributes:error-code: use map instead of swich-case
This commit is contained in:
@@ -14,24 +14,21 @@ const (
|
|||||||
CodeServerError ErrorCode = 500
|
CodeServerError ErrorCode = 500
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var errorReasons = map[ErrorCode]string{
|
||||||
|
CodeTryAlternate: "Try Alternate",
|
||||||
|
CodeBadRequest: "Bad Request",
|
||||||
|
CodeUnauthorised: "Unauthorised",
|
||||||
|
CodeUnknownAttribute: "Unknown Attribute",
|
||||||
|
CodeStaleNonce: "Stale Nonce",
|
||||||
|
CodeServerError: "Server Error",
|
||||||
|
CodeRoleConflict: "Role Conflict",
|
||||||
|
}
|
||||||
|
|
||||||
// Reason returns recommended reason string.
|
// Reason returns recommended reason string.
|
||||||
func (c ErrorCode) Reason() string {
|
func (c ErrorCode) Reason() string {
|
||||||
switch c {
|
reason, ok := errorReasons[c]
|
||||||
case CodeTryAlternate:
|
if !ok {
|
||||||
return "Try Alternate"
|
|
||||||
case CodeBadRequest:
|
|
||||||
return "Bad Request"
|
|
||||||
case CodeUnauthorised:
|
|
||||||
return "Unauthorised"
|
|
||||||
case CodeUnknownAttribute:
|
|
||||||
return "Unknown attribute"
|
|
||||||
case CodeStaleNonce:
|
|
||||||
return "Stale Nonce"
|
|
||||||
case CodeServerError:
|
|
||||||
return "Server Error"
|
|
||||||
case CodeRoleConflict:
|
|
||||||
return "Role conflict"
|
|
||||||
default:
|
|
||||||
return "Unknown Error"
|
return "Unknown Error"
|
||||||
}
|
}
|
||||||
|
return reason
|
||||||
}
|
}
|
||||||
|
@@ -8,6 +8,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// SameTransaction returns true of a and b have same Transaction ID.
|
// SameTransaction returns true of a and b have same Transaction ID.
|
||||||
|
// DEPRECATED: remove usage.
|
||||||
func SameTransaction(a *Message, b *Message) bool {
|
func SameTransaction(a *Message, b *Message) bool {
|
||||||
return a.TransactionID == b.TransactionID
|
return a.TransactionID == b.TransactionID
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user