Instantly share code, notes, and snippets.

@yukimochi /main.go
Last active Nov 7, 2018

Embed
What would you like to do?
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"`
}
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()
// 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
for _, limitDomain := range limitedDomains {
if limitDomain == domain {
limited = true
}
}
data = append(data, instance{
Domain: domain,
Limited: limited,
})
}
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