Variablize redis dbs

This commit is contained in:
Amarpreet Minhas 2023-02-04 00:32:25 -05:00
parent c7257e6885
commit 7ad1325c7a
2 changed files with 9 additions and 3 deletions

View file

@ -26,6 +26,7 @@ func AddNostrAddr(n NostrRequest) {
relays := make(map[string][]string) relays := make(map[string][]string)
user := nostrWellKnown{} user := nostrWellKnown{}
names := map[string]string{n.Name: n.Key} names := map[string]string{n.Name: n.Key}
if n.Relays != nil { if n.Relays != nil {
relays = map[string][]string{n.Key: n.Relays} relays = map[string][]string{n.Key: n.Relays}
user = nostrWellKnown{Names: names, Relays: relays} user = nostrWellKnown{Names: names, Relays: relays}
@ -34,12 +35,12 @@ func AddNostrAddr(n NostrRequest) {
} }
jsonUser, _ := json.Marshal(user) jsonUser, _ := json.Marshal(user)
r, err := redis.New("localhost:6379", "", 0) r, err := redis.New("localhost:6379", "", redis.NostrDb)
if err != nil { if err != nil {
fmt.Println("FAILED") fmt.Println("FAILED")
} }
nameKey := fmt.Sprintf("%s@%s", n.Name, n.Hostname) 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 { if err != nil {
fmt.Println("FAILED") fmt.Println("FAILED")
} }
@ -53,7 +54,7 @@ func GetNostrAddr(w http.ResponseWriter, req *http.Request) {
req.ParseForm() req.ParseForm()
// connect to redis // connect to redis
r, err := redis.New("localhost:6379", "", 0) r, err := redis.New("localhost:6379", "", redis.NostrDb)
if err != nil { if err != nil {
w.WriteHeader(http.StatusNotFound) w.WriteHeader(http.StatusNotFound)
return return

View file

@ -2,6 +2,11 @@ package redis
import "github.com/go-redis/redis" import "github.com/go-redis/redis"
const (
NostrDb = iota
LndDb = iota
)
type Redis struct { type Redis struct {
Client *redis.Client Client *redis.Client
} }