Skip to content

Commit

Permalink
chore: prevent to sleep
Browse files Browse the repository at this point in the history
  • Loading branch information
fanhousanbu committed Mar 17, 2024
1 parent b17d720 commit 388fd53
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
17 changes: 11 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}()

Expand Down
12 changes: 11 additions & 1 deletion telegram/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package telegram

import (
"log"
"net/http"
"net/url"
"os"
"time"

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 388fd53

Please sign in to comment.