mirror of
https://github.com/fiatjaf/nak.git
synced 2025-12-23 06:58:51 +00:00
only build with lmdb on linux.
This commit is contained in:
43
lmdb.go
Normal file
43
lmdb.go
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
//go:build linux && !riscv64 && !arm64
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
|
"fiatjaf.com/nostr/eventstore/lmdb"
|
||||||
|
"fiatjaf.com/nostr/eventstore/nullstore"
|
||||||
|
"fiatjaf.com/nostr/sdk"
|
||||||
|
"fiatjaf.com/nostr/sdk/hints/lmdbh"
|
||||||
|
lmdbkv "fiatjaf.com/nostr/sdk/kvstore/lmdb"
|
||||||
|
"github.com/urfave/cli/v3"
|
||||||
|
)
|
||||||
|
|
||||||
|
func setupLocalDatabases(c *cli.Command, sys *sdk.System) {
|
||||||
|
configPath := c.String("config-path")
|
||||||
|
if configPath != "" {
|
||||||
|
hintsPath := filepath.Join(configPath, "outbox/hints")
|
||||||
|
os.MkdirAll(hintsPath, 0755)
|
||||||
|
_, err := lmdbh.NewLMDBHints(hintsPath)
|
||||||
|
if err != nil {
|
||||||
|
log("failed to create lmdb hints db at '%s': %s\n", hintsPath, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
eventsPath := filepath.Join(configPath, "events")
|
||||||
|
os.MkdirAll(eventsPath, 0755)
|
||||||
|
sys.Store = &lmdb.LMDBBackend{Path: eventsPath}
|
||||||
|
if err := sys.Store.Init(); err != nil {
|
||||||
|
log("failed to create boltdb events db at '%s': %s\n", eventsPath, err)
|
||||||
|
sys.Store = &nullstore.NullStore{}
|
||||||
|
}
|
||||||
|
|
||||||
|
kvPath := filepath.Join(configPath, "kvstore")
|
||||||
|
os.MkdirAll(kvPath, 0755)
|
||||||
|
if kv, err := lmdbkv.NewStore(kvPath); err != nil {
|
||||||
|
log("failed to create boltdb kvstore db at '%s': %s\n", kvPath, err)
|
||||||
|
} else {
|
||||||
|
sys.KVStore = kv
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
30
main.go
30
main.go
@@ -8,11 +8,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"fiatjaf.com/nostr"
|
"fiatjaf.com/nostr"
|
||||||
"fiatjaf.com/nostr/eventstore/lmdb"
|
|
||||||
"fiatjaf.com/nostr/eventstore/nullstore"
|
|
||||||
"fiatjaf.com/nostr/sdk"
|
"fiatjaf.com/nostr/sdk"
|
||||||
"fiatjaf.com/nostr/sdk/hints/lmdbh"
|
|
||||||
lmdbkv "fiatjaf.com/nostr/sdk/kvstore/lmdb"
|
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
"github.com/urfave/cli/v3"
|
"github.com/urfave/cli/v3"
|
||||||
)
|
)
|
||||||
@@ -103,31 +99,7 @@ var app = &cli.Command{
|
|||||||
Before: func(ctx context.Context, c *cli.Command) (context.Context, error) {
|
Before: func(ctx context.Context, c *cli.Command) (context.Context, error) {
|
||||||
sys = sdk.NewSystem()
|
sys = sdk.NewSystem()
|
||||||
|
|
||||||
configPath := c.String("config-path")
|
setupLocalDatabases(c, sys)
|
||||||
if configPath != "" {
|
|
||||||
hintsPath := filepath.Join(configPath, "outbox/hints")
|
|
||||||
os.MkdirAll(hintsPath, 0755)
|
|
||||||
_, err := lmdbh.NewLMDBHints(hintsPath)
|
|
||||||
if err != nil {
|
|
||||||
log("failed to create lmdb hints db at '%s': %s\n", hintsPath, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
eventsPath := filepath.Join(configPath, "events")
|
|
||||||
os.MkdirAll(eventsPath, 0755)
|
|
||||||
sys.Store = &lmdb.LMDBBackend{Path: eventsPath}
|
|
||||||
if err := sys.Store.Init(); err != nil {
|
|
||||||
log("failed to create boltdb events db at '%s': %s\n", eventsPath, err)
|
|
||||||
sys.Store = &nullstore.NullStore{}
|
|
||||||
}
|
|
||||||
|
|
||||||
kvPath := filepath.Join(configPath, "kvstore")
|
|
||||||
os.MkdirAll(kvPath, 0755)
|
|
||||||
if kv, err := lmdbkv.NewStore(kvPath); err != nil {
|
|
||||||
log("failed to create boltdb kvstore db at '%s': %s\n", kvPath, err)
|
|
||||||
} else {
|
|
||||||
sys.KVStore = kv
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sys.Pool = nostr.NewPool(nostr.PoolOptions{
|
sys.Pool = nostr.NewPool(nostr.PoolOptions{
|
||||||
AuthorKindQueryMiddleware: sys.TrackQueryAttempts,
|
AuthorKindQueryMiddleware: sys.TrackQueryAttempts,
|
||||||
|
|||||||
11
non_lmdb.go
Normal file
11
non_lmdb.go
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
//go:build !linux || riscv64 || arm64
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fiatjaf.com/nostr/sdk"
|
||||||
|
"github.com/urfave/cli/v3"
|
||||||
|
)
|
||||||
|
|
||||||
|
func setupLocalDatabases(c *cli.Command, sys *sdk.System) {
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user