well-goknown/main.go

54 lines
1.5 KiB
Go

package main
import (
"net/http"
"git.devvul.com/asara/gologger"
"git.devvul.com/asara/well-goknown/alby"
"git.devvul.com/asara/well-goknown/config"
"git.devvul.com/asara/well-goknown/db"
"git.devvul.com/asara/well-goknown/matrix"
"git.devvul.com/asara/well-goknown/nostr"
"github.com/fiatjaf/eventstore/postgresql"
)
var (
version string
)
func main() {
l := gologger.Get(config.GetConfig().LogLevel).With().Caller().Logger()
l.Debug().Msgf("starting well-goknown v%s", version)
db, _ := db.NewDB()
defer db.Close()
nostr.DB = db
nostr.RelayDb = postgresql.PostgresBackend{DatabaseURL: config.GetConfig().DbUrl}
if err := nostr.RelayDb.Init(); err != nil {
l.Panic().Msgf("unable to connect to relay db: %s", err.Error())
}
relay := nostr.NewRelay(version)
alby.DB = db
// matrix endpoints
l.Debug().Msg("enabling matrix well-known endpoints")
http.HandleFunc("/.well-known/matrix/server", matrix.MatrixServer)
http.HandleFunc("/.well-known/matrix/client", matrix.MatrixClient)
// nostr endpoints
l.Debug().Msg("enabling nostr well-known endpoints")
http.HandleFunc("/.well-known/nostr.json", nostr.GetNostrAddr)
http.Handle("/relay", relay)
// lnurlp endpoint
l.Debug().Msg("enabling lnurlp well-known endpoint")
http.HandleFunc("/.well-known/lnurlp/{name}", alby.GetLnurlp)
http.HandleFunc("/.well-known/lnurlp/{name}/callback", alby.GetLnurlpCallback)
// start server
port := config.GetConfig().ListenAddr
l.Info().Msgf("starting server on %s", port)
http.ListenAndServe(port, nil)
}