summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-10-07 01:15:27 -0500
committerJeff Carr <[email protected]>2025-10-07 01:15:27 -0500
commitdc99007397c61fbc5d173324f24ed7ad193394c0 (patch)
tree95376c948e011dc22c9a68282edc4b0bdf18baac
parent6d3e15dfdff1e1420a92975d78d8dad065e610a0 (diff)
hmm. maybe needed, maybe not
-rw-r--r--save.go28
1 files changed, 20 insertions, 8 deletions
diff --git a/save.go b/save.go
index dccbcaa..72d383e 100644
--- a/save.go
+++ b/save.go
@@ -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 {