Skip to content

Commit 7d1f28a

Browse files
committed
feat: simplify filter logic and enforce > 7% load
1 parent 68e3760 commit 7d1f28a

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

web/service/nord.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,28 @@ func (s *NordService) GetServers(countryId string) (string, error) {
3838
if err != nil {
3939
return "", err
4040
}
41-
return string(body), nil
41+
var data map[string]any
42+
if err := json.Unmarshal(body, &data); err != nil {
43+
return string(body), nil
44+
}
45+
46+
servers, ok := data["servers"].([]any)
47+
if !ok {
48+
return string(body), nil
49+
}
50+
51+
var filtered []any
52+
for _, s := range servers {
53+
if server, ok := s.(map[string]any); ok {
54+
if load, ok := server["load"].(float64); ok && load > 7 {
55+
filtered = append(filtered, s)
56+
}
57+
}
58+
}
59+
data["servers"] = filtered
60+
61+
result, _ := json.Marshal(data)
62+
return string(result), nil
4263
}
4364

4465
func (s *NordService) SetKey(privateKey string) (string, error) {

0 commit comments

Comments
 (0)