package main import ( "bytes" "encoding/json" "github.com/robfig/cron/v3" "github.com/tidwall/gjson" "io" "log" "net/http" "os" "proxy/internal/dto" ) func main() { file, err := os.Open("/root/client.ovpn") if err != nil { log.Fatalf("can not open file, err: %+v", err) } buf := bytes.Buffer{} if _, err := io.Copy(&buf, file); err != nil { log.Fatalf("can not read file, err: %+v", err) } resp, err := http.Get("https://ipinfo.ipidea.io") if err != nil { log.Fatalf("can not get resp, err: %+v", err) } bs, err := io.ReadAll(resp.Body) if err != nil { log.Fatalf("can not read resp, err: %+v", err) } countryCode := gjson.Get(string(bs), "country_code").String() log.Printf("get country code: %s", countryCode) request := dto.RegisterRequest{CountryCode: countryCode, Secret: buf.String()} body, err := json.Marshal(request) c := cron.New(cron.WithChain(cron.SkipIfStillRunning(cron.DefaultLogger))) if _, err := c.AddFunc("* * * * *", func() { // send request reader := bytes.NewBuffer(body) resp, err := http.Post("https://localhost:8080/register", "application/json", reader) if err != nil { log.Printf("err: %+v", err) } respBody, err := io.ReadAll(resp.Body) if err != nil { log.Printf("err: %+v", err) } log.Printf("resp: %s", string(respBody)) }); err != nil { log.Fatalf("err: %+v", err) } }