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.

main.go 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // mtg is just a command-line application that starts a proxy.
  2. //
  3. // Application logic is how to read a config and configure mtglib.Proxy.
  4. // So, probably you need to read the documentation for mtglib package
  5. // first.
  6. //
  7. // mtglib is a core of the application. The rest of the packages provide
  8. // some default implementations for the interfaces, defined in mtglib.
  9. package main
  10. import (
  11. "fmt"
  12. "math/rand"
  13. "runtime/debug"
  14. "strconv"
  15. "time"
  16. "github.com/9seconds/mtg/v2/internal/cli"
  17. "github.com/9seconds/mtg/v2/internal/utils"
  18. "github.com/alecthomas/kong"
  19. )
  20. var version = "dev" // has to be set by ldflags
  21. func main() {
  22. rand.Seed(time.Now().UTC().UnixNano())
  23. if err := utils.SetLimits(); err != nil {
  24. panic(err)
  25. }
  26. if buildInfo, ok := debug.ReadBuildInfo(); ok {
  27. vcsCommit := "<no-commit>"
  28. vcsDate := time.Now()
  29. vcsDirty := ""
  30. for _, setting := range buildInfo.Settings {
  31. switch setting.Key {
  32. case "vcs.time":
  33. vcsDate, _ = time.Parse(time.RFC3339, setting.Value)
  34. case "vcs.revision":
  35. vcsCommit = setting.Value
  36. case "vcs.modified":
  37. if isDirty, _ := strconv.ParseBool(setting.Value); isDirty {
  38. vcsDirty = " [dirty]"
  39. }
  40. }
  41. }
  42. version = fmt.Sprintf("%s (%s: %s on %s%s)",
  43. version,
  44. buildInfo.GoVersion,
  45. vcsDate.Format(time.RFC3339),
  46. vcsCommit,
  47. vcsDirty)
  48. }
  49. cli := &cli.CLI{}
  50. ctx := kong.Parse(cli, kong.Vars{
  51. "version": version,
  52. })
  53. ctx.FatalIfErrorf(ctx.Run(cli, version))
  54. }