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
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

buildinfo.go 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. if _, err := io.WriteString(hasher, buildInfo.Path); err != nil {
  42. panic(err)
  43. }
  44. binary.Write(hasher, binary.LittleEndian, uint64(1+len(buildInfo.Deps))) //nolint: errcheck
  45. sort.Slice(buildInfo.Deps, func(i, j int) bool {
  46. return buildInfo.Deps[i].Path > buildInfo.Deps[j].Path
  47. })
  48. buildInfoCheckSumModule(hasher, &buildInfo.Main)
  49. for _, module := range buildInfo.Deps {
  50. buildInfoCheckSumModule(hasher, module)
  51. }
  52. return fmt.Sprintf("%s (%s: %s on %s%s, modules checksum %s)",
  53. version,
  54. goVersion,
  55. date.Format(time.RFC3339),
  56. commit,
  57. dirtySuffix,
  58. base64.StdEncoding.EncodeToString(hasher.Sum(nil)))
  59. }
  60. func buildInfoCheckSumModule(w io.Writer, module *debug.Module) {
  61. w.Write([]byte{buildInfoModuleStart}) //nolint: errcheck
  62. if _, err := io.WriteString(w, module.Path); err != nil {
  63. panic(err)
  64. }
  65. w.Write([]byte{buildInfoModuleDelimeter}) //nolint: errcheck
  66. if _, err := io.WriteString(w, module.Version); err != nil {
  67. panic(err)
  68. }
  69. w.Write([]byte{buildInfoModuleDelimeter}) //nolint: errcheck
  70. if _, err := io.WriteString(w, module.Sum); err != nil {
  71. panic(err)
  72. }
  73. w.Write([]byte{buildInfoModuleFinish}) //nolint: errcheck
  74. }