Skip to content

Commit

Permalink
♻️ interface{} -> any (#1261)
Browse files Browse the repository at this point in the history
  • Loading branch information
MatiasFrank authored Oct 4, 2024
1 parent fb8f303 commit d4af08f
Show file tree
Hide file tree
Showing 15 changed files with 34 additions and 34 deletions.
2 changes: 1 addition & 1 deletion cmd/rig-ops/cmd/base/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (

var options []fx.Option

func Register(f interface{}) func(cmd *cobra.Command, args []string) error {
func Register(f any) func(cmd *cobra.Command, args []string) error {
options = append(options,
fx.Provide(f),
)
Expand Down
2 changes: 1 addition & 1 deletion cmd/rig/cmd/capsule/jobs/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (c *Cmd) cronJobFromPath(path string) (*capsule.CronJob, error) {
return nil, err
}

var raw interface{}
var raw any
if err := yaml.Unmarshal(bytes, &raw); err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/rig/cmd/capsule/root/status_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ type getInfoStep interface {
GetInfo() *rollout.StepInfo
}

func GetStepInfo(s interface{}) *rollout.StepInfo {
func GetStepInfo(s any) *rollout.StepInfo {
msg, ok := s.(protoreflect.ProtoMessage)
if !ok {
return nil
Expand Down
2 changes: 1 addition & 1 deletion cmd/rig/cmd/capsule/scale/horizontal.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (c *Cmd) autoscale(ctx context.Context, cmd *cobra.Command, _ []string) err
return err
}

var raw interface{}
var raw any
if err := yaml.Unmarshal(bytes, &raw); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ var Module = fx.Module(
fx.Provide(func() common.Prompter { return common.StandardPrompter{} }),
)

type ContextDependency interface{}
type ContextDependency any

type contextParams struct {
fx.In
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/plugin/external_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ type loggerSink struct {
logger logr.Logger
}

func (l *loggerSink) Accept(name string, level hclog.Level, msg string, args ...interface{}) {
func (l *loggerSink) Accept(name string, level hclog.Level, msg string, args ...any) {
logger := l.logger.WithName(name).WithValues(args...)
if level < hclog.Info {
return
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/plugin/heap.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,14 @@ func (s *sliceHeap[E]) Less(i, j int) bool {
return s.less(s.s[i], s.s[j])
}

func (s *sliceHeap[E]) Push(x interface{}) {
func (s *sliceHeap[E]) Push(x any) {
s.s = append(s.s, x.(E))
if s.setIndex != nil {
s.setIndex(s.s[len(s.s)-1], len(s.s)-1)
}
}

func (s *sliceHeap[E]) Pop() interface{} {
func (s *sliceHeap[E]) Pop() any {
e := s.s[len(s.s)-1]
if s.setIndex != nil {
s.setIndex(e, -1)
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/plugin/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func ParseTemplatedConfig[T any](data []byte, req pipeline.CapsuleRequest, steps
}

for k, v := range m {
result := map[string]interface{}{}
result := map[string]any{}
d, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{TagName: "json", Result: &result})
if err != nil {
return empty, err
Expand Down
6 changes: 3 additions & 3 deletions pkg/controller/plugin/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ func (ow *objectWatcher) Watch(options metav1.ListOptions) (watch.Interface, err
return wi, err
}

func (ow *objectWatcher) OnAdd(obj interface{}, _ bool) {
func (ow *objectWatcher) OnAdd(obj any, _ bool) {
if e, ok := obj.(*corev1.Event); ok {
key := cache.NewObjectName(e.InvolvedObject.Namespace, e.InvolvedObject.Name)
item, exists, err := ow.store.GetByKey(key.String())
Expand Down Expand Up @@ -596,11 +596,11 @@ func (ow *objectWatcher) OnAdd(obj interface{}, _ bool) {
}
}

func (ow *objectWatcher) OnUpdate(_, newObj interface{}) {
func (ow *objectWatcher) OnUpdate(_, newObj any) {
ow.OnAdd(newObj, false)
}

func (ow *objectWatcher) OnDelete(obj interface{}) {
func (ow *objectWatcher) OnDelete(obj any) {
if e, ok := obj.(*corev1.Event); ok {
key := cache.NewObjectName(e.InvolvedObject.Namespace, e.InvolvedObject.Name)
item, exists, err := ow.store.GetByKey(key.String())
Expand Down
32 changes: 16 additions & 16 deletions pkg/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ func IsUnauthenticated(err error) bool {
//
// The gRPC framework will generate this error code when cancellation
// is requested.
func CanceledErrorf(format string, a ...interface{}) error {
func CanceledErrorf(format string, a ...any) error {
return NewError(connect.CodeCanceled, fmt.Errorf(format, a...))
}

Expand All @@ -270,7 +270,7 @@ func CanceledErrorf(format string, a ...interface{}) error {
//
// The gRPC framework will generate this error code in the above two
// mentioned cases.
func UnknownErrorf(format string, a ...interface{}) error {
func UnknownErrorf(format string, a ...any) error {
return NewError(connect.CodeUnknown, fmt.Errorf(format, a...))
}

Expand All @@ -280,7 +280,7 @@ func UnknownErrorf(format string, a ...interface{}) error {
// (e.g., a malformed file name).
//
// This error code will not be generated by the gRPC framework.
func InvalidArgumentErrorf(format string, a ...interface{}) error {
func InvalidArgumentErrorf(format string, a ...any) error {
return NewError(connect.CodeInvalidArgument, fmt.Errorf(format, a...))
}

Expand All @@ -292,23 +292,23 @@ func InvalidArgumentErrorf(format string, a ...interface{}) error {
//
// The gRPC framework will generate this error code when the deadline is
// exceeded.
func DeadlineExceededErrorf(format string, a ...interface{}) error {
func DeadlineExceededErrorf(format string, a ...any) error {
return NewError(connect.CodeDeadlineExceeded, fmt.Errorf(format, a...))
}

// NotFoundErrorf creates a new error that means some requested entity (e.g., file or directory) was
// not found.
//
// This error code will not be generated by the gRPC framework.
func NotFoundErrorf(format string, a ...interface{}) error {
func NotFoundErrorf(format string, a ...any) error {
return NewError(connect.CodeNotFound, fmt.Errorf(format, a...))
}

// AlreadyExistsErrorf creates a new error that means an attempt to create an entity failed because one
// already exists.
//
// This error code will not be generated by the gRPC framework.
func AlreadyExistsErrorf(format string, a ...interface{}) error {
func AlreadyExistsErrorf(format string, a ...any) error {
return NewError(connect.CodeAlreadyExists, fmt.Errorf(format, a...))
}

Expand All @@ -321,7 +321,7 @@ func AlreadyExistsErrorf(format string, a ...interface{}) error {
//
// This error code will not be generated by the gRPC core framework,
// but expect authentication middleware to use it.
func PermissionDeniedErrorf(format string, a ...interface{}) error {
func PermissionDeniedErrorf(format string, a ...any) error {
return NewError(connect.CodePermissionDenied, fmt.Errorf(format, a...))
}

Expand All @@ -331,7 +331,7 @@ func PermissionDeniedErrorf(format string, a ...interface{}) error {
// This error code will be generated by the gRPC framework in
// out-of-memory and server overload situations, or when a message is
// larger than the configured maximum size.
func ResourceExhaustedErrorf(format string, a ...interface{}) error {
func ResourceExhaustedErrorf(format string, a ...any) error {
return NewError(connect.CodeResourceExhausted, fmt.Errorf(format, a...))
}

Expand All @@ -357,7 +357,7 @@ func ResourceExhaustedErrorf(format string, a ...interface{}) error {
// read-modify-write on the same resource.
//
// This error code will not be generated by the gRPC framework.
func FailedPreconditionErrorf(format string, a ...interface{}) error {
func FailedPreconditionErrorf(format string, a ...any) error {
return NewError(connect.CodeFailedPrecondition, fmt.Errorf(format, a...))
}

Expand All @@ -369,7 +369,7 @@ func FailedPreconditionErrorf(format string, a ...interface{}) error {
// Aborted, and Unavailable.
//
// This error code will not be generated by the gRPC framework.
func AbortedErrorf(format string, a ...interface{}) error {
func AbortedErrorf(format string, a ...any) error {
return NewError(connect.CodeAborted, fmt.Errorf(format, a...))
}

Expand All @@ -390,7 +390,7 @@ func AbortedErrorf(format string, a ...interface{}) error {
// they are done.
//
// This error code will not be generated by the gRPC framework.
func OutOfRangeErrorf(format string, a ...interface{}) error {
func OutOfRangeErrorf(format string, a ...any) error {
return NewError(connect.CodeOutOfRange, fmt.Errorf(format, a...))
}

Expand All @@ -402,7 +402,7 @@ func OutOfRangeErrorf(format string, a ...interface{}) error {
// is missing on the server. It can also be generated for unknown
// compression algorithms or a disagreement as to whether an RPC should
// be streaming.
func UnimplementedErrorf(format string, a ...interface{}) error {
func UnimplementedErrorf(format string, a ...any) error {
return NewError(connect.CodeUnimplemented, fmt.Errorf(format, a...))
}

Expand All @@ -412,7 +412,7 @@ func UnimplementedErrorf(format string, a ...interface{}) error {
//
// This error code will be generated by the gRPC framework in several
// internal error conditions.
func InternalErrorf(format string, a ...interface{}) error {
func InternalErrorf(format string, a ...any) error {
return NewError(connect.CodeInternal, fmt.Errorf(format, a...))
}

Expand All @@ -426,14 +426,14 @@ func InternalErrorf(format string, a ...interface{}) error {
//
// This error code will be generated by the gRPC framework during
// abrupt shutdown of a server process or network connection.
func UnavailableErrorf(format string, a ...interface{}) error {
func UnavailableErrorf(format string, a ...any) error {
return NewError(connect.CodeUnavailable, fmt.Errorf(format, a...))
}

// DataLossErrorf creates a new error that indicates unrecoverable data loss or corruption.
//
// This error code will not be generated by the gRPC framework.
func DataLossErrorf(format string, a ...interface{}) error {
func DataLossErrorf(format string, a ...any) error {
return NewError(connect.CodeDataLoss, fmt.Errorf(format, a...))
}

Expand All @@ -443,7 +443,7 @@ func DataLossErrorf(format string, a ...interface{}) error {
// The gRPC framework will generate this error code when the
// authentication metadata is invalid or a Credentials callback fails,
// but also expect authentication middleware to generate it.
func UnauthenticatedErrorf(format string, a ...interface{}) error {
func UnauthenticatedErrorf(format string, a ...any) error {
return NewError(connect.CodeUnauthenticated, fmt.Errorf(format, a...))
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/pipeline/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (ok ObjectKey) String() string {
return fmt.Sprintf("%s/%s", ok.GroupVersionKind.String(), ok.ObjectKey.String())
}

func (ok ObjectKey) MarshalLog() interface{} {
func (ok ObjectKey) MarshalLog() any {
return struct {
Group string `json:"group,omitempty"`
Version string `json:"version,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion pkg/roclient/layered_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (r *LayeredReader) List(ctx context.Context, list client.ObjectList, opts .
}
}

bs, err := gojson.Marshal(map[string]interface{}{
bs, err := gojson.Marshal(map[string]any{
"items": objs,
})
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/roclient/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func (r *reader) List(_ context.Context, list client.ObjectList, opts ...client.
}
}

bs, err := gojson.Marshal(map[string]interface{}{
bs, err := gojson.Marshal(map[string]any{
"items": objs,
})
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/uuid/uuid.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (u *UUID) UnmarshalJSON(bs []byte) error {
return nil
}

func (u UUID) MarshalYAML() (interface{}, error) {
func (u UUID) MarshalYAML() (any, error) {
if u == Nil {
return "", nil
}
Expand Down Expand Up @@ -105,7 +105,7 @@ func (u *UUID) Unmarshal(v *yaml.Node) error {
}

func MapstructureDecodeFunc() mapstructure.DecodeHookFuncType {
return func(f reflect.Type, t reflect.Type, data interface{}) (interface{}, error) {
return func(f reflect.Type, t reflect.Type, data any) (any, error) {
if f == reflect.TypeOf("") && t == reflect.TypeOf(Nil) {
s := data.(string)

Expand Down
2 changes: 1 addition & 1 deletion plugins/builtin/object_create/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ object: |
}
require.NoError(t, plugin.Run(context.Background(), req, hclog.Default()))
vpa := &unstructured.Unstructured{
Object: map[string]interface{}{
Object: map[string]any{
"apiVersion": "vpcresources.k8s.aws/v1beta1",
"kind": "SecurityGroupPolicy",
"metadata": map[string]any{
Expand Down

0 comments on commit d4af08f

Please sign in to comment.