mirror of
https://github.com/fiatjaf/khatru.git
synced 2025-03-18 13:53:03 +01:00
43 lines
1.1 KiB
Go
43 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"io"
|
|
"net/http"
|
|
"strings"
|
|
|
|
"github.com/fiatjaf/eventstore/badger"
|
|
"github.com/fiatjaf/khatru"
|
|
"github.com/fiatjaf/khatru/blossom"
|
|
)
|
|
|
|
func main() {
|
|
relay := khatru.NewRelay()
|
|
|
|
db := &badger.BadgerBackend{Path: "/tmp/khatru-badger-blossom-tmp"}
|
|
if err := db.Init(); err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
relay.StoreEvent = append(relay.StoreEvent, db.SaveEvent)
|
|
relay.QueryEvents = append(relay.QueryEvents, db.QueryEvents)
|
|
relay.CountEvents = append(relay.CountEvents, db.CountEvents)
|
|
relay.DeleteEvent = append(relay.DeleteEvent, db.DeleteEvent)
|
|
|
|
bl := blossom.New(relay, "http://localhost:3334")
|
|
bl.Store = blossom.EventStoreBlobIndexWrapper{Store: db, ServiceURL: bl.ServiceURL}
|
|
bl.StoreBlob = append(bl.StoreBlob, func(ctx context.Context, sha256 string, body []byte) error {
|
|
fmt.Println("storing", sha256, len(body))
|
|
return nil
|
|
})
|
|
bl.LoadBlob = append(bl.LoadBlob, func(ctx context.Context, sha256 string) (io.ReadSeeker, error) {
|
|
fmt.Println("loading", sha256)
|
|
blob := strings.NewReader("aaaaa")
|
|
return blob, nil
|
|
})
|
|
|
|
fmt.Println("running on :3334")
|
|
http.ListenAndServe(":3334", relay)
|
|
}
|