diff options
| author | Jeff Carr <[email protected]> | 2025-10-07 01:15:27 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-10-07 01:15:27 -0500 |
| commit | dc99007397c61fbc5d173324f24ed7ad193394c0 (patch) | |
| tree | 95376c948e011dc22c9a68282edc4b0bdf18baac | |
| parent | 6d3e15dfdff1e1420a92975d78d8dad065e610a0 (diff) | |
hmm. maybe needed, maybe not
| -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 { |
