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 and auto generated protobuf files (.pb.go).
`gofmt -r 'interface{} -> any' -w .`
  • Loading branch information
enarha authored and tekton-robot committed Oct 31, 2023
1 parent 8abd20d commit 1ad89d2
Show file tree
Hide file tree
Showing 13 changed files with 23 additions and 23 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
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...)
}
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
4 changes: 2 additions & 2 deletions tools/postgres-migrate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func convertRecord(r *db.Record) error {
// for more details). We handle this by stripping out the problematic fields,
// converting the type, then resetting the fields later.
var gen, observedGen int64
var wantType interface{}
var wantType any
switch m := out.(type) {
case *pb.TaskRun:
r.Type = "tekton.dev/v1beta1.TaskRun"
Expand All @@ -203,7 +203,7 @@ func convertRecord(r *db.Record) error {
m.Status.ObservedGeneration = 0
default:
r.Type = any.TypeUrl
wantType = map[string]interface{}{}
wantType = map[string]any{}
}

// Sanity check that the converted JSON can be safely marshalled into
Expand Down
6 changes: 3 additions & 3 deletions tools/postgres-migrate/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ func TestMigrate(t *testing.T) {
})
}

func clearDB(db *gorm.DB, types ...interface{}) error {
func clearDB(db *gorm.DB, types ...any) error {
for _, t := range types {
out := db.Session(&gorm.Session{AllowGlobalUpdate: true}).Delete(t)
if out.Error != nil {
Expand Down Expand Up @@ -342,8 +342,8 @@ func protodata(t *testing.T, m proto.Message) []byte {
return b
}

func jsondata(t *testing.T, i interface{}) []byte {
b, err := json.Marshal(i)
func jsondata(t *testing.T, v any) []byte {
b, err := json.Marshal(v)
if err != nil {
t.Fatalf("error marshinalling json: %v", err)
}
Expand Down

0 comments on commit 1ad89d2

Please sign in to comment.