|
@@ -4,7 +4,11 @@ import (
|
|
"context"
|
|
"context"
|
|
"crypto/tls"
|
|
"crypto/tls"
|
|
"encoding/json"
|
|
"encoding/json"
|
|
|
|
+ "errors"
|
|
|
|
+ "fmt"
|
|
|
|
+ "io"
|
|
"net/http"
|
|
"net/http"
|
|
|
|
+ "strings"
|
|
)
|
|
)
|
|
|
|
|
|
var cacheCount InstallerCount
|
|
var cacheCount InstallerCount
|
|
@@ -51,3 +55,29 @@ func (s *SafelineService) GetInstallerCount(ctx context.Context) (InstallerCount
|
|
}
|
|
}
|
|
return cacheCount, nil
|
|
return cacheCount, nil
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+// GetExist return ip if id exist
|
|
|
|
+func (s *SafelineService) GetExist(ctx context.Context, id string, token string) (string, error) {
|
|
|
|
+ body := fmt.Sprintf(`{"id":"%s", "token": "%s"}`, id, token)
|
|
|
|
+ req, err := http.NewRequestWithContext(ctx, http.MethodPost, s.APIHost+"/api/v1/public/safeline/exist", strings.NewReader(body))
|
|
|
|
+ if err != nil {
|
|
|
|
+ return "", err
|
|
|
|
+ }
|
|
|
|
+ res, err := s.client.Do(req)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return "", err
|
|
|
|
+ }
|
|
|
|
+ defer res.Body.Close()
|
|
|
|
+ if res.StatusCode != http.StatusOK {
|
|
|
|
+ raw, _ := io.ReadAll(res.Body)
|
|
|
|
+ return "", errors.New(string(raw))
|
|
|
|
+ }
|
|
|
|
+ var r map[string]interface{}
|
|
|
|
+ if err := json.NewDecoder(res.Body).Decode(&r); err != nil {
|
|
|
|
+ return "", err
|
|
|
|
+ }
|
|
|
|
+ if r["code"].(float64) != 0 {
|
|
|
|
+ return "", nil
|
|
|
|
+ }
|
|
|
|
+ return r["data"].(map[string]interface{})["ip"].(string), nil
|
|
|
|
+}
|