summaryrefslogtreecommitdiff
path: root/save.go
diff options
context:
space:
mode:
Diffstat (limited to 'save.go')
-rw-r--r--save.go19
1 files changed, 18 insertions, 1 deletions
diff --git a/save.go b/save.go
index 43e4044..3e4b9af 100644
--- a/save.go
+++ b/save.go
@@ -19,6 +19,23 @@ func ConfigSave(pb proto.Message) error {
return saveTEXT(pb, "")
}
+func Save(pb proto.Message) error {
+ fullname, ok := GetFilename(pb)
+ if !ok {
+ return ErrProtoFilename
+ }
+ if strings.HasSuffix(fullname, ".pb") {
+ SavePB(pb, fullname)
+ }
+ if strings.HasSuffix(fullname, ".text") {
+ return saveTEXT(pb, "")
+ }
+ if strings.HasSuffix(fullname, ".json") {
+ return saveJSON(pb)
+ }
+ return fmt.Errorf("unknown filetype %s", fullname)
+}
+
func SavePB(pb proto.Message, fullname string) error {
if !strings.HasSuffix(fullname, ".pb") {
// todo: append .text here?
@@ -38,7 +55,7 @@ func SavePB(pb proto.Message, fullname string) error {
return err
}
- log.Infof("ConfigSave() filename=%s %d\n", fullname, len(data))
+ log.Infof("ConfigSave() %s (%s)\n", fullname, HumanFormatBytes(len(data)))
return configWrite(fullname, data)
}