diff options
| author | Jeff Carr <[email protected]> | 2025-10-06 23:10:00 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-10-06 23:10:00 -0500 |
| commit | b695089179b9003375a8c51ce45efeaffcc2e816 (patch) | |
| tree | 0e0dbdadae2efc4176719a8ad8ebe360b82d8b5e /save.go | |
| parent | 96b5157afc629037f436e5a6d6ec40b4915ff64c (diff) | |
awesome shortcuts
Diffstat (limited to 'save.go')
| -rw-r--r-- | save.go | 19 |
1 files changed, 18 insertions, 1 deletions
@@ -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) } |
