Documentation
¶
Index ¶
- Constants
- func PrepareTextMarshalerValue(tm encoding.TextMarshaler) string
- type Config
- type Encoder
- type TextEncoder
- func (te *TextEncoder) Encode(b *strings.Builder, f reflect.Value)
- func (te *TextEncoder) Interface(b *strings.Builder, rv reflect.Value)
- func (te *TextEncoder) Map(b *strings.Builder, rv reflect.Value)
- func (te *TextEncoder) Ptr(b *strings.Builder, rv reflect.Value)
- func (te *TextEncoder) Slice(b *strings.Builder, rv reflect.Value)
- func (te *TextEncoder) String(b *strings.Builder, s string)
- func (te *TextEncoder) Struct(b *strings.Builder, rv reflect.Value)
Constants ¶
const ( // DefaultCensorFieldTag is a default tag name for censor fields. DefaultCensorFieldTag = "censor" // UnsupportedTypeTmpl is a template for a value that is returned when a given type is not supported. UnsupportedTypeTmpl = "unsupported type=" )
Variables ¶
This section is empty.
Functions ¶
func PrepareTextMarshalerValue ¶
func PrepareTextMarshalerValue(tm encoding.TextMarshaler) string
PrepareTextMarshalerValue marshals a value that implements encoding.TextMarshaler interface to string.
Types ¶
type Config ¶
type Config struct {
// DisplayMapType is used to display map type in the output.
// The default value is false.
DisplayMapType bool `yaml:"display-map-type"`
// DisplayPointerSymbol is used to display '&' (pointer symbol) in the output.
// The default value is false.
DisplayPointerSymbol bool `yaml:"display-pointer-symbol"`
// DisplayStructName is used to display struct name in the output.
// A struct name includes the last part of the package path.
// The default value is false.
DisplayStructName bool `yaml:"display-struct-name"`
// ExcludePatterns contains regexp patterns that are used for the selection
// of strings that must be masked.
ExcludePatterns []string `yaml:"exclude-patterns"`
// MaskValue is used to mask struct fields with sensitive data.
// The default value is stored in DefaultMaskValue constant.
MaskValue string `yaml:"mask-value"`
// UseJSONTagName sets whether to use the `json` tag to get the name of the struct field.
// If no `json` tag is present, the name of the struct field is used.
UseJSONTagName bool `yaml:"use-json-tag-name"`
}
Config describes censor Encoder configuration.
type Encoder ¶
type Encoder interface {
Struct(b *strings.Builder, rv reflect.Value)
Ptr(b *strings.Builder, rv reflect.Value)
Slice(b *strings.Builder, rv reflect.Value)
Map(b *strings.Builder, rv reflect.Value)
Interface(b *strings.Builder, rv reflect.Value)
String(b *strings.Builder, s string)
Encode(b *strings.Builder, f reflect.Value)
}
type TextEncoder ¶
type TextEncoder struct {
// DisplayMapType is used to display map type in the output.
// The default value is false.
DisplayMapType bool
// DisplayPointerSymbol is used to display '&' (pointer symbol) in the output.
// The default value is false.
DisplayPointerSymbol bool
// DisplayStructName is used to display struct name in the output.
// A struct name includes the last part of the package path.
// The default value is false.
DisplayStructName bool
// contains filtered or unexported fields
}
TextEncoder is a struct that contains options for parsing.
func NewTextEncoder ¶
func NewTextEncoder(c Config) *TextEncoder
NewTextEncoder returns a new instance of TextEncoder with given configuration.
func (*TextEncoder) Interface ¶
func (te *TextEncoder) Interface(b *strings.Builder, rv reflect.Value)
Interface parses an interface and returns an Interface. In case of a pointer to unsupported type of value, a string built from UnsupportedTypeTmpl is used instead of the real value. That string contains a type of the value.
func (*TextEncoder) Map ¶
func (te *TextEncoder) Map(b *strings.Builder, rv reflect.Value)
Map parses a given value and returns a Map. If value is a struct/pointer/slice/array/map/interface, it will be parsed recursively. Note: this method panics if the provided value is not a complex.
func (*TextEncoder) Ptr ¶
func (te *TextEncoder) Ptr(b *strings.Builder, rv reflect.Value)
Ptr parses a given value and returns a Ptr. If the value is nil, it returns a Ptr with a nil Value. In case of a pointer to unsupported type of value, a string built from UnsupportedTypeTmpl is used instead of the real value. That string contains a type of the value.
func (*TextEncoder) Slice ¶
func (te *TextEncoder) Slice(b *strings.Builder, rv reflect.Value)
Slice parses a given value and returns a Slice. This function is also can be used to parse an array. All supported complex types will be parsed recursively. Note: this method panics if the provided value is not a complex.