This commit is contained in:
Amarpreet Minhas 2023-02-02 23:56:15 -05:00
parent e8771e7cd2
commit 2b7a06a0f4
6 changed files with 74 additions and 21 deletions

5
go.mod
View file

@ -2,7 +2,10 @@ module git.minhas.io/asara/well-goknown
go 1.19
require github.com/go-redis/redis v6.15.9+incompatible
require (
github.com/davecgh/go-spew v1.1.1
github.com/go-redis/redis v6.15.9+incompatible
)
require (
github.com/onsi/ginkgo v1.16.5 // indirect

1
go.sum
View file

@ -1,4 +1,5 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=

8
lnd/lnd.go Normal file
View file

@ -0,0 +1,8 @@
package lnd
import "fmt"
func main() {
// https://bitcoin.stackexchange.com/questions/73869/rpc-call-to-lnd
fmt.Println("vim-go")
}

14
main.go
View file

@ -8,7 +8,21 @@ import (
)
func main() {
/*
nostrTest := nostr.NostrRequest{
Name: "asara",
Key: "abcdefg",
Hostname: "devvul.com",
}
nostr.AddNostrAddr(nostrTest)
*/
// matrix endpoints
http.HandleFunc("/.well-known/matrix/server", matrix.Matrix)
// nostr endpoints
http.HandleFunc("/.well-known/nostr.json", nostr.GetNostrAddr)
http.HandleFunc("/request/nostr", nostr.RequestNostrAddr)
// start server
http.ListenAndServe(":8090", nil)
}

View file

@ -1,11 +1,12 @@
package nostr
import (
"encoding/json"
"fmt"
"net/http"
"strings"
"github.com/go-redis/redis"
"git.minhas.io/asara/well-goknown/redis"
)
type nostrWellKnown struct {
@ -17,46 +18,51 @@ type NostrRequest struct {
Name string `json:"name"`
Key string `json:"key"`
Hostname string
Relays []string `json:"relays"`
Relays []string `json:"relays,omitempty"`
}
/*
func AddNostrAddr(n NostrRequest) {
// transform request to well known struct
relays := make(map[string][]string)
user := nostrWellKnown{}
names := map[string]string{n.Name: n.Key}
relays := map[string][]string{n.Key: n.Relays}
user := nostrWellKnown{Names: names, Relays: relays}
if n.Relays != nil {
relays = map[string][]string{n.Key: n.Relays}
user = nostrWellKnown{Names: names, Relays: relays}
} else {
user = nostrWellKnown{Names: names}
}
jsonUser, _ := json.Marshal(user)
client := redis.NewClient(&redis.Options{
Addr: "localhost:6379",
Password: "",
DB: 0,
})
r, err := redis.New("localhost:6379", "", 0)
if err != nil {
fmt.Println("FAILED")
}
nameKey := fmt.Sprintf("%s@%s", n.Name, n.Hostname)
err := client.Set(nameKey, jsonUser, 0).Err()
err = r.Client.Set(nameKey, jsonUser, 0).Err()
if err != nil {
fmt.Println("FAILED")
}
}
*/
func RequestNostrAddr(w http.ResponseWriter, req *http.Request) {
}
func GetNostrAddr(w http.ResponseWriter, req *http.Request) {
// get query string for username
req.ParseForm()
// connect to redis
client := redis.NewClient(&redis.Options{
Addr: "localhost:6379",
Password: "",
DB: 0,
})
r, err := redis.New("localhost:6379", "", 0)
if err != nil {
w.WriteHeader(http.StatusNotFound)
return
}
requestedName := req.FormValue("name")
hostname := getHostname(req.Host)
// search for user@domain
search := fmt.Sprintf("%s@%s", requestedName, hostname)
addr, err := client.Get(search).Result()
search := fmt.Sprintf("%s@%s", requestedName, getHostname(req.Host))
addr, err := r.Client.Get(search).Result()
if err != nil {
w.WriteHeader(http.StatusNotFound)
return

21
redis/redis.go Normal file
View file

@ -0,0 +1,21 @@
package redis
import "github.com/go-redis/redis"
type Redis struct {
Client *redis.Client
}
func New(address string, password string, database int) (*Redis, error) {
client := redis.NewClient(&redis.Options{
Addr: address,
Password: password,
DB: database,
})
if err := client.Ping().Err(); err != nil {
return nil, err
}
return &Redis{
Client: client,
}, nil
}