fix crash

This commit is contained in:
Pijus Kamandulis
2025-05-27 18:58:07 +03:00
parent dabfce5fcd
commit 0a53686351
3 changed files with 98 additions and 89 deletions
+15 -8
View File
@@ -8,13 +8,14 @@ import (
"log"
"net/http"
"os"
"os/signal"
"path/filepath"
"sort"
"strconv"
"strings"
"syscall"
"time"
"github.com/dgraph-io/badger/v3"
"github.com/ostafen/clover/v2"
"github.com/ostafen/clover/v2/document"
c "github.com/ostafen/clover/v2/query"
@@ -69,7 +70,7 @@ func (s *ShareLog) ParseCreateDate() (time.Time, error) {
}
func main() {
store, _ := badgerstore.Open(badger.DefaultOptions("badgerdb"))
store, _ := badgerstore.Open("badgerdb")
db, err := clover.OpenWithStore(store)
if err != nil {
log.Fatalf("Failed to open CloverDB: %v", err)
@@ -100,12 +101,18 @@ func main() {
go watchAndIngest(db)
handlers := Handlers{DB: db}
http.HandleFunc("/", handlers.indexHandler)
fmt.Println("Listening on :8080")
log.Fatal(http.ListenAndServe(":8080", nil))
go func() {
handlers := Handlers{DB: db}
http.HandleFunc("/", handlers.indexHandler)
fmt.Println("Listening on :8081")
log.Fatal(http.ListenAndServe(":8081", nil))
}()
select {} // Keep the program running
fmt.Println("Waitin for ctrl-c")
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
<-sigs
store.Close()
}
func printAllHashes(db *clover.DB) {
@@ -223,7 +230,7 @@ func getHighestShareInRange(db *clover.DB, collection string, since time.Time) (
// Query sorted by "sdiff" descending, limit 1
results, err := db.FindAll(c.NewQuery(collection).
Where(criteria).
Sort(c.SortOption{"SDiff", -1}).
Sort(c.SortOption{Field: "SDiff", Direction: -1}).
Limit(1))
if err != nil || len(results) == 0 {