Skip to content

Instantly share code, notes, and snippets.

@mashirozx
Forked from yukimochi/main.go
Created July 13, 2020 22:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mashirozx/6e0c0a9315c4b473668c86938013182c to your computer and use it in GitHub Desktop.
Save mashirozx/6e0c0a9315c4b473668c86938013182c to your computer and use it in GitHub Desktop.
Check All subscriber in Activity-Relay
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