Skip to content

Commit fb9edee

Browse files
authored
[chore][pkg/stanza] prevent unkeyed literal initialization (#43864)
1 parent c091a1c commit fb9edee

File tree

7 files changed

+20
-10
lines changed

7 files changed

+20
-10
lines changed

pkg/stanza/entry/attribute_field.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ func NewAttributeField(keys ...string) Field {
2222
if keys == nil {
2323
keys = []string{}
2424
}
25-
return Field{AttributeField{
26-
Keys: keys,
27-
}}
25+
return Field{
26+
FieldInterface: AttributeField{
27+
Keys: keys,
28+
},
29+
}
2830
}
2931

3032
// Parent returns the parent of the current field.

pkg/stanza/entry/body_field.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func NewBodyField(keys ...string) Field {
2121
if keys == nil {
2222
keys = []string{}
2323
}
24-
return Field{BodyField{
24+
return Field{FieldInterface: BodyField{
2525
Keys: keys,
2626
}}
2727
}

pkg/stanza/entry/entry_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,11 @@ func TestFieldFromString(t *testing.T) {
225225
output: Field{FieldInterface: AttributeField{Keys: []string{"test", "foo", "bar"}}},
226226
},
227227
{
228-
name: "SimpleResource",
229-
input: "resource.test",
230-
output: Field{ResourceField{Keys: []string{"test"}}},
228+
name: "SimpleResource",
229+
input: "resource.test",
230+
output: Field{
231+
FieldInterface: ResourceField{Keys: []string{"test"}},
232+
},
231233
},
232234
{
233235
name: "NestedResource",

pkg/stanza/entry/field.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ const (
2121
// It is deserialized from JSON dot notation.
2222
type Field struct {
2323
FieldInterface
24+
// prevent unkeyed literal initialization
25+
_ struct{}
2426
}
2527

2628
// RootableField is a Field that may refer directly to "attributes" or "resource"

pkg/stanza/entry/nil_field.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@ func (NilField) String() string {
3232

3333
// NewNilField will create a new nil field
3434
func NewNilField() Field {
35-
return Field{NilField{}}
35+
return Field{FieldInterface: NilField{}}
3636
}

pkg/stanza/entry/resource_field.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func NewResourceField(keys ...string) Field {
2222
if keys == nil {
2323
keys = []string{}
2424
}
25-
return Field{ResourceField{
25+
return Field{FieldInterface: ResourceField{
2626
Keys: keys,
2727
}}
2828
}
@@ -219,6 +219,8 @@ func (f *ResourceField) UnmarshalText(text []byte) error {
219219
return fmt.Errorf("must start with 'resource': %s", text)
220220
}
221221

222-
*f = ResourceField{Keys: keys[1:]}
222+
*f = ResourceField{
223+
Keys: keys[1:],
224+
}
223225
return nil
224226
}

pkg/stanza/operator/helper/output.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ func (c OutputConfig) Build(set component.TelemetrySettings) (OutputOperator, er
4141
// OutputOperator provides a basic implementation of an output operator.
4242
type OutputOperator struct {
4343
BasicOperator
44+
// prevent unkeyed literal initialization
45+
_ struct{}
4446
}
4547

4648
// CanProcess will always return true for an output operator.

0 commit comments

Comments
 (0)