mirror of
https://github.com/libp2p/go-libp2p-core.git
synced 2025-01-14 02:20:06 +08:00
remove unused MultistreamSemverMatcher (#277)
This commit is contained in:
parent
247031f933
commit
b6981edffe
1
go.mod
1
go.mod
@ -4,7 +4,6 @@ go 1.17
|
||||
|
||||
require (
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.1.3
|
||||
github.com/coreos/go-semver v0.3.0
|
||||
github.com/gogo/protobuf v1.3.1
|
||||
github.com/ipfs/go-cid v0.2.0
|
||||
github.com/ipfs/go-log/v2 v2.5.1
|
||||
|
2
go.sum
2
go.sum
@ -5,8 +5,6 @@ github.com/btcsuite/btcd/btcec/v2 v2.1.3/go.mod h1:ctjw4H1kknNJmRN4iP1R7bTQ+v3GJ
|
||||
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.0/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc=
|
||||
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 h1:q0rUy8C/TYNBQS1+CGKw68tLOFYSNEs0TFnxxnS9+4U=
|
||||
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc=
|
||||
github.com/coreos/go-semver v0.3.0 h1:wkHLiw0WNATZnSG7epLsujiMCgPAc9xhjJ4tgnAxmfM=
|
||||
github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
|
@ -1,42 +0,0 @@
|
||||
package helpers
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/coreos/go-semver/semver"
|
||||
"github.com/libp2p/go-libp2p-core/protocol"
|
||||
)
|
||||
|
||||
// MultistreamSemverMatcher returns a matcher function for a given base protocol.
|
||||
// The matcher function will return a boolean indicating whether a protocol ID
|
||||
// matches the base protocol. A given protocol ID matches the base protocol if
|
||||
// the IDs are the same and if the semantic version of the base protocol is the
|
||||
// same or higher than that of the protocol ID provided.
|
||||
// TODO
|
||||
func MultistreamSemverMatcher(base protocol.ID) (func(string) bool, error) {
|
||||
parts := strings.Split(string(base), "/")
|
||||
vers, err := semver.NewVersion(parts[len(parts)-1])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return func(check string) bool {
|
||||
chparts := strings.Split(check, "/")
|
||||
if len(chparts) != len(parts) {
|
||||
return false
|
||||
}
|
||||
|
||||
for i, v := range chparts[:len(chparts)-1] {
|
||||
if parts[i] != v {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
chvers, err := semver.NewVersion(chparts[len(chparts)-1])
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
return vers.Major == chvers.Major && vers.Minor >= chvers.Minor
|
||||
}, nil
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
package helpers
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSemverMatching(t *testing.T) {
|
||||
m, err := MultistreamSemverMatcher("/testing/4.3.5")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
cases := map[string]bool{
|
||||
"/testing/4.3.0": true,
|
||||
"/testing/4.3.7": true,
|
||||
"/testing/4.3.5": true,
|
||||
"/testing/4.2.7": true,
|
||||
"/testing/4.0.0": true,
|
||||
"/testing/5.0.0": false,
|
||||
"/cars/dogs/4.3.5": false,
|
||||
"/foo/1.0.0": false,
|
||||
"": false,
|
||||
"dogs": false,
|
||||
"/foo": false,
|
||||
"/foo/1.1.1.1": false,
|
||||
}
|
||||
|
||||
for p, ok := range cases {
|
||||
if m(p) != ok {
|
||||
t.Fatalf("expected %s to be %t", p, ok)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user