diff --git a/config/exporter.go b/config/exporter.go index f56d55e425f..1b3176fb672 100644 --- a/config/exporter.go +++ b/config/exporter.go @@ -13,6 +13,7 @@ // limitations under the License. package config // import "go.opentelemetry.io/collector/config" + import ( "go.opentelemetry.io/collector/component" ) @@ -24,23 +25,12 @@ import ( // // When embedded in the exporter config, it must be with `mapstructure:",squash"` tag. type ExporterSettings struct { - id component.ID `mapstructure:"-"` - component.ExporterConfig + settings } // NewExporterSettings return a new ExporterSettings with the given ComponentID. func NewExporterSettings(id component.ID) ExporterSettings { - return ExporterSettings{id: id} + return ExporterSettings{settings: newSettings(id)} } var _ component.ExporterConfig = (*ExporterSettings)(nil) - -// ID returns the receiver component.ID. -func (es *ExporterSettings) ID() component.ID { - return es.id -} - -// SetIDName sets the receiver name. -func (es *ExporterSettings) SetIDName(idName string) { - es.id = component.NewIDWithName(es.id.Type(), idName) -} diff --git a/config/extension.go b/config/extension.go index 99054c5506a..209a06222d5 100644 --- a/config/extension.go +++ b/config/extension.go @@ -24,23 +24,12 @@ import ( // // When embedded in the extension config, it must be with `mapstructure:",squash"` tag. type ExtensionSettings struct { - id component.ID `mapstructure:"-"` - component.ExtensionConfig + settings } // NewExtensionSettings return a new ExtensionSettings with the given ID. func NewExtensionSettings(id component.ID) ExtensionSettings { - return ExtensionSettings{id: id} + return ExtensionSettings{settings: newSettings(id)} } var _ component.ExtensionConfig = (*ExtensionSettings)(nil) - -// ID returns the receiver ID. -func (es *ExtensionSettings) ID() component.ID { - return es.id -} - -// SetIDName sets the receiver name. -func (es *ExtensionSettings) SetIDName(idName string) { - es.id = component.NewIDWithName(es.id.Type(), idName) -} diff --git a/config/processor.go b/config/processor.go index d8288a603f0..5950c667516 100644 --- a/config/processor.go +++ b/config/processor.go @@ -24,23 +24,12 @@ import ( // // When embedded in the processor config it must be with `mapstructure:",squash"` tag. type ProcessorSettings struct { - id component.ID `mapstructure:"-"` - component.ProcessorConfig + settings } // NewProcessorSettings return a new ProcessorSettings with the given ComponentID. func NewProcessorSettings(id component.ID) ProcessorSettings { - return ProcessorSettings{id: id} + return ProcessorSettings{settings: newSettings(id)} } var _ component.ProcessorConfig = (*ProcessorSettings)(nil) - -// ID returns the receiver ComponentID. -func (ps *ProcessorSettings) ID() component.ID { - return ps.id -} - -// SetIDName sets the receiver name. -func (ps *ProcessorSettings) SetIDName(idName string) { - ps.id = component.NewIDWithName(ps.id.Type(), idName) -} diff --git a/config/receiver.go b/config/receiver.go index e647e5ebadb..2c29d7db1b6 100644 --- a/config/receiver.go +++ b/config/receiver.go @@ -24,23 +24,12 @@ import ( // // When embedded in the receiver config it must be with `mapstructure:",squash"` tag. type ReceiverSettings struct { - id component.ID `mapstructure:"-"` - component.ReceiverConfig + settings } // NewReceiverSettings return a new ReceiverSettings with the given ID. func NewReceiverSettings(id component.ID) ReceiverSettings { - return ReceiverSettings{id: id} + return ReceiverSettings{settings: newSettings(id)} } var _ component.ReceiverConfig = (*ReceiverSettings)(nil) - -// ID returns the receiver ID. -func (rs *ReceiverSettings) ID() component.ID { - return rs.id -} - -// SetIDName sets the receiver name. -func (rs *ReceiverSettings) SetIDName(idName string) { - rs.id = component.NewIDWithName(rs.id.Type(), idName) -} diff --git a/config/settings.go b/config/settings.go new file mode 100644 index 00000000000..b4f289c0ad3 --- /dev/null +++ b/config/settings.go @@ -0,0 +1,40 @@ +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package config // import "go.opentelemetry.io/collector/config" + +import ( + "go.opentelemetry.io/collector/component" +) + +type settings struct { + id component.ID `mapstructure:"-"` + component.Config +} + +func newSettings(id component.ID) settings { + return settings{id: id} +} + +var _ component.Config = (*settings)(nil) + +// ID returns the receiver component.ID. +func (es *settings) ID() component.ID { + return es.id +} + +// SetIDName sets the receiver name. +func (es *settings) SetIDName(idName string) { + es.id = component.NewIDWithName(es.id.Type(), idName) +}