-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
Copy pathopaque.go
36 lines (28 loc) · 956 Bytes
/
opaque.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package configopaque // import "go.opentelemetry.io/collector/config/configopaque"
import (
"fmt"
)
// String alias that is marshaled and printed in an opaque way.
// To recover the original value, cast it to a string.
type String string
const maskedString = "[REDACTED]"
// MarshalText marshals the string as `[REDACTED]`.
func (s String) MarshalText() ([]byte, error) {
return []byte(maskedString), nil
}
// String formats the string as `[REDACTED]`.
// This is used for the %s and %q verbs.
func (s String) String() string {
return maskedString
}
// GoString formats the string as `[REDACTED]`.
// This is used for the %#v verb.
func (s String) GoString() string {
return fmt.Sprintf("%#v", maskedString)
}
// MarshalBinary marshals the string `[REDACTED]` as []byte.
func (s String) MarshalBinary() (text []byte, err error) {
return []byte(maskedString), nil
}