diff options
Diffstat (limited to 'metadata/config.go')
| -rw-r--r-- | metadata/config.go | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/metadata/config.go b/metadata/config.go index b3c8726..d9d694f 100644 --- a/metadata/config.go +++ b/metadata/config.go @@ -28,32 +28,41 @@ package metadata import ( "io" + "io/ioutil" - "github.com/golang/protobuf/jsonpb" + "google.golang.org/protobuf/encoding/protojson" ) // WriteConfig outputs the Config data as nicely formatted JSON func WriteConfig(config *Config, out io.Writer) error { - m := jsonpb.Marshaler{ - EmitDefaults: true, - EnumsAsInts: false, - Indent: "\t", - OrigName: true, + m := protojson.MarshalOptions{ + Multiline: true, + Indent: "\t", + UseProtoNames: true, + UseEnumNumbers: false, + EmitUnpopulated: true, } - if err := m.Marshal(out, config); err != nil { + bytes, err := m.Marshal(config) + if err != nil { return err } - - _, err := out.Write([]byte{'\n'}) + if _, err = out.Write(bytes); err != nil { + return err + } + _, err = out.Write([]byte{'\n'}) return err } // ReadConfig writes the JSON data into the config structure func ReadConfig(in io.Reader) (*Config, error) { + bytes, err := ioutil.ReadAll(in) + if err != nil { + return nil, err + } config := new(Config) - // Allow (and ignore) unknown fields for forwards compatibility. - u := jsonpb.Unmarshaler{ - AllowUnknownFields: true, + // Discard unknown fields for forwards compatibility. + u := protojson.UnmarshalOptions{ + DiscardUnknown: true, } - return config, u.Unmarshal(in, config) + return config, u.Unmarshal(bytes, config) } |