Add nostr nip-05 registration with lnd invoices #1

Merged
Asara merged 33 commits from nostr_lnd into main 2023-05-30 00:10:37 +00:00
2 changed files with 34 additions and 7 deletions
Showing only changes of commit dd22f01dac - Show all commits

26
config/config.go Normal file
View file

@ -0,0 +1,26 @@
package config
import (
"os"
)
type (
Config struct {
MatrixIdentityServer string
MatrixWellKnownAddress string
}
)
func GetConfig() Config {
return Config{
MatrixIdentityServer: getEnv("MATRIX_IDENTITY_SERVER", ""),
MatrixWellKnownAddress: getEnv("MATRIX_WELL_KNOWN_ADDRESS", ""),
}
}
func getEnv(key, fallback string) string {
if value, ok := os.LookupEnv(key); ok {
return value
}
return fallback
}

View file

@ -4,7 +4,8 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"net/http" "net/http"
"os"
"git.minhas.io/asara/well-goknown/config"
) )
type matrixServerWellKnown struct { type matrixServerWellKnown struct {
@ -13,8 +14,8 @@ type matrixServerWellKnown struct {
func MatrixServer(w http.ResponseWriter, req *http.Request) { func MatrixServer(w http.ResponseWriter, req *http.Request) {
// uses an environment variable for now // uses an environment variable for now
wellKnownAddr, ok := os.LookupEnv("MATRIX_WELL_KNOWN_ADDRESS") wellKnownAddr := config.GetConfig().MatrixWellKnownAddress
if !ok { if wellKnownAddr == "" {
w.WriteHeader(http.StatusNotFound) w.WriteHeader(http.StatusNotFound)
return return
} }
@ -42,14 +43,14 @@ type matrixClientWellKnown struct {
func MatrixClient(w http.ResponseWriter, req *http.Request) { func MatrixClient(w http.ResponseWriter, req *http.Request) {
// uses an environment variable for now // uses an environment variable for now
wellKnownAddr, ok := os.LookupEnv("MATRIX_WELL_KNOWN_ADDRESS") wellKnownAddr := config.GetConfig().MatrixWellKnownAddress
if !ok { if wellKnownAddr == "" {
w.WriteHeader(http.StatusNotFound) w.WriteHeader(http.StatusNotFound)
return return
} }
identityServer, ok := os.LookupEnv("MATRIX_IDENTITY_SERVER") identityServer := config.GetConfig().MatrixIdentityServer
if !ok { if identityServer == "" {
w.Header().Set("Content-Type", "application/json") w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
baseUrl := &matrixClientWellKnown{ baseUrl := &matrixClientWellKnown{