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
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

server.go 784B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package stats
  2. import (
  3. "encoding/json"
  4. "net/http"
  5. "sync"
  6. "time"
  7. "github.com/9seconds/mtg/config"
  8. )
  9. var instance *stats
  10. func Start(conf *config.Config) {
  11. instance = &stats{
  12. URLs: conf.GetURLs(),
  13. Uptime: uptime(time.Now()),
  14. mutex: &sync.RWMutex{},
  15. }
  16. go crashManager()
  17. go connectionManager()
  18. go trafficManager()
  19. http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
  20. w.Header().Set("Content-Type", "application/json")
  21. instance.mutex.Lock()
  22. first, _ := json.Marshal(instance)
  23. instance.mutex.Unlock()
  24. interm := map[string]interface{}{}
  25. json.Unmarshal(first, &interm)
  26. encoder := json.NewEncoder(w)
  27. encoder.SetEscapeHTML(false)
  28. encoder.SetIndent("", " ")
  29. encoder.Encode(interm)
  30. })
  31. http.ListenAndServe(conf.StatAddr(), nil)
  32. }