Skip to content

Commit f17e470

Browse files
authored
[chore][component] Minor stylistic updates to component.ID (open-telemetry#13543)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description Minor stylistic things I noticed while looking at `component.ID`: * We should assert the interfaces it implements. * We don't use the "result parameters"/named return parameters in `MarshalText`. I'm more ambivalent on this one, but I was a bit surprised to see them when they're not used. I can see reasons to keep them as well if we'd prefer.
1 parent ae29ab5 commit f17e470

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

component/identifiable.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package component // import "go.opentelemetry.io/collector/component"
55

66
import (
7+
"encoding"
78
"errors"
89
"fmt"
910
"regexp"
@@ -71,6 +72,12 @@ func MustNewType(strType string) Type {
7172
return ty
7273
}
7374

75+
var (
76+
_ fmt.Stringer = ID{}
77+
_ encoding.TextMarshaler = ID{}
78+
_ encoding.TextUnmarshaler = (*ID)(nil)
79+
)
80+
7481
// ID represents the identity for a component. It combines two values:
7582
// * type - the Type of the component.
7683
// * name - the name of that component.
@@ -116,7 +123,7 @@ func (id ID) Name() string {
116123

117124
// MarshalText implements the encoding.TextMarshaler interface.
118125
// This marshals the type and name as one string in the config.
119-
func (id ID) MarshalText() (text []byte, err error) {
126+
func (id ID) MarshalText() ([]byte, error) {
120127
return []byte(id.String()), nil
121128
}
122129

0 commit comments

Comments
 (0)