make it possible to set VersionTLS to a draft version

Go doesn't allow duplicate cases in a switch statement.
This commit is contained in:
Marten Seemann 2020-10-29 15:04:55 +07:00
parent b034f1ac7c
commit 2839cbdcff
2 changed files with 11 additions and 9 deletions

View file

@ -34,15 +34,13 @@ const (
)
func versionToALPN(v protocol.VersionNumber) string {
//nolint:exhaustive
switch v {
case protocol.VersionTLS, protocol.VersionDraft29:
if v == protocol.VersionTLS || v == protocol.VersionDraft29 {
return nextProtoH3Draft29
case protocol.VersionDraft32:
return nextProtoH3Draft32
default:
return ""
}
if v == protocol.VersionDraft32 {
return nextProtoH3Draft32
}
return ""
}
// contextKey is a value for use with context.WithValue. It's used as

View file

@ -35,6 +35,12 @@ func IsValidVersion(v VersionNumber) bool {
}
func (vn VersionNumber) String() string {
// For releases, VersionTLS will be set to a draft version.
// A switch statement can't contain duplicate cases.
if vn == VersionTLS && VersionTLS != VersionDraft29 && VersionTLS != VersionDraft32 {
return "TLS dev version (WIP)"
}
//nolint:exhaustive
switch vn {
case VersionWhatever:
return "whatever"
@ -44,8 +50,6 @@ func (vn VersionNumber) String() string {
return "draft-29"
case VersionDraft32:
return "draft-32"
case VersionTLS:
return "TLS dev version (WIP)"
default:
if vn.isGQUIC() {
return fmt.Sprintf("gQUIC %d", vn.toGQUICVersion())