mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-11-24 08:46:54 +08:00
also migrate jsonpb
This commit is contained in:
@@ -1,11 +1,10 @@
|
||||
package volume_info
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"google.golang.org/protobuf/jsonpb"
|
||||
jsonpb "google.golang.org/protobuf/encoding/protojson"
|
||||
|
||||
"github.com/seaweedfs/seaweedfs/weed/glog"
|
||||
"github.com/seaweedfs/seaweedfs/weed/pb/volume_server_pb"
|
||||
@@ -44,7 +43,7 @@ func MaybeLoadVolumeInfo(fileName string) (volumeInfo *volume_server_pb.VolumeIn
|
||||
}
|
||||
|
||||
glog.V(1).Infof("maybeLoadVolumeInfo Unmarshal volume info %v", fileName)
|
||||
if err = jsonpb.Unmarshal(bytes.NewReader(tierData), volumeInfo); err != nil {
|
||||
if err = jsonpb.Unmarshal(tierData, volumeInfo); err != nil {
|
||||
glog.Warningf("unmarshal error: %v", err)
|
||||
err = fmt.Errorf("unmarshal error: %v", err)
|
||||
return
|
||||
@@ -65,17 +64,17 @@ func SaveVolumeInfo(fileName string, volumeInfo *volume_server_pb.VolumeInfo) er
|
||||
return fmt.Errorf("%s not writable", fileName)
|
||||
}
|
||||
|
||||
m := jsonpb.Marshaler{
|
||||
EmitDefaults: true,
|
||||
Indent: " ",
|
||||
m := jsonpb.MarshalOptions{
|
||||
EmitUnpopulated: true,
|
||||
Indent: " ",
|
||||
}
|
||||
|
||||
text, marshalErr := m.MarshalToString(volumeInfo)
|
||||
text, marshalErr := m.Marshal(volumeInfo)
|
||||
if marshalErr != nil {
|
||||
return fmt.Errorf("marshal to %s: %v", fileName, marshalErr)
|
||||
}
|
||||
|
||||
writeErr := util.WriteFile(fileName, []byte(text), 0755)
|
||||
writeErr := util.WriteFile(fileName, text, 0755)
|
||||
if writeErr != nil {
|
||||
return fmt.Errorf("fail to write %s : %v", fileName, writeErr)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user