also migrate jsonpb

This commit is contained in:
chrislu
2022-08-17 12:42:03 -07:00
parent eaeb141b09
commit 2b580a7566
15 changed files with 47 additions and 85 deletions

View File

@@ -1,17 +1,16 @@
package filer
import (
"bytes"
"fmt"
"io"
"github.com/seaweedfs/seaweedfs/weed/pb/iam_pb"
"google.golang.org/protobuf/jsonpb"
jsonpb "google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/proto"
)
func ParseS3ConfigurationFromBytes[T proto.Message](content []byte, config T) error {
if err := jsonpb.Unmarshal(bytes.NewBuffer(content), config); err != nil {
if err := jsonpb.Unmarshal(content, config); err != nil {
return err
}
return nil
@@ -19,12 +18,22 @@ func ParseS3ConfigurationFromBytes[T proto.Message](content []byte, config T) er
func ProtoToText(writer io.Writer, config proto.Message) error {
m := jsonpb.Marshaler{
EmitDefaults: false,
Indent: " ",
m := jsonpb.MarshalOptions{
EmitUnpopulated: true,
Indent: " ",
}
return m.Marshal(writer, config)
text, marshalErr := m.Marshal(config)
if marshalErr != nil {
return fmt.Errorf("marshal proto message: %v", marshalErr)
}
_, writeErr := writer.Write(text)
if writeErr != nil {
return fmt.Errorf("fail to write proto message: %v", writeErr)
}
return writeErr
}
// CheckDuplicateAccessKey returns an error message when s3cfg has duplicate access keys