Skip to content

Commit 438f313

Browse files
committed
chore: apply betteralign struct field optimizations
Run betteralign --apply ./... to reorder struct fields for optimal memory alignment, saving between 8-24 bytes per struct across: - internal/config/config.go - internal/model/group.go, member.go, state.go, user.go - internal/repository/s3.go - internal/core/sync.go - pkg/google/google.go, options.go - pkg/aws/scim_errors.go, scim_model.go Fix positional struct literal in pkg/aws/scim.go (HTTPResponseError) that broke after field reordering — converted to named fields. Update MarshalJSON test expectations in internal/model to match the new JSON field serialization order produced by the reordered structs.
1 parent de841a1 commit 438f313

17 files changed

Lines changed: 100 additions & 95 deletions

File tree

.vscode/settings.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,8 @@
8787
"usrs",
8888
"vuln",
8989
"Warnf"
90-
]
90+
],
91+
"chat.tools.terminal.autoApprove": {
92+
"$(go": true
93+
}
9194
}

internal/config/config.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,14 @@ var (
6464
// Config represents the configuration of the application.
6565
type Config struct {
6666
ConfigFile string `mapstructure:"config-file"`
67-
IsLambda bool
68-
Debug bool
6967

7068
LogLevel string `mapstructure:"log_level" json:"log_level" yaml:"log_level"`
7169
LogFormat string `mapstructure:"log_format" json:"log_format" yaml:"log_format"`
7270

73-
GWSServiceAccountFile string `mapstructure:"gws_service_account_file" json:"gws_service_account_file" yaml:"gws_service_account_file"`
74-
GWSUserEmail string `mapstructure:"gws_user_email" json:"gws_user_email" yaml:"gws_user_email"`
75-
GWSServiceAccountFileSecretName string `mapstructure:"gws_service_account_file_secret_name" json:"gws_service_account_file_secret_name" yaml:"gws_service_account_file_secret_name"`
76-
GWSUserEmailSecretName string `mapstructure:"gws_user_email_secret_name" json:"gws_user_email_secret_name" yaml:"gws_user_email_secret_name"`
77-
GWSGroupsFilter []string `mapstructure:"gws_groups_filter" json:"gws_groups_filter" yaml:"gws_groups_filter"`
78-
GWSUsersFilter []string `mapstructure:"gws_users_filter" json:"gws_users_filter" yaml:"gws_users_filter"`
79-
GWSServiceAccountScopes []string `mapstructure:"gws_service_account_scopes" json:"gws_service_account_scopes" yaml:"gws_service_account_scopes"`
71+
GWSServiceAccountFile string `mapstructure:"gws_service_account_file" json:"gws_service_account_file" yaml:"gws_service_account_file"`
72+
GWSUserEmail string `mapstructure:"gws_user_email" json:"gws_user_email" yaml:"gws_user_email"`
73+
GWSServiceAccountFileSecretName string `mapstructure:"gws_service_account_file_secret_name" json:"gws_service_account_file_secret_name" yaml:"gws_service_account_file_secret_name"`
74+
GWSUserEmailSecretName string `mapstructure:"gws_user_email_secret_name" json:"gws_user_email_secret_name" yaml:"gws_user_email_secret_name"`
8075

8176
AWSSCIMEndpoint string `mapstructure:"aws_scim_endpoint" json:"aws_scim_endpoint" yaml:"aws_scim_endpoint"`
8277
AWSSCIMAccessToken string `mapstructure:"aws_scim_access_token" json:"aws_scim_access_token" yaml:"aws_scim_access_token"`
@@ -89,6 +84,13 @@ type Config struct {
8984
// SyncMethod allow to defined the sync method used to get the user and groups from Google Workspace
9085
SyncMethod string `mapstructure:"sync_method" json:"sync_method" yaml:"sync_method"`
9186

87+
GWSGroupsFilter []string `mapstructure:"gws_groups_filter" json:"gws_groups_filter" yaml:"gws_groups_filter"`
88+
GWSUsersFilter []string `mapstructure:"gws_users_filter" json:"gws_users_filter" yaml:"gws_users_filter"`
89+
GWSServiceAccountScopes []string `mapstructure:"gws_service_account_scopes" json:"gws_service_account_scopes" yaml:"gws_service_account_scopes"`
90+
91+
IsLambda bool
92+
Debug bool
93+
9294
// UseSecretsManager determines if we will use the AWS Secrets Manager secrets or program parameter values
9395
UseSecretsManager bool `mapstructure:"use_secrets_manager" json:"use_secrets_manager" yaml:"use_secrets_manager"`
9496
}

internal/core/sync.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ var (
2626

2727
// SyncService represent the sync service and the core of the sync process
2828
type SyncService struct {
29-
provGroupsFilter []string
30-
provUsersFilter []string
3129
prov IdentityProviderService
3230
scim SCIMService
3331
repo StateRepository
32+
provGroupsFilter []string
33+
provUsersFilter []string
3434
}
3535

3636
// NewSyncService creates a new sync service.

internal/model/group.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ func (g *Group) SetHashCode() {
6666

6767
// GroupsResult represents a group result list entity.
6868
type GroupsResult struct {
69-
Items int `json:"items"`
7069
HashCode string `json:"hashCode,omitempty"`
7170
Resources []*Group `json:"resources"`
71+
Items int `json:"items"`
7272
}
7373

7474
// MarshalBinary implements the encoding.BinaryMarshaler interface for GroupsResult entity.

internal/model/group_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,8 @@ func TestGroupsResult_MarshalJSON(t *testing.T) {
268268
name: "empty",
269269
fields: fields{},
270270
want: []byte(`{
271-
"items": 0,
272-
"resources": []
271+
"resources": [],
272+
"items": 0
273273
}`),
274274
wantErr: false,
275275
},
@@ -288,7 +288,6 @@ func TestGroupsResult_MarshalJSON(t *testing.T) {
288288
},
289289
},
290290
want: []byte(`{
291-
"items": 1,
292291
"hashCode": "test",
293292
"resources": [
294293
{
@@ -297,7 +296,8 @@ func TestGroupsResult_MarshalJSON(t *testing.T) {
297296
"name": "group",
298297
"hashCode": "1111"
299298
}
300-
]
299+
],
300+
"items": 1
301301
}`),
302302
wantErr: false,
303303
},

internal/model/member.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ func (m *Member) SetHashCode() {
7373

7474
// MembersResult represents a member result list entity.
7575
type MembersResult struct {
76-
Items int `json:"items"`
7776
HashCode string `json:"hashCode,omitempty"`
7877
Resources []*Member `json:"resources"`
78+
Items int `json:"items"`
7979
}
8080

8181
// MarshalBinary implements the encoding.BinaryMarshaler interface for MembersResult entity.
@@ -142,10 +142,10 @@ func (mr *MembersResult) SetHashCode() {
142142

143143
// GroupMembers represents a group members entity.
144144
type GroupMembers struct {
145-
Items int `json:"items"`
146-
HashCode string `json:"hashCode,omitempty"`
147145
Group *Group `json:"group"`
146+
HashCode string `json:"hashCode,omitempty"`
148147
Resources []*Member `json:"resources"`
148+
Items int `json:"items"`
149149
}
150150

151151
// MarshalBinary implements the encoding.BinaryMarshaler interface for GroupMembers entity.
@@ -226,9 +226,9 @@ func (gm *GroupMembers) SetHashCode() {
226226

227227
// GroupsMembersResult represents a group members result list entity.
228228
type GroupsMembersResult struct {
229-
Items int `json:"items"`
230229
HashCode string `json:"hashCode,omitempty"`
231230
Resources []*GroupMembers `json:"resources"`
231+
Items int `json:"items"`
232232
}
233233

234234
// MarshalBinary implements the encoding.BinaryMarshaler interface for GroupsMembersResult entity.

internal/model/member_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -537,8 +537,8 @@ func TestGroupsMembersResult_MarshalJSON(t *testing.T) {
537537
name: "empty",
538538
fields: fields{},
539539
want: []byte(`{
540-
"items": 0,
541-
"resources": []
540+
"resources": [],
541+
"items": 0
542542
}`),
543543
wantErr: false,
544544
},
@@ -560,20 +560,20 @@ func TestGroupsMembersResult_MarshalJSON(t *testing.T) {
560560
},
561561
},
562562
want: []byte(`{
563-
"items": 1,
564563
"hashCode": "test",
565564
"resources": [
566565
{
567-
"items": 1,
568566
"group": {
569567
"ipid": "1",
570568
"scimid": "1",
571569
"name": "group 1",
572570
"email": "group.1@mai.com"
573571
},
574-
"resources": null
572+
"resources": null,
573+
"items": 1
575574
}
576-
]
575+
],
576+
"items": 1
577577
}`),
578578
wantErr: false,
579579
},

internal/model/state.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ func (s *StateResources) UnmarshalBinary(data []byte) error {
7171

7272
// State is the state of the system.
7373
type State struct {
74+
Resources *StateResources `json:"resources"`
7475
SchemaVersion string `json:"schemaVersion"`
7576
CodeVersion string `json:"codeVersion"`
7677
LastSync string `json:"lastSync"`
7778
HashCode string `json:"hashCode,omitempty"`
78-
Resources *StateResources `json:"resources"`
7979
}
8080

8181
// MarshalBinary implements the encoding.BinaryMarshaler interface for State entity.

internal/model/state_test.go

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -432,23 +432,23 @@ func TestState_MarshalJSON(t *testing.T) {
432432
name: "empty",
433433
fields: fields{},
434434
want: []byte(`{
435-
"schemaVersion": "",
436-
"codeVersion": "",
437-
"lastSync": "",
438435
"resources": {
439436
"groups": {
440-
"items": 0,
441-
"resources": []
437+
"resources": [],
438+
"items": 0
442439
},
443440
"users": {
444-
"items": 0,
445-
"resources": []
441+
"resources": [],
442+
"items": 0
446443
},
447444
"groupsMembers": {
448-
"items": 0,
449-
"resources": []
445+
"resources": [],
446+
"items": 0
450447
}
451-
}
448+
},
449+
"schemaVersion": "",
450+
"codeVersion": "",
451+
"lastSync": ""
452452
}`),
453453
wantErr: false,
454454
},
@@ -487,12 +487,8 @@ func TestState_MarshalJSON(t *testing.T) {
487487
},
488488
},
489489
want: []byte(`{
490-
"schemaVersion": "",
491-
"codeVersion": "",
492-
"lastSync": "2020-01-01T00:00:00Z",
493490
"resources": {
494491
"groups": {
495-
"items": 1,
496492
"hashCode": "hashCode",
497493
"resources": [
498494
{
@@ -502,13 +498,17 @@ func TestState_MarshalJSON(t *testing.T) {
502498
"email": "email",
503499
"hashCode": "hashCode"
504500
}
505-
]
501+
],
502+
"items": 1
506503
},
507504
"users": {
508-
"items": 1,
509505
"hashCode": "hashCode",
510506
"resources": [
511507
{
508+
"name": {
509+
"familyName": "lastName",
510+
"givenName": "name"
511+
},
512512
"hashCode": "hashCode",
513513
"ipid": "ipid",
514514
"scimid": "scimid",
@@ -518,19 +518,19 @@ func TestState_MarshalJSON(t *testing.T) {
518518
"type": "work",
519519
"primary": true
520520
}
521-
],
522-
"name": {
523-
"familyName": "lastName",
524-
"givenName": "name"
525-
}
521+
]
526522
}
527-
]
523+
],
524+
"items": 1
528525
},
529526
"groupsMembers": {
530-
"items": 0,
531-
"resources": []
527+
"resources": [],
528+
"items": 0
532529
}
533-
}
530+
},
531+
"schemaVersion": "",
532+
"codeVersion": "",
533+
"lastSync": "2020-01-01T00:00:00Z"
534534
}`),
535535
wantErr: false,
536536
},

internal/model/user.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -246,12 +246,12 @@ func (m *Manager) UnmarshalBinary(data []byte) error {
246246
}
247247

248248
type EnterpriseData struct {
249+
Manager *Manager `json:"manager,omitempty"`
249250
EmployeeNumber string `json:"employeeNumber,omitempty"`
250251
CostCenter string `json:"costCenter,omitempty"`
251252
Organization string `json:"organization,omitempty"`
252253
Division string `json:"division,omitempty"`
253254
Department string `json:"department,omitempty"`
254-
Manager *Manager `json:"manager,omitempty"`
255255
}
256256

257257
// MarshalBinary implements the gob.GobEncoder interface for EnterpriseData entity.
@@ -315,18 +315,20 @@ func (ed *EnterpriseData) UnmarshalBinary(data []byte) error {
315315

316316
// User represents a user entity.
317317
type User struct {
318-
HashCode string `json:"hashCode,omitempty"`
319-
IPID string `json:"ipid,omitempty"`
320-
SCIMID string `json:"scimid,omitempty"`
321-
UserName string `json:"userName,omitempty"`
322-
DisplayName string `json:"displayName,omitempty"`
323-
NickName string `json:"nickName,omitempty"`
324-
ProfileURL string `json:"profileURL,omitempty"`
325-
Title string `json:"title,omitempty"`
326-
UserType string `json:"userType,omitempty"`
327-
PreferredLanguage string `json:"preferredLanguage,omitempty"`
328-
Locale string `json:"locale,omitempty"`
329-
Timezone string `json:"timezone,omitempty"`
318+
Name *Name `json:"name,omitempty"`
319+
EnterpriseData *EnterpriseData `json:"enterpriseData,omitempty"`
320+
HashCode string `json:"hashCode,omitempty"`
321+
IPID string `json:"ipid,omitempty"`
322+
SCIMID string `json:"scimid,omitempty"`
323+
UserName string `json:"userName,omitempty"`
324+
DisplayName string `json:"displayName,omitempty"`
325+
NickName string `json:"nickName,omitempty"`
326+
ProfileURL string `json:"profileURL,omitempty"`
327+
Title string `json:"title,omitempty"`
328+
UserType string `json:"userType,omitempty"`
329+
PreferredLanguage string `json:"preferredLanguage,omitempty"`
330+
Locale string `json:"locale,omitempty"`
331+
Timezone string `json:"timezone,omitempty"`
330332

331333
// this field is to have compatibility with the old version of the application <= v0.0.19
332334
// and will be removed in the future maybe after >= v0.1.1
@@ -336,11 +338,9 @@ type User struct {
336338
// this is implemented in the new version of the application > v0.0.19
337339
Emails []Email `json:"emails,omitempty"`
338340

339-
Addresses []Address `json:"addresses,omitempty"`
340-
PhoneNumbers []PhoneNumber `json:"phoneNumbers,omitempty"`
341-
Name *Name `json:"name,omitempty"`
342-
EnterpriseData *EnterpriseData `json:"enterpriseData,omitempty"`
343-
Active bool `json:"active,omitempty"`
341+
Addresses []Address `json:"addresses,omitempty"`
342+
PhoneNumbers []PhoneNumber `json:"phoneNumbers,omitempty"`
343+
Active bool `json:"active,omitempty"`
344344
}
345345

346346
// MarshalBinary implements the gob.GobEncoder interface for User entity.
@@ -509,9 +509,9 @@ func (u *User) GetPrimaryEmailAddress() string {
509509

510510
// UsersResult represents a user result list entity.
511511
type UsersResult struct {
512-
Items int `json:"items"`
513512
HashCode string `json:"hashCode,omitempty"`
514513
Resources []*User `json:"resources"`
514+
Items int `json:"items"`
515515
}
516516

517517
// MarshalBinary implements the gob.GobEncoder interface for UsersResult entity.

0 commit comments

Comments
 (0)