Something went wrong on our end
-
Volker Schukai authoredVolker Schukai authored
spec.go 889 B
// Copyright 2022 schukai GmbH
// SPDX-License-Identifier: AGPL-3.0-or-later
package negotiation
import "strings"
type spec struct {
val string
q float64
}
// specs represents []spec
type specs []spec
// Len is to implement sort.Interface for Specs.
func (s specs) Len() int {
return len(s)
}
// Swap is to implement sort.Interface for Specs.
func (s specs) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
}
// Less is to implement sort.Interface for Specs.
func (s specs) Less(i, j int) bool {
if s[i].q > s[j].q {
return true
}
if s[i].q == s[j].q {
if s[i].val == "*" || strings.HasSuffix(s[i].val, "/*") {
return true
}
if s[j].val == "*" || strings.HasSuffix(s[j].val, "/*") {
return false
}
return i < j
}
return false
}
func (s specs) hasVal(val string) bool {
for _, spec := range s {
if spec.val == val {
return true
}
}
return false
}