Debian Codegraph @

pipeline/internal/globalsignal/signal.go

raw symbols SCIP
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3
4 package globalsignal // import "go.opentelemetry.io/collector/pipeline/internal/globalsignal"
5
6 import (
7 "encoding"
8 "fmt"
9 )
10
11 var (
12 SignalProfiles = Signal{name: "profiles"}
13 SignalTraces = Signal{name: "traces"}
14 SignalMetrics = Signal{name: "metrics"}
15 SignalLogs = Signal{name: "logs"}
16
17 _ encoding.TextMarshaler = (*Signal)(nil)
18 _ encoding.TextUnmarshaler = (*Signal)(nil)
19 )
20
21 // Signal represents the signals supported by the collector.
22 type Signal struct {
23 name string
24 }
25
26 // String returns the string representation of the signal.
27 func (s Signal) String() string {
28 return s.name
29 }
30
31 // MarshalText marshals the Signal.
32 func (s Signal) MarshalText() ([]byte, error) {
33 return []byte(s.name), nil
34 }
35
36 // UnmarshalText marshals the Signal.
37 func (s *Signal) UnmarshalText(text []byte) error {
38 switch string(text) {
39 case SignalProfiles.name:
40 *s = SignalProfiles
41 case SignalTraces.name:
42 *s = SignalTraces
43 case SignalMetrics.name:
44 *s = SignalMetrics
45 case SignalLogs.name:
46 *s = SignalLogs
47 default:
48 return fmt.Errorf("unknown pipeline signal: %q", string(text))
49 }
50 return nil
51 }