diff options
Diffstat (limited to 'save.go')
| -rw-r--r-- | save.go | 28 |
1 files changed, 20 insertions, 8 deletions
@@ -24,8 +24,12 @@ func Save(pb proto.Message) error { if err != nil { return err } + return SavePB(pb, fullname) +} + +func SavePB(pb proto.Message, fullname string) error { if strings.HasSuffix(fullname, ".pb") { - SavePB(pb, fullname) + return saveProto(pb, fullname) } if strings.HasSuffix(fullname, ".text") { return saveTEXT(pb, "") @@ -36,7 +40,7 @@ func Save(pb proto.Message) error { return fmt.Errorf("unknown filetype %s", fullname) } -func SavePB(pb proto.Message, fullname string) error { +func saveProto(pb proto.Message, fullname string) error { if !strings.HasSuffix(fullname, ".pb") { // todo: append .text here? return log.Errorf("%s needs to end in '.pb'", fullname) @@ -55,7 +59,7 @@ func SavePB(pb proto.Message, fullname string) error { return err } - log.Infof("ConfigSave() %s (%s)\n", fullname, HumanFormatBytes(len(data))) + log.Infof("pb.Save() %s (%s)\n", fullname, HumanFormatBytes(len(data))) return configWrite(fullname, data) } @@ -99,10 +103,14 @@ func saveTEXT(pb proto.Message, header string) error { return err } - s := prototext.Format(pb) + data := prototext.Format(pb) - log.Infof("ConfigSave() filename=%s %d\n", fullname, len(s)) - return configWrite(fullname, []byte(header+s)) + err = configWrite(fullname, []byte(data)) + if err != nil { + return err + } + log.Infof("pb.Save() %s (%s)\n", fullname, HumanFormatBytes(len(data))) + return nil } func saveJSON(pb proto.Message) error { @@ -128,8 +136,12 @@ func saveJSON(pb proto.Message) error { fullname += ".json" - log.Infof("ConfigSave() filename=%s %d\n", fullname, len(data)) - return configWrite(fullname, []byte(data)) + err = configWrite(fullname, []byte(data)) + if err != nil { + return err + } + log.Infof("pb.Save() %s (%s)\n", fullname, HumanFormatBytes(len(data))) + return nil } func configWrite(fullname string, data []byte) error { |
