-
-
Save mashirozx/6e0c0a9315c4b473668c86938013182c to your computer and use it in GitHub Desktop.
Check All subscriber in Activity-Relay
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"encoding/json" | |
"fmt" | |
"os" | |
"strings" | |
"time" | |
"github.com/go-redis/redis" | |
) | |
type instance struct { | |
Domain string `json:"domain"` | |
Limited bool `json:"limited"` | |
Failed bool `json:"failed"` | |
} | |
type exData struct { | |
Instances []instance `json:"instances"` | |
LastUpdated int64 `json:"last_updated"` | |
} | |
func main() { | |
execDate := time.Now().Unix() | |
subscription := redis.NewClient(&redis.Options{ | |
Addr: os.Getenv("REDIS_URL"), | |
}) | |
limitedDomains, _ := subscription.HKeys("relay:config:limitedDomain").Result() | |
failedDomains, _ := subscription.Keys("relay:statistics:*").Result() | |
// Check all subscriptor. | |
var data []instance | |
insts, _ := subscription.Keys("relay:subscription:*").Result() | |
for _, inst := range insts { | |
domain := strings.Replace(inst, "relay:subscription:", "", 1) | |
limited := false | |
failed := false | |
for _, limitDomain := range limitedDomains { | |
if limitDomain == domain { | |
limited = true | |
} | |
} | |
for _, failedtDomain := range failedDomains { | |
if failedtDomain == "relay:statistics:"+domain { | |
failed = true | |
} | |
} | |
data = append(data, instance{ | |
Domain: domain, | |
Limited: limited, | |
Failed: failed, | |
}) | |
} | |
var ex = exData{} | |
ex.Instances = data | |
ex.LastUpdated = execDate | |
js, err := json.Marshal(&ex) | |
if err != nil { | |
panic(err) | |
} | |
fmt.Println(string(js)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment