Skip to content

Commit e0c0e24

Browse files
committed
Chore: use a single package for all Feature structs
Also replaces `golang.org/x/exp/slices` with `slices` from the Go 1.21 stdlib > small spin-off from dapr#3046 Signed-off-by: ItalyPaleAle <[email protected]>
1 parent 2fcfc1a commit e0c0e24

File tree

22 files changed

+49
-48
lines changed

22 files changed

+49
-48
lines changed

.build-tools/go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ require (
99
github.com/invopop/jsonschema v0.6.0
1010
github.com/spf13/cobra v1.6.1
1111
github.com/xeipuuv/gojsonschema v1.2.1-0.20201027075954-b076d39a02e5
12-
golang.org/x/exp v0.0.0-20231006140011-7918f672742d
1312
gopkg.in/yaml.v3 v3.0.1
1413
sigs.k8s.io/yaml v1.4.0
1514
)

.build-tools/go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 h1:EzJWgHo
4545
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ=
4646
github.com/xeipuuv/gojsonschema v1.2.1-0.20201027075954-b076d39a02e5 h1:ImnGIsrcG8vwbovhYvvSY8fagVV6QhCWSWXfzwGDLVs=
4747
github.com/xeipuuv/gojsonschema v1.2.1-0.20201027075954-b076d39a02e5/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y=
48-
golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI=
49-
golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo=
5048
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
5149
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
5250
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

.build-tools/pkg/metadataschema/validators.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@ package metadataschema
1616
import (
1717
"errors"
1818
"fmt"
19+
"slices"
1920
"strings"
2021

21-
"golang.org/x/exp/slices"
22-
2322
mdutils "github.com/dapr/components-contrib/metadata"
2423
)
2524

.golangci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ linters-settings:
131131
desc: "must use context"
132132
- pkg: "github.com/pkg/errors"
133133
desc: "must use standard library (errors package and/or fmt.Errorf)"
134+
- pkg: "golang.org/x/exp/slices"
135+
desc: "must use slices from standard library"
134136
- pkg: "github.com/go-chi/chi$"
135137
desc: "must use github.com/go-chi/chi/v5"
136138
- pkg: "github.com/cenkalti/backoff$"

bindings/cloudflare/queues/cfqueues.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@ import (
2020
"io"
2121
"net/http"
2222
"reflect"
23+
"slices"
2324
"strconv"
2425

25-
"golang.org/x/exp/slices"
26-
2726
"github.com/dapr/components-contrib/bindings"
2827
"github.com/dapr/components-contrib/common/component/cloudflare/workers"
2928
contribMetadata "github.com/dapr/components-contrib/metadata"

common/features/feature.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
Copyright 2023 The Dapr Authors
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
14+
package features
15+
16+
import (
17+
"slices"
18+
)
19+
20+
// Feature is a generic type for features supported by components.
21+
type Feature[T any] string
22+
23+
// IsPresent checks if a given feature is present in the list.
24+
func (f Feature[T]) IsPresent(features []Feature[T]) bool {
25+
return slices.Contains(features, f)
26+
}

configuration/postgres/postgres.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"fmt"
2121
"reflect"
2222
"regexp"
23+
"slices"
2324
"strconv"
2425
"strings"
2526
"sync"
@@ -28,7 +29,6 @@ import (
2829
"github.com/jackc/pgx/v5"
2930
"github.com/jackc/pgx/v5/pgconn"
3031
"github.com/jackc/pgx/v5/pgxpool"
31-
"golang.org/x/exp/slices"
3232

3333
"github.com/dapr/components-contrib/configuration"
3434
contribMetadata "github.com/dapr/components-contrib/metadata"

crypto/feature.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,8 @@ limitations under the License.
1414
package crypto
1515

1616
import (
17-
"golang.org/x/exp/slices"
17+
"github.com/dapr/components-contrib/common/features"
1818
)
1919

2020
// Feature names a feature that can be implemented by the crypto provider components.
21-
type Feature string
22-
23-
// IsPresent checks if a given feature is present in the list.
24-
func (f Feature) IsPresent(features []Feature) bool {
25-
return slices.Contains(features, f)
26-
}
21+
type Feature = features.Feature[SubtleCrypto]

crypto/key.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ package crypto
1515

1616
import (
1717
"encoding/json"
18+
"slices"
1819
"time"
1920

2021
"github.com/lestrrat-go/jwx/v2/jwk"
21-
"golang.org/x/exp/slices"
2222
)
2323

2424
// Key extends jwk.Key adding optional properties for determining if the key is valid (time bounds) or can be used for certain purposes.

middleware/http/opa/middleware.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ import (
2424
"net/http"
2525
"net/textproto"
2626
"reflect"
27+
"slices"
2728
"strconv"
2829
"strings"
2930
"time"
3031

3132
"github.com/open-policy-agent/opa/rego"
32-
"golang.org/x/exp/slices"
3333

3434
"github.com/dapr/components-contrib/common/httputils"
3535
contribMetadata "github.com/dapr/components-contrib/metadata"

0 commit comments

Comments
 (0)