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 символов.

123456789101112131415161718192021222324252627282930313233343536373839
  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. speedCurrent: &speed{},
  15. mutex: &sync.RWMutex{},
  16. }
  17. http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
  18. w.Header().Set("Content-Type", "application/json")
  19. instance.mutex.Lock()
  20. first, _ := json.Marshal(instance)
  21. instance.mutex.Unlock()
  22. interm := map[string]interface{}{}
  23. json.Unmarshal(first, &interm)
  24. encoder := json.NewEncoder(w)
  25. encoder.SetEscapeHTML(false)
  26. encoder.SetIndent("", " ")
  27. encoder.Encode(interm)
  28. })
  29. http.ListenAndServe(conf.StatAddr(), nil)
  30. }