partial docs update.

This commit is contained in:
fiatjaf
2025-04-21 12:12:11 -03:00
parent 59bddab471
commit aaf0740513
9 changed files with 65 additions and 81 deletions
+1 -2
View File
@@ -39,7 +39,7 @@ func startPollingGame(relay *khatru.Relay) {
Content: "team A has scored!",
Tags: nostr.Tags{{"t", "this-game"}}
}
evt.Sign(global.RelayPrivateKey)
evt.Sign(global.RelaySecretKey)
// calling BroadcastEvent will send the event to everybody who has been listening for tag "t=[this-game]"
// there is no need to do any code to keep track of these clients or who is listening to what, khatru
// does that already in the background automatically
@@ -61,4 +61,3 @@ func startPollingGame(relay *khatru.Relay) {
func fetchGameStatus() (GameStatus, error) {
// implementation of calling some external API goes here
}
```
+7 -11
View File
@@ -21,23 +21,19 @@ func main () {
// other stuff here
}
func handleWeatherQuery(ctx context.Context, filter nostr.Filter) (ch chan *nostr.Event, err error) {
if filter.Kind != 10774 {
func handleWeatherQuery(ctx context.Context, filter nostr.Filter) iter.Seq[nostr.Event] {
if filter.Kind != nostr.Kind(10774) {
// this function only handles kind 10774, if the query is for something else we return
// a nil channel, which corresponds to no results
return nil, nil
return nil
}
file, err := os.Open("weatherdata.xml")
if err != nil {
return nil, fmt.Errorf("we have lost our file: %w", err)
return nil
}
// QueryEvents functions are expected to return a channel
ch := make(chan *nostr.Event)
// and they can do their query asynchronously, emitting events to the channel as they come
go func () {
return func(yield func(nostr.Event) bool) {
defer file.Close()
// we're going to do this for each tag in the filter
@@ -74,14 +70,14 @@ func handleWeatherQuery(ctx context.Context, filter nostr.Filter) (ch chan *nost
{"condition", record[3]},
}
}
evt.Sign(global.RelayPrivateKey)
evt.Sign(global.RelaySecretKey)
ch <- evt
}
}
}
}()
return ch, nil
}
}
```
+2 -2
View File
@@ -4,7 +4,7 @@ outline: deep
# Implementing NIP-50 `search` support
The [`nostr.Filter` type](https://pkg.go.dev/github.com/nbd-wtf/go-nostr#Filter) has a `Search` field, so you basically just has to handle that if it's present.
The [`nostr.Filter` type](https://pkg.go.dev/fiatjaf.com/nostr#Filter) has a `Search` field, so you basically just has to handle that if it's present.
It can be tricky to implement fulltext search properly though, so some [eventstores](../core/eventstore) implement it natively, such as [Bluge](https://pkg.go.dev/fiatjaf.com/nostr/eventstore/bluge), [OpenSearch](https://pkg.go.dev/fiatjaf.com/nostr/eventstore/opensearch) and [ElasticSearch](https://pkg.go.dev/fiatjaf.com/nostr/eventstore/elasticsearch) (although for the last two you'll need an instance of these database servers running, while with Bluge it's embedded).
@@ -39,7 +39,7 @@ Other adapters, like [SQLite](https://pkg.go.dev/fiatjaf.com/nostr/eventstore/sq
```go
relay.StoreEvent = append(relay.StoreEvent, db.SaveEvent, search.SaveEvent)
relay.QueryEvents = append(relay.QueryEvents, func (ctx context.Context, filter nostr.Filter) (chan *nostr.Event, error) {
relay.QueryStored = func (ctx context.Context, filter nostr.Filter) iter.Seq[nostr.Event] {
if len(filter.Search) > 0 {
return search.QueryEvents(ctx, filter)
} else {