Browse Source

mod: slave

Ben 1 year ago
parent
commit
7d18596326
3 changed files with 10 additions and 10 deletions
  1. 6 5
      cmd/slave.go
  2. 4 3
      go.mod
  3. 0 2
      go.sum

+ 6 - 5
cmd/slave.go

@@ -4,12 +4,12 @@ import (
 	"be-vpn/internal/dto"
 	"bytes"
 	"encoding/json"
-	"github.com/robfig/cron/v3"
 	"github.com/tidwall/gjson"
 	"io"
 	"log"
 	"net/http"
 	"os"
+	"time"
 )
 
 func main() {
@@ -35,9 +35,11 @@ func main() {
 
 	request := dto.RegisterRequest{CountryCode: countryCode, Secret: buf.String()}
 	body, err := json.Marshal(request)
+	if err != nil {
+		log.Printf("err: %+v", err)
+	}
 
-	c := cron.New(cron.WithChain(cron.SkipIfStillRunning(cron.DefaultLogger)))
-	if _, err := c.AddFunc("* * * * *", func() {
+	for true {
 		// send request
 		reader := bytes.NewBuffer(body)
 		resp, err := http.Post("https://localhost:8080/register", "application/json", reader)
@@ -49,7 +51,6 @@ func main() {
 			log.Printf("err: %+v", err)
 		}
 		log.Printf("resp: %s", string(respBody))
-	}); err != nil {
-		log.Fatalf("err: %+v", err)
+		time.Sleep(1 * time.Second)
 	}
 }

+ 4 - 3
go.mod

@@ -2,7 +2,10 @@ module be-vpn
 
 go 1.19
 
-require github.com/gin-gonic/gin v1.9.1
+require (
+	github.com/gin-gonic/gin v1.9.1
+	github.com/tidwall/gjson v1.14.4
+)
 
 require (
 	github.com/bytedance/sonic v1.10.0-rc2 // indirect
@@ -23,8 +26,6 @@ require (
 	github.com/modern-go/reflect2 v1.0.2 // indirect
 	github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
 	github.com/pelletier/go-toml/v2 v2.0.9 // indirect
-	github.com/robfig/cron/v3 v3.0.1 // indirect
-	github.com/tidwall/gjson v1.14.4 // indirect
 	github.com/tidwall/match v1.1.1 // indirect
 	github.com/tidwall/pretty v1.2.0 // indirect
 	github.com/twitchyliquid64/golang-asm v0.15.1 // indirect

+ 0 - 2
go.sum

@@ -56,8 +56,6 @@ github.com/pelletier/go-toml/v2 v2.0.9 h1:uH2qQXheeefCCkuBBSLi7jCiSmj3VRh2+Goq2N
 github.com/pelletier/go-toml/v2 v2.0.9/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
 github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
 github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
-github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
-github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
 github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
 github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
 github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=