Skip to content

Commit

Permalink
Merge pull request #97 from fiatjaf/eventstore
Browse files Browse the repository at this point in the history
remove storage plugins and move those to eventstore module
  • Loading branch information
fiatjaf committed Nov 1, 2023
2 parents 54369b8 + 3c044da commit e5fb4bb
Show file tree
Hide file tree
Showing 32 changed files with 174 additions and 2,265 deletions.
4 changes: 2 additions & 2 deletions add-event.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"regexp"

"github.com/fiatjaf/relayer/v2/storage"
"github.com/fiatjaf/eventstore"
"github.com/nbd-wtf/go-nostr"
)

Expand Down Expand Up @@ -33,7 +33,7 @@ func AddEvent(ctx context.Context, relay Relay, evt *nostr.Event) (accepted bool

if saveErr := store.SaveEvent(ctx, evt); saveErr != nil {
switch saveErr {
case storage.ErrDupEvent:
case eventstore.ErrDupEvent:
return true, saveErr.Error()
default:
errmsg := saveErr.Error()
Expand Down
5 changes: 3 additions & 2 deletions examples/basic/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import (
"log"
"time"

"github.com/fiatjaf/eventstore"
"github.com/fiatjaf/eventstore/postgresql"
"github.com/fiatjaf/relayer/v2"
"github.com/fiatjaf/relayer/v2/storage/postgresql"
"github.com/kelseyhightower/envconfig"
"github.com/nbd-wtf/go-nostr"
)
Expand All @@ -23,7 +24,7 @@ func (r *Relay) Name() string {
return "BasicRelay"
}

func (r *Relay) Storage(ctx context.Context) relayer.Storage {
func (r *Relay) Storage(ctx context.Context) eventstore.Store {
return r.storage
}

Expand Down
5 changes: 3 additions & 2 deletions examples/expensive/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import (
"net/http"
"time"

"github.com/fiatjaf/eventstore"
"github.com/fiatjaf/eventstore/postgresql"
"github.com/fiatjaf/relayer/v2"
"github.com/fiatjaf/relayer/v2/storage/postgresql"
"github.com/kelseyhightower/envconfig"
_ "github.com/lib/pq"
"github.com/nbd-wtf/go-nostr"
Expand All @@ -30,7 +31,7 @@ func (r *Relay) Name() string {
return "ExpensiveRelay"
}

func (r *Relay) Storage(ctx context.Context) relayer.Storage {
func (r *Relay) Storage(ctx context.Context) eventstore.Store {
return r.storage
}

Expand Down
7 changes: 4 additions & 3 deletions examples/rss-bridge/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"time"

"github.com/cockroachdb/pebble"
"github.com/fiatjaf/eventstore"
"github.com/fiatjaf/relayer/v2"
"github.com/kelseyhightower/envconfig"
"github.com/nbd-wtf/go-nostr"
Expand Down Expand Up @@ -90,7 +91,7 @@ func (relay *Relay) AcceptEvent(ctx context.Context, _ *nostr.Event) bool {
return false
}

func (relay *Relay) Storage(ctx context.Context) relayer.Storage {
func (relay *Relay) Storage(ctx context.Context) eventstore.Store {
return store{relay.db}
}

Expand All @@ -103,11 +104,11 @@ func (b store) SaveEvent(ctx context.Context, _ *nostr.Event) error {
return errors.New("blocked: we don't accept any events")
}

func (b store) DeleteEvent(ctx context.Context, id string, pubkey string) error {
func (b store) DeleteEvent(ctx context.Context, target *nostr.Event) error {
return errors.New("blocked: we can't delete any events")
}

func (b store) QueryEvents(ctx context.Context, filter *nostr.Filter) (chan *nostr.Event, error) {
func (b store) QueryEvents(ctx context.Context, filter nostr.Filter) (chan *nostr.Event, error) {
if filter.IDs != nil || len(filter.Tags) > 0 {
return nil, nil
}
Expand Down
3 changes: 1 addition & 2 deletions examples/search/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,4 @@ echo '["REQ", "asdf", {"search": "steve", "kinds": [0]}]' | websocat -n ws://127

Currently the indexing is very basic: It will index the `contents` field for all events where kind != 4.
Some additional mapping and pre-processing could add better support for different content types.
See comments in `storage/elasticsearch/elasticsearch.go`.

See comments in `github.com/fiatjaf/eventstore/elasticsearch/elasticsearch.go`.
6 changes: 3 additions & 3 deletions examples/search/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import (
"fmt"
"log"

"github.com/fiatjaf/eventstore"
"github.com/fiatjaf/eventstore/elasticsearch"
"github.com/fiatjaf/relayer/v2"
"github.com/fiatjaf/relayer/v2/storage/elasticsearch"
"github.com/kelseyhightower/envconfig"
"github.com/nbd-wtf/go-nostr"
)
Expand All @@ -19,7 +20,7 @@ func (r *Relay) Name() string {
return "SearchRelay"
}

func (r *Relay) Storage(ctx context.Context) relayer.Storage {
func (r *Relay) Storage(ctx context.Context) eventstore.Store {
return r.storage
}

Expand Down Expand Up @@ -47,7 +48,6 @@ func (r *Relay) BeforeSave(evt *nostr.Event) {
}

func (r *Relay) AfterSave(evt *nostr.Event) {

}

func main() {
Expand Down
5 changes: 3 additions & 2 deletions examples/whitelisted/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import (
"encoding/json"
"log"

"github.com/fiatjaf/eventstore"
"github.com/fiatjaf/eventstore/postgresql"
"github.com/fiatjaf/relayer/v2"
"github.com/fiatjaf/relayer/v2/storage/postgresql"
"github.com/kelseyhightower/envconfig"
"github.com/nbd-wtf/go-nostr"
)
Expand All @@ -22,7 +23,7 @@ func (r *Relay) Name() string {
return "WhitelistedRelay"
}

func (r *Relay) Storage(ctx context.Context) relayer.Storage {
func (r *Relay) Storage(ctx context.Context) eventstore.Store {
return r.storage
}

Expand Down
29 changes: 14 additions & 15 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,28 +1,22 @@
module github.com/fiatjaf/relayer/v2

go 1.21
go 1.21.0

require (
github.com/PuerkitoBio/goquery v1.8.0
github.com/aquasecurity/esquery v0.2.0
github.com/cockroachdb/pebble v0.0.0-20220723153705-3fc374e4dc66
github.com/elastic/go-elasticsearch/v8 v8.6.0
github.com/etcd-io/bbolt v1.3.3
github.com/fasthttp/websocket v1.5.3
github.com/go-sql-driver/mysql v1.5.0
github.com/fiatjaf/eventstore v0.0.1
github.com/gobwas/ws v1.2.0
github.com/grokify/html-strip-tags-go v0.0.1
github.com/jb55/lnsocket/go v0.0.0-20220725174341-b98b5cd37bb6
github.com/jmoiron/sqlx v1.3.1
github.com/kelseyhightower/envconfig v1.4.0
github.com/lib/pq v1.10.3
github.com/mattn/go-sqlite3 v1.14.6
github.com/lib/pq v1.10.9
github.com/mmcdole/gofeed v1.1.3
github.com/nbd-wtf/go-nostr v0.18.11
github.com/nbd-wtf/go-nostr v0.24.2
github.com/rif/cache2go v1.0.0
github.com/rs/cors v1.7.0
github.com/stevelacy/daz v0.1.4
github.com/stretchr/testify v1.8.0
github.com/tidwall/gjson v1.14.4
golang.org/x/exp v0.0.0-20230425010034-47ecfdc1ba53
golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba
Expand All @@ -34,6 +28,7 @@ require (
github.com/aead/siphash v1.0.1 // indirect
github.com/andybalholm/brotli v1.0.5 // indirect
github.com/andybalholm/cascadia v1.3.1 // indirect
github.com/aquasecurity/esquery v0.2.0 // indirect
github.com/btcsuite/btcd v0.23.1 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
github.com/btcsuite/btcd/btcutil v1.1.3 // indirect
Expand All @@ -48,7 +43,7 @@ require (
github.com/btcsuite/btcwallet/wtxmgr v1.5.0 // indirect
github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd // indirect
github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792 // indirect
github.com/cespare/xxhash/v2 v2.1.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cockroachdb/errors v1.8.1 // indirect
github.com/cockroachdb/logtags v0.0.0-20190617123548-eb05cc24525f // indirect
github.com/cockroachdb/redact v1.0.8 // indirect
Expand All @@ -57,15 +52,20 @@ require (
github.com/decred/dcrd/crypto/blake256 v1.0.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
github.com/decred/dcrd/lru v1.0.0 // indirect
github.com/elastic/elastic-transport-go/v8 v8.0.0-20211216131617-bbee439d559c // indirect
github.com/dgraph-io/ristretto v0.1.1 // indirect
github.com/dustin/go-humanize v1.0.0 // indirect
github.com/elastic/elastic-transport-go/v8 v8.3.0 // indirect
github.com/elastic/go-elasticsearch/v7 v7.6.0 // indirect
github.com/elastic/go-elasticsearch/v8 v8.10.1 // indirect
github.com/fatih/structs v1.1.0 // indirect
github.com/go-errors/errors v1.0.1 // indirect
github.com/gobwas/httphead v0.1.0 // indirect
github.com/gobwas/pool v0.2.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/glog v1.0.0 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/jmoiron/sqlx v1.3.5 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.11 // indirect
github.com/kkdai/bstream v1.0.0 // indirect
Expand All @@ -86,9 +86,9 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/puzpuzpuz/xsync v1.5.2 // indirect
github.com/puzpuzpuz/xsync/v2 v2.5.1 // indirect
github.com/savsgio/gotils v0.0.0-20230208104028-c358bd845dee // indirect
github.com/stretchr/objx v0.5.0 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
Expand All @@ -98,5 +98,4 @@ require (
golang.org/x/sys v0.8.0 // indirect
golang.org/x/term v0.6.0 // indirect
golang.org/x/text v0.8.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit e5fb4bb

Please sign in to comment.