Highly-opinionated (ex-bullshit-free) MTPROTO proxy for Telegram. If you use v1.0 or upgrade broke you proxy, please read the chapter Version 2
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

buildinfo.go 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package main
  2. import (
  3. "crypto/sha256"
  4. "encoding/base64"
  5. "encoding/binary"
  6. "fmt"
  7. "io"
  8. "runtime/debug"
  9. "sort"
  10. "strconv"
  11. "time"
  12. )
  13. var version = "dev" // has to be set by ldflags
  14. const (
  15. buildInfoModuleStart byte = iota
  16. buildInfoModuleFinish
  17. buildInfoModuleDelimeter
  18. )
  19. func getVersion() string {
  20. buildInfo, ok := debug.ReadBuildInfo()
  21. if !ok {
  22. return version
  23. }
  24. date := time.Now()
  25. commit := ""
  26. goVersion := buildInfo.GoVersion
  27. dirtySuffix := ""
  28. for _, setting := range buildInfo.Settings {
  29. switch setting.Key {
  30. case "vcs.time":
  31. date, _ = time.Parse(time.RFC3339, setting.Value)
  32. case "vcs.revision":
  33. commit = setting.Value
  34. case "vcs.modified":
  35. if dirty, _ := strconv.ParseBool(setting.Value); dirty {
  36. dirtySuffix = " [dirty]"
  37. }
  38. }
  39. }
  40. hasher := sha256.New()
  41. checksumModule := func(mod *debug.Module) {
  42. hasher.Write([]byte{buildInfoModuleStart})
  43. io.WriteString(hasher, mod.Path) //nolint: errcheck
  44. hasher.Write([]byte{buildInfoModuleDelimeter})
  45. io.WriteString(hasher, mod.Version) //nolint: errcheck
  46. hasher.Write([]byte{buildInfoModuleDelimeter})
  47. io.WriteString(hasher, mod.Sum) //nolint: errcheck
  48. hasher.Write([]byte{buildInfoModuleFinish})
  49. }
  50. io.WriteString(hasher, buildInfo.Path) //nolint: errcheck
  51. binary.Write(hasher, binary.LittleEndian, uint64(1+len(buildInfo.Deps))) //nolint: errcheck
  52. sort.Slice(buildInfo.Deps, func(i, j int) bool {
  53. return buildInfo.Deps[i].Path > buildInfo.Deps[j].Path
  54. })
  55. checksumModule(&buildInfo.Main)
  56. for _, module := range buildInfo.Deps {
  57. checksumModule(module)
  58. }
  59. return fmt.Sprintf("%s (%s: %s on %s%s, modules checksum %s)",
  60. version,
  61. goVersion,
  62. date.Format(time.RFC3339),
  63. commit,
  64. dirtySuffix,
  65. base64.StdEncoding.EncodeToString(hasher.Sum(nil)))
  66. }