version_report.go 935 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright 2016 Martin Hebnes Pedersen (LA5NTA). All rights reserved.
  2. // Use of this source code is governed by the MIT-license that can be
  3. // found in the LICENSE file.
  4. package main
  5. import (
  6. "encoding/json"
  7. "fmt"
  8. "os"
  9. "path"
  10. "runtime"
  11. "time"
  12. "github.com/la5nta/pat/internal/cmsapi"
  13. )
  14. func postVersionUpdate() error {
  15. var lastUpdated time.Time
  16. file, err := os.OpenFile(path.Join(appDir, "last_version_report.json"), os.O_RDWR|os.O_CREATE, 0600)
  17. if err != nil {
  18. return err
  19. }
  20. defer file.Close()
  21. json.NewDecoder(file).Decode(&lastUpdated)
  22. if time.Since(lastUpdated) < 24*time.Hour {
  23. return nil
  24. }
  25. v := cmsapi.VersionAdd{
  26. Callsign: fOptions.MyCall,
  27. Program: AppName,
  28. Version: Version,
  29. Comments: fmt.Sprintf("%s - %s/%s", GitRev, runtime.GOOS, runtime.GOARCH),
  30. }
  31. if err := v.Post(); err != nil {
  32. return err
  33. }
  34. file.Truncate(0)
  35. file.Seek(0, 0)
  36. return json.NewEncoder(file).Encode(time.Now())
  37. }