Skip to content

Commit f64d076

Browse files
committed
refactor: remove 'get' prefix from method names to follow Go conventions
This commit refactors method names to follow Go naming conventions by removing the 'get' prefix from exported methods. In Go, getters should not have a 'get' prefix as it's considered redundant. Changes: - Renamed getLAN() to lan() in network.go - Renamed getServerNICID() to serverNICID() in network.go - Updated all call sites in network.go, ipblock.go, and server.go - Updated corresponding test methods in network_test.go This improves code consistency and follows Go best practices for method naming.
1 parent 151a31a commit f64d076

4 files changed

Lines changed: 16 additions & 16 deletions

File tree

internal/service/cloud/ipblock.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ func (s *Service) ReconcileFailoverIPBlockDeletion(ctx context.Context, ms *scop
199199
}
200200

201201
// Check if IPBlock is still being used
202-
lan, err := s.getLAN(ctx, ms)
202+
lan, err := s.lan(ctx, ms)
203203
if err != nil {
204204
return false, err
205205
}

internal/service/cloud/network.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func (s *Service) ReconcileLAN(ctx context.Context, ms *scope.Machine) (requeue
6969
}
7070
defer ms.Locker.Unlock(lockKey)
7171

72-
lan, request, err := scopedFindResource(ctx, ms, s.getLAN, s.getLatestLANCreationRequest)
72+
lan, request, err := scopedFindResource(ctx, ms, s.lan, s.getLatestLANCreationRequest)
7373
if err != nil {
7474
return false, err
7575
}
@@ -109,7 +109,7 @@ func (s *Service) ReconcileLANDeletion(ctx context.Context, ms *scope.Machine) (
109109
defer ms.Locker.Unlock(lockKey)
110110

111111
// Try to retrieve the cluster LAN or even check if it's currently still being created.
112-
lan, request, err := scopedFindResource(ctx, ms, s.getLAN, s.getLatestLANCreationRequest)
112+
lan, request, err := scopedFindResource(ctx, ms, s.lan, s.getLatestLANCreationRequest)
113113
if err != nil {
114114
return false, err
115115
}
@@ -146,8 +146,8 @@ func (s *Service) ReconcileLANDeletion(ctx context.Context, ms *scope.Machine) (
146146
return err == nil, err
147147
}
148148

149-
// getLAN tries to retrieve the cluster-related LAN in the data center.
150-
func (s *Service) getLAN(ctx context.Context, ms *scope.Machine) (*sdk.Lan, error) {
149+
// lan tries to retrieve the cluster-related LAN in the data center.
150+
func (s *Service) lan(ctx context.Context, ms *scope.Machine) (*sdk.Lan, error) {
151151
depth := int32(2) // for listing the LANs with their number of NICs
152152

153153
// check if the LAN exists
@@ -410,7 +410,7 @@ func (s *Service) swapNICInFailoverGroup(
410410
matchLabels client.MatchingLabels,
411411
) (requeue bool, err error) {
412412
log := s.logger.WithName("swapNICInFailoverGroup")
413-
nicID, err := s.getServerNICID(ctx, ms)
413+
nicID, err := s.serverNICID(ctx, ms)
414414
if err != nil {
415415
return false, err
416416
}
@@ -470,16 +470,16 @@ func (s *Service) swapNICInFailoverGroup(
470470
}
471471

472472
func (s *Service) ensureFailoverDeletion(ctx context.Context, ms *scope.Machine) (requeue bool, err error) {
473-
nicID, err := s.getServerNICID(ctx, ms)
473+
nicID, err := s.serverNICID(ctx, ms)
474474
if err != nil || nicID == "" {
475475
return false, err
476476
}
477477

478478
return s.removeNICFromFailoverGroup(ctx, ms, nicID)
479479
}
480480

481-
func (s *Service) getServerNICID(ctx context.Context, ms *scope.Machine) (string, error) {
482-
log := s.logger.WithName("getServerNICID")
481+
func (s *Service) serverNICID(ctx context.Context, ms *scope.Machine) (string, error) {
482+
log := s.logger.WithName("serverNICID")
483483
server, err := s.getServer(ctx, ms)
484484
if err != nil {
485485
if isNotFound(err) {
@@ -611,7 +611,7 @@ func (s *Service) retrieveLANFailoverConfig(
611611
) (requeue bool, err error) {
612612
log := s.logger.WithName("retrieveLANFailoverConfig")
613613

614-
gotLAN, err := s.getLAN(ctx, ms)
614+
gotLAN, err := s.lan(ctx, ms)
615615
if err != nil {
616616
return true, err
617617
}

internal/service/cloud/network_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,15 @@ func (s *lanSuite) TestNetworkDeleteLANSuccessful() {
8686
func (s *lanSuite) TestNetworkGetLANSuccessful() {
8787
lan := s.exampleLAN()
8888
s.mockListLANsCall().Return(&sdk.Lans{Items: &[]sdk.Lan{lan}}, nil).Once()
89-
foundLAN, err := s.service.getLAN(s.ctx, s.machineScope)
89+
foundLAN, err := s.service.lan(s.ctx, s.machineScope)
9090
s.NoError(err)
9191
s.NotNil(foundLAN)
9292
s.Equal(lan, *foundLAN)
9393
}
9494

9595
func (s *lanSuite) TestNetworkGetLANNotFound() {
9696
s.mockListLANsCall().Return(&sdk.Lans{Items: &[]sdk.Lan{}}, nil).Once()
97-
lan, err := s.service.getLAN(s.ctx, s.machineScope)
97+
lan, err := s.service.lan(s.ctx, s.machineScope)
9898
s.NoError(err)
9999
s.Nil(lan)
100100
}
@@ -104,7 +104,7 @@ func (s *lanSuite) TestNetworkGetLAN_ExistingLAN() {
104104
s.mockListLANsCall().Return(&sdk.Lans{Items: &[]sdk.Lan{lan}}, nil).Once()
105105

106106
s.machineScope.IonosMachine.Spec.NetworkID = ptr.To("42")
107-
foundLAN, err := s.service.getLAN(s.ctx, s.machineScope)
107+
foundLAN, err := s.service.lan(s.ctx, s.machineScope)
108108
s.NoError(err)
109109
s.NotNil(foundLAN)
110110
s.Equal(lan, *foundLAN)
@@ -115,14 +115,14 @@ func (s *lanSuite) TestNetworkGetLAN_LANIDNotFound() {
115115
s.mockListLANsCall().Return(&sdk.Lans{Items: &[]sdk.Lan{lan}}, nil).Once()
116116

117117
s.machineScope.IonosMachine.Spec.NetworkID = ptr.To("2")
118-
foundLAN, err := s.service.getLAN(s.ctx, s.machineScope)
118+
foundLAN, err := s.service.lan(s.ctx, s.machineScope)
119119
s.EqualError(err, "LAN with ID 2 not found")
120120
s.Nil(foundLAN)
121121
}
122122

123123
func (s *lanSuite) TestNetworkGetLANErrorNotUnique() {
124124
s.mockListLANsCall().Return(&sdk.Lans{Items: &[]sdk.Lan{s.exampleLAN(), s.exampleLAN()}}, nil).Once()
125-
lan, err := s.service.getLAN(s.ctx, s.machineScope)
125+
lan, err := s.service.lan(s.ctx, s.machineScope)
126126
s.Error(err)
127127
s.Nil(lan)
128128
}

internal/service/cloud/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ func (s *Service) createServer(ctx context.Context, secret *corev1.Secret, ms *s
318318
return errors.New("unable to obtain bootstrap data from secret")
319319
}
320320

321-
lan, err := s.getLAN(ctx, ms)
321+
lan, err := s.lan(ctx, ms)
322322
if err != nil {
323323
return err
324324
}

0 commit comments

Comments
 (0)