Skip to content

Commit

Permalink
avoid nil reference occurs occasionally
Browse files Browse the repository at this point in the history
  • Loading branch information
mpon committed Jul 14, 2020
1 parent 181e28d commit e68332c
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions internal/pkg/awsapi/ecs_container_instance_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package awsapi
import (
"strings"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/ec2"
"github.com/aws/aws-sdk-go-v2/service/ecs"
"github.com/mpon/ecswalk/internal/pkg/sliceutil"
Expand Down Expand Up @@ -51,6 +52,9 @@ type EcsContainerInstanceInfoList []*EcsContainerInstanceInfo
func NewEcsContainerInstanceInfoList(containerInstances []ecs.ContainerInstance) EcsContainerInstanceInfoList {
var list EcsContainerInstanceInfoList
for _, c := range containerInstances {
if c.VersionInfo == nil {
c.VersionInfo = &ecs.VersionInfo{}
}
list = append(list, &EcsContainerInstanceInfo{
ContainerInstance: c,
})
Expand All @@ -72,6 +76,9 @@ func (cList EcsContainerInstanceInfoList) SetEc2Instances(ec2Instances []ec2.Ins
for _, c := range cList {
for _, i := range ec2Instances {
if *i.InstanceId == *c.ContainerInstance.Ec2InstanceId {
if i.PrivateIpAddress == nil {
i.PrivateIpAddress = aws.String("")
}
c.Ec2Instance = i
}
}
Expand Down

0 comments on commit e68332c

Please sign in to comment.