diff --git a/cmd/storage.go b/cmd/storage.go index 48ccd13f..8a3812ae 100644 --- a/cmd/storage.go +++ b/cmd/storage.go @@ -12,7 +12,6 @@ import ( "github.com/aws/aws-sdk-go-v2/service/s3" "github.com/gabriel-vasile/mimetype" - "github.com/outscale/goutils/sdk/ptr" "github.com/outscale/octl/pkg/builder" "github.com/outscale/octl/pkg/config" "github.com/outscale/octl/pkg/debug" @@ -85,6 +84,6 @@ func guessContentType(arg reflect.Value) { } mime := mimetype.Detect(body) messages.Info("detected mime-type: %s", mime.String()) - po.ContentType = ptr.To(mime.String()) + po.ContentType = new(mime.String()) } } diff --git a/pkg/builder/build.go b/pkg/builder/build.go index e059d7d5..06348862 100644 --- a/pkg/builder/build.go +++ b/pkg/builder/build.go @@ -136,8 +136,7 @@ func (b *Builder[T]) BuildAPI( } rootCmd.AddCommand(apiCmd) ct := reflect.TypeFor[*T]() - for i := range ct.NumMethod() { - m := ct.Method(i) + for m := range ct.Methods() { if !methodFilter(m) { continue } diff --git a/pkg/builder/flags/flags.go b/pkg/builder/flags/flags.go index 97c3e753..3b1728cf 100644 --- a/pkg/builder/flags/flags.go +++ b/pkg/builder/flags/flags.go @@ -68,8 +68,7 @@ func (b *Builder) Build(fs *FlagSet, arg reflect.Type, prefix string, allowRequi arg = arg.Elem() } typeName := arg.Name() - for i := range arg.NumField() { - f := arg.Field(i) + for f := range arg.Fields() { ot := f.Type t := ot diff --git a/pkg/config/generate/builder/client.go b/pkg/config/generate/builder/client.go index c3c5b907..631427bf 100644 --- a/pkg/config/generate/builder/client.go +++ b/pkg/config/generate/builder/client.go @@ -21,8 +21,7 @@ func NewClientBuilder(cfg Config) *ClientBuilder { func (b *ClientBuilder) BuildFor(build *config.Config, client any) { ct := reflect.TypeOf(client) - for i := range ct.NumMethod() { - m := ct.Method(i) + for m := range ct.Methods() { if strings.HasSuffix(m.Name, "Raw") || strings.HasSuffix(m.Name, "WithBody") || m.Type.NumOut() != 2 { continue } @@ -30,8 +29,7 @@ func (b *ClientBuilder) BuildFor(build *config.Config, client any) { b.BuildMethod(build, m) } } - for i := range ct.NumMethod() { - m := ct.Method(i) + for m := range ct.Methods() { if strings.HasSuffix(m.Name, "Raw") || strings.HasSuffix(m.Name, "WithBody") || m.Type.NumOut() != 2 { continue } diff --git a/pkg/config/generate/builder/method.go b/pkg/config/generate/builder/method.go index 619a1d25..0ecfb3bb 100644 --- a/pkg/config/generate/builder/method.go +++ b/pkg/config/generate/builder/method.go @@ -101,8 +101,7 @@ func (b *MethodBuilder) buildCall() error { respContent, found = resp.FieldByName(b.call.Content) respContentType = respContent.Type } else { - for i := range resp.NumField() { - field := resp.Field(i) + for field := range resp.Fields() { if field.Anonymous || strings.HasSuffix(field.Name, "Context") || strings.HasSuffix(field.Name, "Metadata") { continue } diff --git a/pkg/output/format/get.go b/pkg/output/format/get.go index 2430ee5e..76a58c2c 100644 --- a/pkg/output/format/get.go +++ b/pkg/output/format/get.go @@ -93,7 +93,7 @@ func deref(val any) any { switch { case val == nil || rval.IsZero(): return "" - case tval.Kind() == reflect.Ptr || tval.Kind() == reflect.Interface: + case tval.Kind() == reflect.Pointer || tval.Kind() == reflect.Interface: return deref(rval.Elem().Interface()) case tval.Kind() == reflect.Slice && rval.Len() == 0: return "" diff --git a/pkg/output/format/get_test.go b/pkg/output/format/get_test.go index f843ee76..9a0b5798 100644 --- a/pkg/output/format/get_test.go +++ b/pkg/output/format/get_test.go @@ -19,7 +19,7 @@ func TestGetRow(t *testing.T) { t.Run("Working with non exploded content", func(t *testing.T) { vm := &osc.Vm{ VmId: "i-foo", - BsuOptimized: ptr.To(true), + BsuOptimized: new(true), Nics: []osc.NicLight{{ MacAddress: "01:02:03:04", LinkPublicIp: &osc.LinkPublicIpLightForVm{ @@ -44,10 +44,10 @@ func TestGetRow(t *testing.T) { }) t.Run("Working with exploded content", func(t *testing.T) { vm := &osc.QuotaTypes{ - QuotaType: ptr.To("global"), + QuotaType: new("global"), Quotas: &[]osc.Quota{ - {Name: ptr.To("foo"), UsedValue: ptr.To(10)}, - {Name: ptr.To("bar"), UsedValue: ptr.To(20)}, + {Name: new("foo"), UsedValue: new(10)}, + {Name: new("bar"), UsedValue: new(20)}, }, } rows, err := format.GetRows(vm, config.Columns{ @@ -62,7 +62,7 @@ func TestGetRow(t *testing.T) { }) t.Run("Displaying rounded float64s", func(t *testing.T) { types := &osc.UnitPriceEntry{ - UnitPrice: ptr.To(1.), + UnitPrice: new(1.), } rows, err := format.GetRows(types, config.Columns{ {Content: ".UnitPrice"}, @@ -73,7 +73,7 @@ func TestGetRow(t *testing.T) { }) t.Run("Displaying rounded float32", func(t *testing.T) { types := &osc.UnitPriceEntry{ - UnitPrice: ptr.To(1.2345), + UnitPrice: new(1.2345), } rows, err := format.GetRows(types, config.Columns{ {Content: ".UnitPrice"}, @@ -84,7 +84,7 @@ func TestGetRow(t *testing.T) { }) t.Run("Displaying rounded float64s", func(t *testing.T) { types := &osc.VmType{ - Eth: ptr.To(1), MemorySize: ptr.To[float32](1.), + Eth: new(1), MemorySize: ptr.To[float32](1.), } rows, err := format.GetRows(types, config.Columns{ {Content: ".Eth"}, @@ -96,7 +96,7 @@ func TestGetRow(t *testing.T) { }) t.Run("Displaying rounded float32", func(t *testing.T) { types := &osc.VmType{ - Eth: ptr.To(1), MemorySize: ptr.To[float32](1.2345), + Eth: new(1), MemorySize: ptr.To[float32](1.2345), } rows, err := format.GetRows(types, config.Columns{ {Content: ".Eth"}, diff --git a/pkg/structs/find.go b/pkg/structs/find.go index df309e5d..fa5cfd1a 100644 --- a/pkg/structs/find.go +++ b/pkg/structs/find.go @@ -14,8 +14,8 @@ func FindFieldByType[T any](v reflect.Value) (reflect.Value, bool) { } switch v.Kind() { case reflect.Struct: - for i := range v.NumField() { - res, found := FindFieldByType[T](v.Field(i)) + for _, field := range v.Fields() { + res, found := FindFieldByType[T](field) if found { return res, true }