diff --git a/main.go b/main.go index 180fa79..8a5b9e8 100644 --- a/main.go +++ b/main.go @@ -4,30 +4,35 @@ import ( "fmt" "github.com/assimon/captcha-bot/bootstrap" "io" + "log" "net/http" + "strconv" "time" ) +var counter = 0 + func main() { go func() { http.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) { + counter++ w.Header().Set("Access-Control-Allow-Origin", "*") - fmt.Fprintf(w, "OK") + _, _ = fmt.Fprintf(w, "OK, checker: "+strconv.Itoa(counter)) }) - http.ListenAndServe(":80", nil) + _ = http.ListenAndServe(":80", nil) }() go func() { - t := time.NewTimer(time.Second * 10) + t := time.Tick(time.Second * 10) for { if resp, err := http.Get("https://captcha-bot-zg9p.onrender.com/healthz"); err != nil { - fmt.Println(fmt.Sprintf("err:%v", err)) + log.Default().Printf("error: " + err.Error()) } else { if b, err := io.ReadAll(resp.Body); err == nil { - fmt.Println("health: " + string(b)) + log.Default().Printf("health: " + string(b)) } } - <-t.C + <-t } }() diff --git a/telegram/root.go b/telegram/root.go index 4a7e594..a4264e6 100644 --- a/telegram/root.go +++ b/telegram/root.go @@ -2,6 +2,8 @@ package telegram import ( "log" + "net/http" + "net/url" "os" "time" @@ -35,7 +37,15 @@ func BotStart() { } // ๅๅ‘ไปฃ็† if config.TelegramC.ApiProxy != "" { - setting.URL = config.TelegramC.ApiProxy + trans := &http.Transport{ + Proxy: func(_ *http.Request) (*url.URL, error) { + return url.Parse(config.TelegramC.ApiProxy) + }, + } + setting.Client = &http.Client{ + Timeout: time.Minute, + Transport: trans, + } } var err error Bot, err = tb.NewBot(setting)