Skip to content

Commit

Permalink
use golang.org/exp/x/slices
Browse files Browse the repository at this point in the history
  • Loading branch information
magiconair committed Jun 13, 2023
1 parent a70dfc2 commit 772a0ac
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 20 deletions.
9 changes: 0 additions & 9 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1431,15 +1431,6 @@ func safeAssign(t, ptrT interface{}) error {
return nil
}

func uint32SliceContains(n uint32, a []uint32) bool {
for _, v := range a {
if n == v {
return true
}
}
return false
}

type InvalidResponseTypeError struct {
got, want interface{}
}
Expand Down
3 changes: 2 additions & 1 deletion client_sub.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/gopcua/opcua/stats"
"github.com/gopcua/opcua/ua"
"github.com/gopcua/opcua/uasc"
"golang.org/x/exp/slices"
)

// Subscribe creates a Subscription with given parameters.
Expand Down Expand Up @@ -156,7 +157,7 @@ func (c *Client) sendRepublishRequests(ctx context.Context, sub *Subscription, a
// todo(fs): check if sub.nextSeq is in the available sequence numbers
// todo(fs): if not then we need to decide whether we fail b/c of data loss
// todo(fs): or whether we log it and continue.
if len(availableSeq) > 0 && !uint32SliceContains(sub.nextSeq, availableSeq) {
if len(availableSeq) > 0 && !slices.Contains(availableSeq, sub.nextSeq) {
log.Printf("sub %d: next sequence number %d not in retransmission buffer %v", sub.SubscriptionID, sub.nextSeq, availableSeq)
}

Expand Down
13 changes: 3 additions & 10 deletions debug/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"log"
"os"
"strings"

"golang.org/x/exp/slices"
)

// Flags contains the debug flags set by OPC_DEBUG.
Expand Down Expand Up @@ -58,14 +60,5 @@ func ToJSON(v interface{}) string {
// FlagSet returns true if the OPCUA_DEBUG environment variable contains the
// given flag.
func FlagSet(name string) bool {
return stringSliceContains(name, strings.Fields(Flags))
}

func stringSliceContains(s string, vals []string) bool {
for _, v := range vals {
if s == v {
return true
}
}
return false
return slices.Contains(strings.Fields(Flags), name)
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/pascaldekloe/goe v0.1.0
github.com/pkg/errors v0.8.1
golang.org/x/crypto v0.7.0
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1
)

require (
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A=
golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 h1:k/i9J1pBpvlfR+9QsetwPyERsqu1GIbi967PQMq3Ivc=
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w=
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.6.0 h1:clScbb1cHjoCkyRbWwBEUZ5H/tIFu5TAXIqaZD0Gcjw=
Expand Down

0 comments on commit 772a0ac

Please sign in to comment.