package main import ( "context" "fmt" "log" "net/http" "strings" "time" "github.com/nbd-wtf/go-nostr" "github.com/nbd-wtf/go-nostr/nip19" ) // --- Your FetchNotesHTML() from earlier --- func FetchNotesHTML(relayURL, npub string) (string, error) { ctx := context.Background() relay, err := nostr.RelayConnect(ctx, relayURL) if err != nil { return "", fmt.Errorf("relay connection failed: %w", err) } defer relay.Close() var filters nostr.Filters if _, v, err := nip19.Decode(npub); err == nil { pub := v.(string) filters = []nostr.Filter{{ Kinds: []int{nostr.KindTextNote}, Authors: []string{pub}, Limit: 3, }} } else { return "", fmt.Errorf("npub decode failed: %w", err) } ctx, cancel := context.WithTimeout(ctx, 5*time.Second) defer cancel() sub, err := relay.Subscribe(ctx, filters) if err != nil { return "", fmt.Errorf("subscribe failed: %w", err) } var builder strings.Builder for ev := range sub.Events { id, _ := nip19.EncodeNote(ev.ID) pub, _ := nip19.EncodePublicKey(ev.PubKey) t := time.Unix(int64(ev.CreatedAt), 0).UTC() rfc3339 := t.Format(time.RFC3339) content := ev.Content builder.WriteString("
  • ") builder.WriteString("
    ") builder.WriteString(fmt.Sprintf("

    ID: %s

    ", id)) builder.WriteString(fmt.Sprintf("

    Author: %s

    ", pub)) builder.WriteString(fmt.Sprintf("

    Created: %s

    ", rfc3339)) builder.WriteString(fmt.Sprintf("

    Content: %s

    ", content)) builder.WriteString("
    ") builder.WriteString("
  • ") builder.WriteString("
    ") } return builder.String(), nil } // --- Your static HTML template with a placeholder --- const htmlTemplate = ` despera.space

    IDs

    Long Form Notes

    Other Stuff

    Posts

    ` // --- HTTP Handler --- func handler(w http.ResponseWriter, r *http.Request) { relayURL := "wss://relay.despera.space" npub := "npub1nmk2399jazpsup0vsm6dzxw7gydzm5atedj4yhdkn3yx7jh7tzpq842975" notesHTML, err := FetchNotesHTML(relayURL, npub) if err != nil { http.Error(w, fmt.Sprintf("failed to fetch notes: %v", err), http.StatusInternalServerError) return } page := strings.Replace(htmlTemplate, "{{POSTS}}", notesHTML, 1) w.Header().Set("Content-Type", "text/html; charset=utf-8") fmt.Fprint(w, page) } // --- Main --- func main() { http.HandleFunc("/", handler) fmt.Println("Serving on http://localhost:8080...") log.Fatal(http.ListenAndServe(":8080", nil)) }