Variablize redis dbs
This commit is contained in:
parent
c7257e6885
commit
7ad1325c7a
2 changed files with 9 additions and 3 deletions
|
@ -26,6 +26,7 @@ func AddNostrAddr(n NostrRequest) {
|
|||
relays := make(map[string][]string)
|
||||
user := nostrWellKnown{}
|
||||
names := map[string]string{n.Name: n.Key}
|
||||
|
||||
if n.Relays != nil {
|
||||
relays = map[string][]string{n.Key: n.Relays}
|
||||
user = nostrWellKnown{Names: names, Relays: relays}
|
||||
|
@ -34,12 +35,12 @@ func AddNostrAddr(n NostrRequest) {
|
|||
}
|
||||
jsonUser, _ := json.Marshal(user)
|
||||
|
||||
r, err := redis.New("localhost:6379", "", 0)
|
||||
r, err := redis.New("localhost:6379", "", redis.NostrDb)
|
||||
if err != nil {
|
||||
fmt.Println("FAILED")
|
||||
}
|
||||
nameKey := fmt.Sprintf("%s@%s", n.Name, n.Hostname)
|
||||
err = r.Client.Set(nameKey, jsonUser, 0).Err()
|
||||
err = r.Client.Set(nameKey, jsonUser, redis.NostrDb).Err()
|
||||
if err != nil {
|
||||
fmt.Println("FAILED")
|
||||
}
|
||||
|
@ -53,7 +54,7 @@ func GetNostrAddr(w http.ResponseWriter, req *http.Request) {
|
|||
req.ParseForm()
|
||||
|
||||
// connect to redis
|
||||
r, err := redis.New("localhost:6379", "", 0)
|
||||
r, err := redis.New("localhost:6379", "", redis.NostrDb)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
return
|
||||
|
|
|
@ -2,6 +2,11 @@ package redis
|
|||
|
||||
import "github.com/go-redis/redis"
|
||||
|
||||
const (
|
||||
NostrDb = iota
|
||||
LndDb = iota
|
||||
)
|
||||
|
||||
type Redis struct {
|
||||
Client *redis.Client
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue