Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions cmd/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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())
}
}
3 changes: 1 addition & 2 deletions pkg/builder/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/builder/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 2 additions & 4 deletions pkg/config/generate/builder/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,15 @@ 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
}
if strings.HasPrefix(m.Name, "Read") || strings.HasPrefix(m.Name, "List") {
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
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/config/generate/builder/method.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/output/format/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
Expand Down
16 changes: 8 additions & 8 deletions pkg/output/format/get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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{
Expand All @@ -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"},
Expand All @@ -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"},
Expand All @@ -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"},
Expand All @@ -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"},
Expand Down
4 changes: 2 additions & 2 deletions pkg/structs/find.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Loading