mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-09-19 10:08:30 +08:00
also migrate jsonpb
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user