replace gogo protobuf and switch linter

This commit is contained in:
Willy Kloucek
2021-10-14 15:56:19 +02:00
parent cbac7e0052
commit 42b60fddb6
6 changed files with 21 additions and 16 deletions
+10 -5
View File
@@ -1,9 +1,10 @@
package store
import (
"io/ioutil"
"os"
"github.com/gogo/protobuf/jsonpb"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/proto"
)
@@ -15,8 +16,12 @@ func (s Store) parseRecordFromFile(record proto.Message, filePath string) error
}
defer file.Close()
decoder := jsonpb.Unmarshaler{}
if err = decoder.Unmarshal(file, record); err != nil {
b, err := ioutil.ReadAll(file)
if err != nil {
return err
}
if err := protojson.Unmarshal(b, record); err != nil {
return err
}
return nil
@@ -30,8 +35,8 @@ func (s Store) writeRecordToFile(record proto.Message, filePath string) error {
}
defer file.Close()
encoder := jsonpb.Marshaler{}
if err = encoder.Marshal(file, record); err != nil {
if v, err := protojson.Marshal(record); err != nil {
file.Write(v)
return err
}