jx/internal/resource/encoder.go
Matthew Rich 5a49359722
Some checks failed
Lint / golangci-lint (push) Failing after 10m8s
Declarative Tests / test (push) Successful in 54s
add encoder/decoder support for json and yaml
add support for jsonschema verification
2024-04-03 09:54:50 -07:00

43 lines
709 B
Go

// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
package resource
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
}