Skip to content

khatru

khatru


mkdir hkatru
cd hkatru
go mod init example.com/m/v2
go get github.com/fiatjaf/khatru
go get github.com/fiatjaf/eventstore/sqlite3

// main.go
package main

import (
    "fmt"
    "net/http"

    "github.com/fiatjaf/eventstore/sqlite3"
    "github.com/fiatjaf/khatru"
)

func main() {
    relay := khatru.NewRelay()

    db := sqlite3.SQLite3Backend{DatabaseURL: "./nostr.sqlite"}
    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)

    fmt.Println("running on :3334")
    http.ListenAndServe(":3334", relay)
}