add modules

This commit is contained in:
Iru 2025-11-23 19:16:16 +01:00
commit 38e72e2a0c
2 changed files with 12 additions and 4 deletions

View file

@ -13,10 +13,11 @@ import (
) )
type Config struct { type Config struct {
Port int Port int
NSec string NSec string
NPub string SecretKey nostr.SecretKey
Relays []string NPub string
Relays []string
} }
func check(e error) { func check(e error) {
@ -71,6 +72,7 @@ func LoadConfig() *Config {
npub := nip19.EncodeNpub(pk) npub := nip19.EncodeNpub(pk)
log.Printf("Loading private key from file %s. Will send alerts from %s", nsecfile, npub) log.Printf("Loading private key from file %s. Will send alerts from %s", nsecfile, npub)
config.NSec = nsec config.NSec = nsec
config.SecretKey = sk
} else { } else {
sk := nostr.Generate() sk := nostr.Generate()
pk := nostr.GetPublicKey(sk) pk := nostr.GetPublicKey(sk)
@ -78,6 +80,7 @@ func LoadConfig() *Config {
npub := nip19.EncodeNpub(pk) npub := nip19.EncodeNpub(pk)
log.Printf("Using random private key. Will send alerts from %s", npub) log.Printf("Using random private key. Will send alerts from %s", npub)
config.NSec = nsec config.NSec = nsec
config.SecretKey = sk
} }
npub, ok := os.LookupEnv("NOSTR_NPUB") npub, ok := os.LookupEnv("NOSTR_NPUB")
@ -90,6 +93,8 @@ func LoadConfig() *Config {
relays, ok := os.LookupEnv("NOSTR_RELAYS") relays, ok := os.LookupEnv("NOSTR_RELAYS")
if ok { if ok {
config.Relays = strings.Split(relays, ",") config.Relays = strings.Split(relays, ",")
} else {
config.Relays = strings.Split(relayargs, ",")
} }
return &config return &config
} }

View file

@ -8,6 +8,9 @@ import (
func main() { func main() {
cfg := LoadConfig() cfg := LoadConfig()
for _, relay := range cfg.Relays {
log.Printf(relay)
}
http.HandleFunc("/", alertReceiver) http.HandleFunc("/", alertReceiver)
log.Printf("Server starting on http://localhost:%d", cfg.Port) log.Printf("Server starting on http://localhost:%d", cfg.Port)
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", cfg.Port), nil)) log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", cfg.Port), nil))