removed global variables

This commit is contained in:
pippellia-btc
2025-06-06 10:18:11 +02:00
parent 54db3ef429
commit e213cfd4c4

View File

@@ -19,9 +19,6 @@ import (
"github.com/redis/go-redis/v9" "github.com/redis/go-redis/v9"
) )
var events chan *nostr.Event
var pubkeys chan string
func main() { func main() {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
@@ -32,8 +29,8 @@ func main() {
panic(err) panic(err)
} }
events = make(chan *nostr.Event, config.EventsCapacity) events := make(chan *nostr.Event, config.EventsCapacity)
pubkeys = make(chan string, config.PubkeysCapacity) pubkeys := make(chan string, config.PubkeysCapacity)
db := redb.New(&redis.Options{Addr: config.RedisAddress}) db := redb.New(&redis.Options{Addr: config.RedisAddress})
count, err := db.NodeCount(ctx) count, err := db.NodeCount(ctx)
@@ -89,7 +86,6 @@ func main() {
pipe.Processor(ctx, config.Processor, db, events) pipe.Processor(ctx, config.Processor, db, events)
}() }()
go printStats(ctx)
wg.Wait() wg.Wait()
} }
@@ -103,7 +99,7 @@ func handleSignals(cancel context.CancelFunc) {
cancel() cancel()
} }
// enqueue things into channels // enqueue things into the specified channel or log if full
func enqueue[T any](queue chan T) func(t T) error { func enqueue[T any](queue chan T) func(t T) error {
return func(t T) error { return func(t T) error {
select { select {
@@ -115,7 +111,7 @@ func enqueue[T any](queue chan T) func(t T) error {
} }
} }
func printStats(ctx context.Context) { func printStats(ctx context.Context, events chan *nostr.Event, pubkeys chan string) {
filename := "stats.log" filename := "stats.log"
file, err := os.OpenFile(filename, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644) file, err := os.OpenFile(filename, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)
if err != nil { if err != nil {