Skip to content

Commit 40cf56e

Browse files
committed
uses semver/v3
1 parent f8ee370 commit 40cf56e

File tree

6 files changed

+21
-16
lines changed

6 files changed

+21
-16
lines changed

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ go 1.13
1515
// replace github.com/hedzr/go-ringbuf => ../go-ringbuf
1616

1717
require (
18-
github.com/Masterminds/semver v1.5.0
18+
github.com/Masterminds/semver/v3 v3.1.1
1919
github.com/hedzr/log v0.3.21
20+
gopkg.in/hedzr/errors.v2 v2.1.5
2021
)

go.sum

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

version/backend_factor.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package version
22

33
import (
44
"fmt"
5-
"github.com/Masterminds/semver"
5+
"github.com/Masterminds/semver/v3"
66
"github.com/hedzr/lb/lbapi"
77
"github.com/hedzr/log"
88
)
@@ -19,7 +19,7 @@ type VersioningBackendFactor interface {
1919
// address is like 'host:port' typically, but you can use any forms you like.
2020
func NewBackendFactor(version string, addr string) VersioningBackendFactor {
2121
f := &backendFactor{
22-
version: check(version),
22+
version: verCleanup(version),
2323
addr: addr,
2424
}
2525

@@ -38,7 +38,7 @@ type backendFactor struct {
3838
versionObj *semver.Version
3939
}
4040

41-
func check(v string) string {
41+
func verCleanup(v string) string {
4242
if v[0] == 'v' {
4343
return v[1:]
4444
}

version/builder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package version
22

33
import (
4-
"github.com/Masterminds/semver"
4+
"github.com/Masterminds/semver/v3"
55
"github.com/hedzr/lb/lbapi"
66
"github.com/hedzr/lb/wrr"
77
"github.com/hedzr/log"

version/constraints_peer.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package version
22

33
import (
44
"fmt"
5-
"github.com/Masterminds/semver"
5+
"github.com/Masterminds/semver/v3"
66
"github.com/hedzr/lb/lbapi"
77
)
88

@@ -34,15 +34,18 @@ import (
3434
//
3535
// See also NewBackendsFactor and New
3636
func NewConstrainablePeer(constraints string, weight int) (peer lbapi.Constrainable) {
37-
p := &constrainablePeer{
38-
constraints: constraints,
39-
weight: weight,
40-
constraintsObj: nil,
41-
}
4237
vc, err := semver.NewConstraint(constraints)
4338
if err == nil {
44-
p.constraintsObj = vc
45-
peer = p
39+
peer = NewConstrainablePeerFromObj(vc, weight)
40+
}
41+
return
42+
}
43+
44+
func NewConstrainablePeerFromObj(constraints *semver.Constraints, weight int) (peer lbapi.Constrainable) {
45+
peer = &constrainablePeer{
46+
weight: weight,
47+
constraints: constraints.String(),
48+
constraintsObj: constraints,
4649
}
4750
return
4851
}

version/constraints_peer_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package version
22

33
import (
4-
"github.com/Masterminds/semver"
4+
"github.com/Masterminds/semver/v3"
55
"testing"
66
)
77

0 commit comments

Comments
 (0)