Skip to content

Commit

Permalink
Replace the interface{} type with the shorter any
Browse files Browse the repository at this point in the history
Go 1.18 includes the predeclared identifier "any", which is a shorter
alias of "interface{}". The following command was used to replace each
instance of "interface{}" with "any" in the codebase excluding the
vendor directory.
`gofmt -r 'interface{} -> any' -w .`
  • Loading branch information
enarha committed Oct 8, 2023
1 parent 0aa7ce4 commit 9afbfb7
Show file tree
Hide file tree
Showing 21 changed files with 107 additions and 107 deletions.
6 changes: 3 additions & 3 deletions pkg/api/server/cel/cel.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,16 @@ func ParseFilter(env *cel.Env, filter string) (cel.Program, error) {
// allowAll is a CEL program implementation that always returns true.
type allowAll struct{}

func (allowAll) ContextEval(context.Context, interface{}) (ref.Val, *cel.EvalDetails, error) {
func (allowAll) ContextEval(context.Context, any) (ref.Val, *cel.EvalDetails, error) {
return types.Bool(true), nil, nil
}

func (allowAll) Eval(interface{}) (ref.Val, *cel.EvalDetails, error) {
func (allowAll) Eval(any) (ref.Val, *cel.EvalDetails, error) {
return types.Bool(true), nil, nil
}

// Match determines whether the given CEL filter matches the result.
func Match(prg cel.Program, data map[string]interface{}) (bool, error) {
func Match(prg cel.Program, data map[string]any) (bool, error) {
if prg == nil {
return true, nil
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/server/db/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ type Annotations map[string]string

// Scan resolves serialized data read from database into an Annotation.
// This implements the sql.Scanner interface.
func (ann *Annotations) Scan(value interface{}) error {
func (ann *Annotations) Scan(value any) error {
if ann == nil {
return errors.New("the annotation pointer mustn't be nil")
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/api/server/test/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,6 @@ type testLogger struct {
t *testing.T
}

func (t *testLogger) Printf(format string, args ...interface{}) {
func (t *testLogger) Printf(format string, args ...any) {
t.t.Logf(format, args...)
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/api/server/v1alpha2/log/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func initConfig(ctx context.Context, cfg *server.Config) (*s3.Client, error) {
var awsConfig aws.Config
var err error
if len(cfg.S3_ENDPOINT) > 0 {
customResolver := aws.EndpointResolverWithOptionsFunc(func(service, region string, options ...interface{}) (aws.Endpoint, error) {
customResolver := aws.EndpointResolverWithOptionsFunc(func(service, region string, options ...any) (aws.Endpoint, error) {
if region == cfg.S3_REGION {
return aws.Endpoint{
URL: cfg.S3_ENDPOINT,
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/server/v1alpha2/record/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,14 @@ func Match(r *pb.Record, prg cel.Program) (bool, error) {
return false, nil
}

var m map[string]interface{}
var m map[string]any
if d := r.GetData().GetValue(); d != nil {
if err := json.Unmarshal(r.GetData().GetValue(), &m); err != nil {
return false, err
}
}

return resultscel.Match(prg, map[string]interface{}{
return resultscel.Match(prg, map[string]any{
"name": r.GetName(),
"data_type": r.GetData().GetType(),
"data": m,
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/server/v1alpha2/result/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func Match(r *pb.Result, prg cel.Program) (bool, error) {
if r == nil {
return false, nil
}
return resultscel.Match(prg, map[string]interface{}{
return resultscel.Match(prg, map[string]any{
"result": r,
})
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/config/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type Store struct {
}

// NewStore creates a new store of Configs and optionally calls functions when ConfigMaps are updated.
func NewStore(logger configmap.Logger, onAfterStore ...func(name string, value interface{})) *Store {
func NewStore(logger configmap.Logger, onAfterStore ...func(name string, value any)) *Store {
store := &Store{
UntypedStore: configmap.NewUntypedStore(
"results",
Expand Down
4 changes: 2 additions & 2 deletions pkg/internal/jsonutil/jsonutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (

// AnyBytes returns the marshalled bytes of an Any proto wrapping the given
// message, or causes the test to fail.
func AnyBytes(t testing.TB, i interface{}) []byte {
func AnyBytes(t testing.TB, v any) []byte {
t.Helper()
b, err := json.Marshal(i)
b, err := json.Marshal(v)
if err != nil {
t.Fatalf("error marshalling Any proto: %v", err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/pipelinerunmetrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ func viewUnregister(logger *zap.SugaredLogger) {

// MetricsOnStore returns a function that checks if metrics are configured for a config.Store, and registers it if so
func MetricsOnStore(logger *zap.SugaredLogger) func(name string,
value interface{}) {
return func(name string, value interface{}) {
value any) {
return func(name string, value any) {
if name != config.GetMetricsConfigName() {
return
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/taskrunmetrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ func viewUnregister(logger *zap.SugaredLogger) {

// MetricsOnStore returns a function that checks if metrics are configured for a config.Store, and registers it if so
func MetricsOnStore(logger *zap.SugaredLogger) func(name string,
value interface{}) {
return func(name string, value interface{}) {
value any) {
return func(name string, value any) {
if name != config.GetMetricsConfigName() {
return
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/watcher/convert/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,8 @@ func TestToProto(t *testing.T) {

}

func toJSON(i interface{}) []byte {
b, err := json.Marshal(i)
func toJSON(v any) []byte {
b, err := json.Marshal(v)
if err != nil {
panic(fmt.Sprintf("error marshalling json: %v", err))
}
Expand Down
6 changes: 3 additions & 3 deletions proto/pipeline/v1beta1/pipeline_go_proto/common.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 11 additions & 11 deletions proto/pipeline/v1beta1/pipeline_go_proto/pipelinerun.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9afbfb7

Please sign in to comment.