Store json the lazy way...

This commit is contained in:
Amarpreet Minhas 2023-04-29 15:25:28 -04:00
parent 4747b15d62
commit 5c35f2daac

View file

@ -2,6 +2,7 @@ package nostr
import (
"context"
b64 "encoding/base64"
"encoding/json"
"errors"
"fmt"
@ -12,7 +13,6 @@ import (
"git.minhas.io/asara/well-goknown/lnd"
"git.minhas.io/asara/well-goknown/logger"
"git.minhas.io/asara/well-goknown/redis"
"github.com/davecgh/go-spew/spew"
"github.com/nbd-wtf/go-nostr/nip19"
)
@ -72,6 +72,7 @@ func RequestNostrAddr(w http.ResponseWriter, r *http.Request) {
user = nostrWellKnown{Names: names}
}
jsonUser, _ := json.Marshal(user)
enc := b64.StdEncoding.EncodeToString([]byte(jsonUser))
// generate the payment request
exp := time.Until(time.Now().Add(time.Minute * 15))
@ -81,11 +82,10 @@ func RequestNostrAddr(w http.ResponseWriter, r *http.Request) {
return
}
requestKey := getRkey("requested", r.FormValue("Name"), getHostname(r.Host))
err = redisCli.Client.Set(ctx, requestKey, jsonUser, exp).Err()
err = redisCli.Client.Set(ctx, requestKey, enc, exp).Err()
if err != nil {
l.Error().Msg("unable to connect to redis")
}
spew.Dump(paymentReq)
}
}
@ -111,10 +111,15 @@ func GetNostrAddr(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNotFound)
return
}
dec, err := b64.StdEncoding.DecodeString(addr)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(addr)
w.Write(dec)
}
func AddNostrAddr(n NostrRequest) {
@ -142,7 +147,8 @@ func AddNostrAddr(n NostrRequest) {
l.Error().Msg("unable to connect to redis")
}
nameKey := getRkey("verified", n.Name, n.Hostname)
err = redisCli.Client.Set(ctx, nameKey, jsonUser, 0).Err()
enc := b64.StdEncoding.EncodeToString([]byte(jsonUser))
err = redisCli.Client.Set(ctx, nameKey, enc, 0).Err()
if err != nil {
l.Error().Msg("unable to connect to redis")
}