codectool

package
v2.7.3 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package codectool provides some codec tools for JSON and YAML marshaling.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(r io.Reader, v interface{}) error

Decode decodes a json stream into a value of the given type. It converts yaml to json before decoding by leveraging Unmarshal.

func DecodeJSON

func DecodeJSON(r io.Reader, v interface{}) error

DecodeJSON decodes a json stream into a value of the given type.

func DecodeYAML

func DecodeYAML(r io.Reader, v interface{}) error

DecodeYAML decodes a yaml stream into a value of the given type.

func EncodeJSON

func EncodeJSON(w io.Writer, v interface{}) error

EncodeJSON encodes a value into a json stream.

func EncodeYAML

func EncodeYAML(w io.Writer, v interface{}) error

EncodeYAML encodes a value into a yaml stream.

func JSONToYAML

func JSONToYAML(in []byte) ([]byte, error)

JSONToYAML converts a json stream into a yaml stream.

func MarshalJSON

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

MarshalJSON wraps json.Marshal.

func MarshalYAML

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

MarshalYAML wraps yaml.MarshalYAML.

func MustDecode

func MustDecode(r io.Reader, v interface{})

MustDecode decodes a json stream into a value of the given type. It converts yaml to json before decoding by leveraging Unmarshal. It panics if an error occurs.

func MustDecodeJSON

func MustDecodeJSON(r io.Reader, v interface{})

MustDecodeJSON decodes a json stream into a value of the given type. It panics if an error occurs.

func MustDecodeYAML

func MustDecodeYAML(r io.Reader, v interface{})

MustDecodeYAML decodes a yaml stream into a value of the given type. It panics if an error occurs.

func MustEncodeJSON

func MustEncodeJSON(w io.Writer, v interface{})

MustEncodeJSON encodes a value into a json stream. It panics if an error occurs.

func MustEncodeYAML

func MustEncodeYAML(w io.Writer, v interface{})

MustEncodeYAML encodes a value into a yaml stream. It panics if an error occurs.

func MustJSONToYAML

func MustJSONToYAML(in []byte) []byte

MustJSONToYAML converts a json stream into a yaml stream. It panics if an error occurs.

func MustMarshalJSON

func MustMarshalJSON(v interface{}) []byte

MustMarshalJSON wraps json.Marshal by panic instead of returning error.

func MustMarshalYAML

func MustMarshalYAML(v interface{}) []byte

MustMarshalYAML wraps yaml.Marshal by panic instead of returning error.

func MustUnmarshal

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

MustUnmarshal wraps json.MustUnmarshal by panic instead of returning error. It converts yaml to json before decoding by leveraging Unmarshal. It panics if an error occurs.

func MustUnmarshalJSON

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

MustUnmarshalJSON wraps json.Unmarshal. It panics if an error occurs.

func MustUnmarshalYAML

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

MustUnmarshalYAML wraps yaml.Unmarshal by panic instead of returning error.

func MustYAMLToJSON

func MustYAMLToJSON(in []byte) []byte

MustYAMLToJSON converts a json stream into a yaml stream. It panics if an error occurs.

func StructToMap

func StructToMap(s interface{}) (map[string]interface{}, error)

StructToMap converts a struct to a map based on json marshal.

func Unmarshal

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

Unmarshal wraps json.Unmarshal. It will convert yaml to json before unmarshal. Since json is a subset of yaml, passing json through this method should be a no-op.

func UnmarshalJSON

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

UnmarshalJSON wraps json.Unmarshal.

func UnmarshalYAML

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

UnmarshalYAML wraps yaml.Unmarshal.

func YAMLToJSON

func YAMLToJSON(in []byte) ([]byte, error)

YAMLToJSON converts a yaml stream into a json stream.

Types

This section is empty.

Jump to

Keyboard shortcuts

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