1// Copyright The OpenTelemetry Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//       http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package config
16
17// Receiver is the configuration of a component.Receiver. Specific extensions must implement
18// this interface and must embed ReceiverSettings struct or a struct that extends it.
19type Receiver interface {
20	identifiable
21	validatable
22
23	privateConfigReceiver()
24}
25
26// Receivers is a map of names to Receivers.
27type Receivers map[ComponentID]Receiver
28
29// ReceiverSettings defines common settings for a component.Receiver configuration.
30// Specific receivers can embed this struct and extend it with more fields if needed.
31//
32// It is highly recommended to "override" the Validate() function.
33//
34// When embedded in the receiver config it must be with `mapstructure:",squash"` tag.
35type ReceiverSettings struct {
36	id ComponentID `mapstructure:"-"`
37}
38
39// NewReceiverSettings return a new ReceiverSettings with the given ComponentID.
40func NewReceiverSettings(id ComponentID) ReceiverSettings {
41	return ReceiverSettings{id: ComponentID{typeVal: id.Type(), nameVal: id.Name()}}
42}
43
44var _ Receiver = (*ReceiverSettings)(nil)
45
46// ID returns the receiver ComponentID.
47func (rs *ReceiverSettings) ID() ComponentID {
48	return rs.id
49}
50
51// SetIDName sets the receiver name.
52func (rs *ReceiverSettings) SetIDName(idName string) {
53	rs.id.nameVal = idName
54}
55
56// Validate validates the configuration and returns an error if invalid.
57func (rs *ReceiverSettings) Validate() error {
58	return nil
59}
60
61func (rs *ReceiverSettings) privateConfigReceiver() {}
62