Documentation ¶
Overview ¶
Package codec provides a simple interface for encoding and decoding values with JSON and YAML implementations, along with a means to configure them with a flag.FlagSet.
Index ¶
- func DecodeFromString(codec Codec, src string, dest interface{}) error
- func EncodeToString(codec Codec, obj interface{}) (string, error)
- func JSONBytesToYAMLBytes(data []byte) ([]byte, error)
- func JSONToYAML(in io.Reader, out io.Writer) error
- func YAMLBytesToJSONBytes(data []byte) ([]byte, error)
- func YAMLToJSON(in io.Reader, out io.Writer) error
- type Codec
- type FromFlags
- type MockCodec
- type MockCodecMockRecorder
- type MockFromFlags
- type MockFromFlagsMockRecorder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeFromString ¶
DecodeFromString uses the given codec to decode the given string into the given destination.
func EncodeToString ¶
EncodeToString uses the given Codec to encode an object to a string
func JSONBytesToYAMLBytes ¶
JSONBytesToYAMLBytes concerts JSON bytes to YAML bytes
func JSONToYAML ¶
JSONToYAML reads JSON from the given Reader, converts it to YAML, and writes it to the given writer.
func YAMLBytesToJSONBytes ¶
YAMLBytesToJSONBytes concerts YAML bytes to JSON bytes
Types ¶
type Codec ¶
type Codec interface { // Encode a value to a writer, based on the --format flag Encode(interface{}, io.Writer) error // Decode a value from a reader, based on the --format flag Decode(io.Reader, interface{}) error }
Codec allows encoding of an interface{} to an io.Writer and decoding from an io.Reader. This is a useful alternative to the golang binary encoding interfaces--which typically go to/from byte slices--when reading to and from files or file descriptors
func NewJson ¶
func NewJson() Codec
NewJson produces a Codec that reads and writes to JSON. The JSON produced by Encode is prettified for human consumption.
func NewJsonMin ¶
func NewJsonMin() Codec
NewJsonMin returns a Codec that reads and writes to JSON. The JSON written is not indented.
type FromFlags ¶
type FromFlags interface { // Validate verifies that all necessary flags are provided Validate() error // Make produces a new Codec from the provided flags Make() Codec // Type returns the type of the codec. Type() string }
FromFlags produces an Codec from a flag.FlagSet.
func NewFromFlags ¶
NewFromFlags produces a FromFlags, and installs necessary configuration flags into the provided FlagSet
type MockCodec ¶
type MockCodec struct {
// contains filtered or unexported fields
}
MockCodec is a mock of Codec interface
func NewMockCodec ¶
func NewMockCodec(ctrl *gomock.Controller) *MockCodec
NewMockCodec creates a new mock instance
func (*MockCodec) EXPECT ¶
func (m *MockCodec) EXPECT() *MockCodecMockRecorder
EXPECT returns an object that allows the caller to indicate expected use
type MockCodecMockRecorder ¶
type MockCodecMockRecorder struct {
// contains filtered or unexported fields
}
MockCodecMockRecorder is the mock recorder for MockCodec
func (*MockCodecMockRecorder) Decode ¶
func (mr *MockCodecMockRecorder) Decode(arg0, arg1 interface{}) *gomock.Call
Decode indicates an expected call of Decode
func (*MockCodecMockRecorder) Encode ¶
func (mr *MockCodecMockRecorder) Encode(arg0, arg1 interface{}) *gomock.Call
Encode indicates an expected call of Encode
type MockFromFlags ¶
type MockFromFlags struct {
// contains filtered or unexported fields
}
MockFromFlags is a mock of FromFlags interface
func NewMockFromFlags ¶
func NewMockFromFlags(ctrl *gomock.Controller) *MockFromFlags
NewMockFromFlags creates a new mock instance
func (*MockFromFlags) EXPECT ¶
func (m *MockFromFlags) EXPECT() *MockFromFlagsMockRecorder
EXPECT returns an object that allows the caller to indicate expected use
func (*MockFromFlags) Validate ¶
func (m *MockFromFlags) Validate() error
Validate mocks base method
type MockFromFlagsMockRecorder ¶
type MockFromFlagsMockRecorder struct {
// contains filtered or unexported fields
}
MockFromFlagsMockRecorder is the mock recorder for MockFromFlags
func (*MockFromFlagsMockRecorder) Make ¶
func (mr *MockFromFlagsMockRecorder) Make() *gomock.Call
Make indicates an expected call of Make
func (*MockFromFlagsMockRecorder) Type ¶
func (mr *MockFromFlagsMockRecorder) Type() *gomock.Call
Type indicates an expected call of Type
func (*MockFromFlagsMockRecorder) Validate ¶
func (mr *MockFromFlagsMockRecorder) Validate() *gomock.Call
Validate indicates an expected call of Validate