encoding

package
v1.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 27, 2022 License: Apache-2.0 Imports: 9 Imported by: 18

Documentation

Overview

Package encoding provides encoding utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetJSONStringOrStringValue

func GetJSONStringOrStringValue(rawMessage json.RawMessage) string

GetJSONStringOrStringValue returns the JSON string for the RawMessage if the RawMessage is a string, and the raw value as a string otherwise.

If the RawMessage is empty, this returns "".

func InterfaceSliceOrStringToCommaSepString

func InterfaceSliceOrStringToCommaSepString(in interface{}) (string, error)

InterfaceSliceOrStringToCommaSepString parses the input as a slice or string into a comma separated string. This is commonly used with JSON or YAML fields that need to support both string slices and string literals.

func MarshalYAML

func MarshalYAML(v interface{}) (_ []byte, retErr error)

MarshalYAML marshals the given value into YAML.

func NewYAMLDecoderNonStrict

func NewYAMLDecoderNonStrict(reader io.Reader) *yaml.Decoder

NewYAMLDecoderNonStrict creates a new YAML decoder from the reader.

func NewYAMLDecoderStrict

func NewYAMLDecoderStrict(reader io.Reader) *yaml.Decoder

NewYAMLDecoderStrict creates a new YAML decoder from the reader.

func NewYAMLEncoder

func NewYAMLEncoder(writer io.Writer) *yaml.Encoder

NewYAMLEncoder creates a new YAML encoder reader from the Writer. The encoder must be closed after use.

func UnmarshalJSONNonStrict

func UnmarshalJSONNonStrict(data []byte, v interface{}) error

UnmarshalJSONNonStrict unmarshals the data as JSON, returning a user error on failure.

If the data length is 0, this is a no-op.

func UnmarshalJSONOrYAMLNonStrict

func UnmarshalJSONOrYAMLNonStrict(data []byte, v interface{}) error

UnmarshalJSONOrYAMLNonStrict unmarshals the data as JSON or YAML in order, returning a user error with both errors on failure.

If the data length is 0, this is a no-op.

func UnmarshalJSONOrYAMLStrict

func UnmarshalJSONOrYAMLStrict(data []byte, v interface{}) error

UnmarshalJSONOrYAMLStrict unmarshals the data as JSON or YAML in order, returning a user error with both errors on failure.

If the data length is 0, this is a no-op.

func UnmarshalJSONStrict

func UnmarshalJSONStrict(data []byte, v interface{}) error

UnmarshalJSONStrict unmarshals the data as JSON, returning a user error on failure.

If the data length is 0, this is a no-op.

func UnmarshalYAMLNonStrict

func UnmarshalYAMLNonStrict(data []byte, v interface{}) error

UnmarshalYAMLNonStrict unmarshals the data as YAML, returning a user error on failure.

If the data length is 0, this is a no-op.

func UnmarshalYAMLStrict

func UnmarshalYAMLStrict(data []byte, v interface{}) error

UnmarshalYAMLStrict unmarshals the data as YAML, returning a user error on failure.

If the data length is 0, this is a no-op.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL