diff options
| author | Jeff Carr <[email protected]> | 2025-10-20 13:20:40 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-10-20 13:20:40 -0500 |
| commit | 5c4c1fcaf4e724573dd39b4d4fa0d600a9870221 (patch) | |
| tree | c50e35d812e30029a40132c7653504b79a0c3c9b /loadCache.go | |
| parent | c99d5193053a9377acfb62677bf241e540f9f6ee (diff) | |
maybe better than before. notsure
Diffstat (limited to 'loadCache.go')
| -rw-r--r-- | loadCache.go | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/loadCache.go b/loadCache.go new file mode 100644 index 0000000..f7ab6ae --- /dev/null +++ b/loadCache.go @@ -0,0 +1,49 @@ +package config + +import ( + "errors" + + "go.wit.com/log" + "google.golang.org/protobuf/proto" +) + +// loads foo.proto from ~/.cache/<appname>/foo.text +func CacheLoad(pb proto.Message) error { + appname, err := GetAppname() // already configured by your application + if err != nil { + return err + } + protoname, err := GetProtobufName(pb) // defined in the foo.proto file + if err != nil { + return err + } + + // Get ~/.cache/appname/protoname.text + fullname := makeCacheFilename(appname, protoname) + + // get the current filename in the protobuf file + curfilename, err := GetFilename(pb) + if err != nil { + return err + } + if curfilename == "" { + log.Printf("ConfigLoad() reading in %s\n", fullname) + } + + err = loadPB(pb, fullname) + if err != nil { + return ErrMarshal + } + + // If the cache file is new or has moved, this updates it to correct filename + // (the filename is what is used by pb.Save() + if curfilename != fullname { + _, err := SetFilename(pb, fullname) + if err != nil { + log.Info("FILENAME COULD NOT BE SET old=", curfilename) + log.Info("FILENAME COULD NOT BE SET new=", fullname) + return errors.Join(err, errors.New("something is wrong in lib/config")) + } + } + return nil +} |
