diff options
| author | Jeff Carr <[email protected]> | 2025-10-22 09:19:26 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-10-22 09:19:26 -0500 |
| commit | 23b2d19bc03b4db253b15cc6fef7176ab31d4f18 (patch) | |
| tree | 275cb2d3fc92cb5af997582c715f4619eb1d68d2 /versionCheck.go | |
| parent | 820fa4b7e71690accbd17063894032140bd9c4b6 (diff) | |
finally can fix the Load() and Save() names
Diffstat (limited to 'versionCheck.go')
| -rw-r--r-- | versionCheck.go | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/versionCheck.go b/versionCheck.go new file mode 100644 index 0000000..1beb7a5 --- /dev/null +++ b/versionCheck.go @@ -0,0 +1,53 @@ +package config + +import ( + "errors" + + "go.wit.com/lib/protobuf/filepb" + "google.golang.org/protobuf/proto" +) + +// verify 'version' for .pb files +// application should die if they don't match +// returns (newVersion, oldVersion, error) +func VersionCheck(pb proto.Message) (string, string, error) { + fullname, err := GetFilename(pb) + if err != nil { + return "", "", err + } + return VersionCheckFile(pb, fullname) +} + +// verify 'version' for .pb files +// application should die if they don't match +// returns (newVersion, oldVersion, error) +func VersionCheckFile(pb proto.Message, filename string) (string, string, error) { + var newVersion string + var newUuid string + var err error + + newVersion, err = GetString(pb, "version") + if err != nil { + return newVersion, "", err + } + + newUuid, err = GetString(pb, "uuid") + if err != nil { + return newVersion, newUuid, err + } + + oldVersion, oldUuid, err := filepb.IdentifyPB(filename) + if err != nil { + return newVersion, newUuid, err + } + + if newVersion != oldVersion { + return newVersion, oldVersion, errors.New("version mismatch") + } + + if newUuid != oldUuid { + return newVersion, oldVersion, errors.New("UUID mismatch") + } + + return newVersion, oldVersion, nil +} |
