43 lines
703 B
Go
43 lines
703 B
Go
|
// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
|
||
|
|
||
|
package codec
|
||
|
|
||
|
import (
|
||
|
"encoding/json"
|
||
|
_ "fmt"
|
||
|
_ "github.com/xeipuuv/gojsonschema"
|
||
|
"gopkg.in/yaml.v3"
|
||
|
"io"
|
||
|
_ "log"
|
||
|
)
|
||
|
|
||
|
type JSONEncoder json.Encoder
|
||
|
|
||
|
type Encoder interface {
|
||
|
Encode(v any) error
|
||
|
Close() error
|
||
|
}
|
||
|
|
||
|
func NewEncoder() *Encoder {
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
func NewJSONEncoder(w io.Writer) Encoder {
|
||
|
return (*JSONEncoder)(json.NewEncoder(w))
|
||
|
}
|
||
|
|
||
|
func NewYAMLEncoder(w io.Writer) Encoder {
|
||
|
return yaml.NewEncoder(w)
|
||
|
}
|
||
|
|
||
|
func NewProtoBufEncoder(w io.Writer) Encoder {
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
func (j *JSONEncoder) Encode(v any) error {
|
||
|
return (*json.Encoder)(j).Encode(v)
|
||
|
}
|
||
|
func (j *JSONEncoder) Close() error {
|
||
|
return nil
|
||
|
}
|