Browse Source

filere.conf: prefer to use json format

logrus
Chris Lu 4 years ago
parent
commit
c0d279c54e
  1. 16
      weed/filer/filer_conf.go
  2. 1
      weed/shell/command_fs_configure.go

16
weed/filer/filer_conf.go

@ -1,12 +1,14 @@
package filer package filer
import ( import (
"bytes"
"context" "context"
"io" "io"
"github.com/chrislusf/seaweedfs/weed/glog" "github.com/chrislusf/seaweedfs/weed/glog"
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb" "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
"github.com/chrislusf/seaweedfs/weed/util" "github.com/chrislusf/seaweedfs/weed/util"
"github.com/golang/protobuf/jsonpb"
"github.com/golang/protobuf/proto" "github.com/golang/protobuf/proto"
"github.com/viant/ptrie" "github.com/viant/ptrie"
) )
@ -53,6 +55,9 @@ func (fc *FilerConf) loadFromChunks(filer *Filer, chunks []*filer_pb.FileChunk)
func (fc *FilerConf) LoadFromBytes(data []byte) (err error) { func (fc *FilerConf) LoadFromBytes(data []byte) (err error) {
conf := &filer_pb.FilerConf{} conf := &filer_pb.FilerConf{}
if err := jsonpb.Unmarshal(bytes.NewReader(data), conf); err != nil {
err = proto.UnmarshalText(string(data), conf) err = proto.UnmarshalText(string(data), conf)
if err != nil { if err != nil {
glog.Errorf("unable to parse filer conf: %v", err) glog.Errorf("unable to parse filer conf: %v", err)
@ -60,6 +65,9 @@ func (fc *FilerConf) LoadFromBytes(data []byte) (err error) {
return nil return nil
} }
return nil
}
return fc.doLoadConf(conf) return fc.doLoadConf(conf)
} }
@ -121,5 +129,11 @@ func (fc *FilerConf) ToProto() *filer_pb.FilerConf {
} }
func (fc *FilerConf) ToText(writer io.Writer) error { func (fc *FilerConf) ToText(writer io.Writer) error {
return proto.MarshalText(writer, fc.ToProto())
m := jsonpb.Marshaler{
EmitDefaults: false,
Indent: " ",
}
return m.Marshal(writer, fc.ToProto())
} }

1
weed/shell/command_fs_configure.go

@ -99,6 +99,7 @@ func (c *commandFsConfigure) Do(args []string, commandEnv *CommandEnv, writer io
fc.ToText(&buf) fc.ToText(&buf)
fmt.Fprintf(writer, string(buf.Bytes())) fmt.Fprintf(writer, string(buf.Bytes()))
fmt.Fprintln(writer)
if *apply { if *apply {

Loading…
Cancel
Save