@@ -3,7 +3,6 @@ package server
33import (
44 "encoding/json"
55 "net/http"
6- "strconv"
76 "time"
87
98 "github.com/codeshelldev/gotl/pkg/logger"
@@ -14,10 +13,10 @@ import (
1413)
1514
1615type RequestBody struct {
17- IP string `json:"ip,omitempty"`
18- Addr string `json:"addr,omitempty"`
19- Mac string `json:"mac,omitempty"`
20- StartupTime string `json:"startupTime,omitempty"`
16+ IP string `json:"ip,omitempty"`
17+ Addr string `json:"addr,omitempty"`
18+ Mac string `json:"mac,omitempty"`
19+ StartupTime * int `json:"startupTime,omitempty"`
2120}
2221
2322func httpHandler (w http.ResponseWriter , req * http.Request ) {
@@ -92,11 +91,9 @@ func httpHandler(w http.ResponseWriter, req *http.Request) {
9291 return
9392 }
9493
95- if body .StartupTime != "" {
96- startupTime , err := strconv .Atoi (body .StartupTime )
97-
94+ if body .StartupTime != nil {
9895 if err == nil {
99- time .Sleep (time .Duration (startupTime ) * time .Second )
96+ time .Sleep (time .Duration (* body . StartupTime ) * time .Second )
10097
10198 reachable , err = tryPing (client , body .Addr ,
10299 func () (bool , error ) {
@@ -142,7 +139,7 @@ func httpHandler(w http.ResponseWriter, req *http.Request) {
142139}
143140
144141func tryPingInterval (client * websocket.Conn , interval , retries int , addr string ) (bool , error ) {
145- ticker := time .NewTicker (time .Duration (config . ENV . PING_INTERVAL ) * time .Second )
142+ ticker := time .NewTicker (time .Duration (interval ) * time .Second )
146143 defer ticker .Stop ()
147144
148145 count := 0
@@ -164,7 +161,7 @@ func tryPingInterval(client *websocket.Conn, interval, retries int, addr string)
164161 return false , err
165162 }
166163
167- if count >= config . ENV . PING_RETRIES {
164+ if count >= retries {
168165 break
169166 }
170167 }
0 commit comments