Skip to content

Commit 7cb8b61

Browse files
committed
add n use new util func
1 parent 4ddfc55 commit 7cb8b61

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

internal/cmd/public-ip/ranges/list/list.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
1616
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
1717
"github.com/stackitcloud/stackit-cli/internal/pkg/services/iaas/client"
18+
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
1819
"github.com/stackitcloud/stackit-sdk-go/services/iaas"
1920
)
2021

@@ -66,7 +67,7 @@ func NewCmd(params *params.CmdParams) *cobra.Command {
6667
if err != nil {
6768
return fmt.Errorf("list public IP ranges: %w", err)
6869
}
69-
publicIpRanges := *resp.Items
70+
publicIpRanges := utils.GetSliceFromPointer(resp.Items)
7071

7172
// Truncate output
7273
if model.Limit != nil && len(publicIpRanges) > int(*model.Limit) {

internal/pkg/utils/utils.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,3 +250,11 @@ func ConvertToBase64PatchedServers(servers []iaas.Server) []Base64PatchedServer
250250

251251
return result
252252
}
253+
254+
// GetSliceFromPointer returns the value of a pointer to a slice of type T. If the pointer is nil, it returns an empty slice.
255+
func GetSliceFromPointer[T any](s *[]T) []T {
256+
if s == nil {
257+
return []T{}
258+
}
259+
return *s
260+
}

0 commit comments

Comments
 (0)