Skip to content

Commit 62a8dfc

Browse files
committed
refactor initialization of structures in internal/allocator/allocator.go
1 parent d4987d9 commit 62a8dfc

File tree

2 files changed

+27
-22
lines changed

2 files changed

+27
-22
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
* Added explicit initialization of fields of structures in `internal/allocator/allocator.go`, when golangci-lint exhaustruct enabled
12
* Added explicit initialization of all fields of the `endpoint` structure in `internal/endpoint/endpoint.go`, when golangci-lint exhaustruct enabled
23

34
* Fixed topic writer infinite reconnections in some cases

internal/allocator/allocator.go

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55

66
"github.com/ydb-platform/ydb-go-genproto/protos/Ydb"
77
"github.com/ydb-platform/ydb-go-genproto/protos/Ydb_Table"
8+
"google.golang.org/protobuf/types/known/structpb"
89
)
910

1011
type (
@@ -116,7 +117,7 @@ func (a *boolAllocator) Bool() (v *Ydb.Value_BoolValue) {
116117

117118
func (a *boolAllocator) free() {
118119
for _, v := range a.allocations {
119-
*v = Ydb.Value_BoolValue{}
120+
*v = Ydb.Value_BoolValue{BoolValue: false}
120121
boolPool.Put(v)
121122
}
122123
a.allocations = a.allocations[:0]
@@ -135,7 +136,7 @@ func (a *bytesAllocator) Bytes() (v *Ydb.Value_BytesValue) {
135136

136137
func (a *bytesAllocator) free() {
137138
for _, v := range a.allocations {
138-
*v = Ydb.Value_BytesValue{}
139+
*v = Ydb.Value_BytesValue{BytesValue: []byte{}}
139140
bytesPool.Put(v)
140141
}
141142
a.allocations = a.allocations[:0]
@@ -192,7 +193,7 @@ func (a *doubleAllocator) Double() (v *Ydb.Value_DoubleValue) {
192193

193194
func (a *doubleAllocator) free() {
194195
for _, v := range a.allocations {
195-
*v = Ydb.Value_DoubleValue{}
196+
*v = Ydb.Value_DoubleValue{DoubleValue: 0}
196197
doublePool.Put(v)
197198
}
198199
a.allocations = a.allocations[:0]
@@ -211,7 +212,7 @@ func (a *floatAllocator) Float() (v *Ydb.Value_FloatValue) {
211212

212213
func (a *floatAllocator) free() {
213214
for _, v := range a.allocations {
214-
*v = Ydb.Value_FloatValue{}
215+
*v = Ydb.Value_FloatValue{FloatValue: 0}
215216
floatPool.Put(v)
216217
}
217218
a.allocations = a.allocations[:0]
@@ -230,7 +231,7 @@ func (a *int32Allocator) Int32() (v *Ydb.Value_Int32Value) {
230231

231232
func (a *int32Allocator) free() {
232233
for _, v := range a.allocations {
233-
*v = Ydb.Value_Int32Value{}
234+
*v = Ydb.Value_Int32Value{Int32Value: 0}
234235
int32Pool.Put(v)
235236
}
236237
a.allocations = a.allocations[:0]
@@ -249,7 +250,7 @@ func (a *int64Allocator) Int64() (v *Ydb.Value_Int64Value) {
249250

250251
func (a *int64Allocator) free() {
251252
for _, v := range a.allocations {
252-
*v = Ydb.Value_Int64Value{}
253+
*v = Ydb.Value_Int64Value{Int64Value: 0}
253254
int64Pool.Put(v)
254255
}
255256
a.allocations = a.allocations[:0]
@@ -287,7 +288,7 @@ func (a *low128Allocator) Low128() (v *Ydb.Value_Low_128) {
287288

288289
func (a *low128Allocator) free() {
289290
for _, v := range a.allocations {
290-
*v = Ydb.Value_Low_128{}
291+
*v = Ydb.Value_Low_128{Low_128: 0}
291292
low128Pool.Put(v)
292293
}
293294
a.allocations = a.allocations[:0]
@@ -306,7 +307,7 @@ func (a *nestedAllocator) Nested() (v *Ydb.Value_NestedValue) {
306307

307308
func (a *nestedAllocator) free() {
308309
for _, v := range a.allocations {
309-
*v = Ydb.Value_NestedValue{}
310+
*v = Ydb.Value_NestedValue{NestedValue: new(Ydb.Value)}
310311
nestedPool.Put(v)
311312
}
312313
a.allocations = a.allocations[:0]
@@ -325,7 +326,7 @@ func (a *nullFlagAllocator) NullFlag() (v *Ydb.Value_NullFlagValue) {
325326

326327
func (a *nullFlagAllocator) free() {
327328
for _, v := range a.allocations {
328-
*v = Ydb.Value_NullFlagValue{}
329+
*v = Ydb.Value_NullFlagValue{NullFlagValue: structpb.NullValue_NULL_VALUE}
329330
nullFlagPool.Put(v)
330331
}
331332
a.allocations = a.allocations[:0]
@@ -363,7 +364,10 @@ func (a *pairAllocator) Pair() (v *Ydb.ValuePair) {
363364

364365
func (a *pairAllocator) free() {
365366
for _, v := range a.allocations {
366-
*v = Ydb.ValuePair{}
367+
*v = Ydb.ValuePair{
368+
Key: new(Ydb.Value),
369+
Payload: new(Ydb.Value),
370+
}
367371
pairPool.Put(v)
368372
}
369373
a.allocations = a.allocations[:0]
@@ -428,7 +432,7 @@ func (a *textAllocator) Text() (v *Ydb.Value_TextValue) {
428432

429433
func (a *textAllocator) free() {
430434
for _, v := range a.allocations {
431-
*v = Ydb.Value_TextValue{}
435+
*v = Ydb.Value_TextValue{TextValue: ""}
432436
textPool.Put(v)
433437
}
434438
a.allocations = a.allocations[:0]
@@ -471,7 +475,7 @@ func (a *typeDecimalAllocator) TypeDecimal() (v *Ydb.Type_DecimalType) {
471475

472476
func (a *typeDecimalAllocator) free() {
473477
for _, v := range a.allocations {
474-
*v = Ydb.Type_DecimalType{}
478+
*v = Ydb.Type_DecimalType{DecimalType: new(Ydb.DecimalType)}
475479
typeDecimalPool.Put(v)
476480
}
477481
a.allocations = a.allocations[:0]
@@ -490,7 +494,7 @@ func (a *typeDictAllocator) TypeDict() (v *Ydb.Type_DictType) {
490494

491495
func (a *typeDictAllocator) free() {
492496
for _, v := range a.allocations {
493-
*v = Ydb.Type_DictType{}
497+
*v = Ydb.Type_DictType{DictType: new(Ydb.DictType)}
494498
typeDictPool.Put(v)
495499
}
496500
a.allocations = a.allocations[:0]
@@ -509,7 +513,7 @@ func (a *typeEmptyListAllocator) TypeEmptyList() (v *Ydb.Type_EmptyListType) {
509513

510514
func (a *typeEmptyListAllocator) free() {
511515
for _, v := range a.allocations {
512-
*v = Ydb.Type_EmptyListType{}
516+
*v = Ydb.Type_EmptyListType{EmptyListType: structpb.NullValue_NULL_VALUE}
513517
typeEmptyListPool.Put(v)
514518
}
515519
a.allocations = a.allocations[:0]
@@ -528,7 +532,7 @@ func (a *typeEmptyDictAllocator) TypeEmptyDict() (v *Ydb.Type_EmptyDictType) {
528532

529533
func (a *typeEmptyDictAllocator) free() {
530534
for _, v := range a.allocations {
531-
*v = Ydb.Type_EmptyDictType{}
535+
*v = Ydb.Type_EmptyDictType{EmptyDictType: structpb.NullValue_NULL_VALUE}
532536
typeEmptyDictPool.Put(v)
533537
}
534538
a.allocations = a.allocations[:0]
@@ -566,7 +570,7 @@ func (a *typeListAllocator) TypeList() (v *Ydb.Type_ListType) {
566570

567571
func (a *typeListAllocator) free() {
568572
for _, v := range a.allocations {
569-
*v = Ydb.Type_ListType{}
573+
*v = Ydb.Type_ListType{ListType: new(Ydb.ListType)}
570574
typeListPool.Put(v)
571575
}
572576
a.allocations = a.allocations[:0]
@@ -585,7 +589,7 @@ func (a *typeOptionalAllocator) TypeOptional() (v *Ydb.Type_OptionalType) {
585589

586590
func (a *typeOptionalAllocator) free() {
587591
for _, v := range a.allocations {
588-
*v = Ydb.Type_OptionalType{}
592+
*v = Ydb.Type_OptionalType{OptionalType: new(Ydb.OptionalType)}
589593
typeOptionalPool.Put(v)
590594
}
591595
a.allocations = a.allocations[:0]
@@ -604,7 +608,7 @@ func (a *typeStructAllocator) TypeStruct() (v *Ydb.Type_StructType) {
604608

605609
func (a *typeStructAllocator) free() {
606610
for _, v := range a.allocations {
607-
*v = Ydb.Type_StructType{}
611+
*v = Ydb.Type_StructType{StructType: new(Ydb.StructType)}
608612
typeStructPool.Put(v)
609613
}
610614
a.allocations = a.allocations[:0]
@@ -623,7 +627,7 @@ func (a *typeTupleAllocator) TypeTuple() (v *Ydb.Type_TupleType) {
623627

624628
func (a *typeTupleAllocator) free() {
625629
for _, v := range a.allocations {
626-
*v = Ydb.Type_TupleType{}
630+
*v = Ydb.Type_TupleType{TupleType: new(Ydb.TupleType)}
627631
typeTuplePool.Put(v)
628632
}
629633
a.allocations = a.allocations[:0]
@@ -642,7 +646,7 @@ func (a *typeVariantAllocator) TypeVariant() (v *Ydb.Type_VariantType) {
642646

643647
func (a *typeVariantAllocator) free() {
644648
for _, v := range a.allocations {
645-
*v = Ydb.Type_VariantType{}
649+
*v = Ydb.Type_VariantType{VariantType: new(Ydb.VariantType)}
646650
typeVariantPool.Put(v)
647651
}
648652
a.allocations = a.allocations[:0]
@@ -680,7 +684,7 @@ func (a *uint32Allocator) Uint32() (v *Ydb.Value_Uint32Value) {
680684

681685
func (a *uint32Allocator) free() {
682686
for _, v := range a.allocations {
683-
*v = Ydb.Value_Uint32Value{}
687+
*v = Ydb.Value_Uint32Value{Uint32Value: 0}
684688
uint32Pool.Put(v)
685689
}
686690
a.allocations = a.allocations[:0]
@@ -699,7 +703,7 @@ func (a *uint64Allocator) Uint64() (v *Ydb.Value_Uint64Value) {
699703

700704
func (a *uint64Allocator) free() {
701705
for _, v := range a.allocations {
702-
*v = Ydb.Value_Uint64Value{}
706+
*v = Ydb.Value_Uint64Value{Uint64Value: 0}
703707
uint64Pool.Put(v)
704708
}
705709
a.allocations = a.allocations[:0]

0 commit comments

Comments
 (0)