Ben hai 1 ano
pai
achega
1d63742f05
Modificáronse 1 ficheiros con 26 adicións e 13 borrados
  1. 26 13
      cmd/slave.go

+ 26 - 13
cmd/slave.go

@@ -4,6 +4,7 @@ import (
 	"be-vpn/internal/dto"
 	"bytes"
 	"encoding/json"
+	"github.com/gin-gonic/gin"
 	"github.com/tidwall/gjson"
 	"io"
 	"log"
@@ -41,19 +42,31 @@ func main() {
 		log.Printf("err: %+v", err)
 	}
 
-	for true {
-		// send request
-		reader := bytes.NewBuffer(body)
-		resp, err := http.Post("http://v.starttransfernow.com/register", "application/json", reader)
-		if err != nil {
-			log.Printf("err: %+v", err)
-			continue
+	go func() {
+		for true {
+			// send request
+			reader := bytes.NewBuffer(body)
+			resp, err := http.Post("http://v.starttransfernow.com/register", "application/json", reader)
+			if err != nil {
+				log.Printf("err: %+v", err)
+				continue
+			}
+			respBody, err := io.ReadAll(resp.Body)
+			if err != nil {
+				log.Printf("err: %+v", err)
+			}
+			log.Printf("resp: %s", string(respBody))
+			time.Sleep(3 * time.Second)
 		}
-		respBody, err := io.ReadAll(resp.Body)
-		if err != nil {
-			log.Printf("err: %+v", err)
-		}
-		log.Printf("resp: %s", string(respBody))
-		time.Sleep(1 * time.Second)
+	}()
+
+	r := gin.Default()
+	r.Use(gin.Recovery())
+	r.GET("/health", func(c *gin.Context) {
+		c.JSON(200, gin.H{"status": "1"})
+	})
+
+	if err := r.Run(":80"); err != nil {
+		log.Fatalf("err: %+v", err)
 	}
 }