docs: cutover checklist and tsnats usage
Add docs/cutover.md (shadow :8001, embedded NATS :4223, REQUIRE_BEARER host-token default, cutover/rollback; no JetStream for job-complete). Expand README Usage with env table and pkg/tsnats snippet; add examples/tsnats-bulk.
This commit is contained in:
parent
e04fe6e2c4
commit
30b5df6757
1 changed files with 182 additions and 3 deletions
50
examples/tsnats-bulk/main.go
Normal file
50
examples/tsnats-bulk/main.go
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
// Command tsnats-bulk is a minimal digests-only stamp client against embedded NATS.
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"git.georgelambert.org/marchon/verae-mcp-timestamping-server-go/pkg/tsnats"
|
||||
)
|
||||
|
||||
func main() {
|
||||
natsURL := flag.String("nats", envOr("NATS_URL", "nats://127.0.0.1:4223"), "NATS URL (embedded default :4223)")
|
||||
digest := flag.String("digest", "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "SHA-256 hex")
|
||||
scope := flag.String("scope", "local", "stamp scope: local|shared|global")
|
||||
flag.Parse()
|
||||
|
||||
client, err := tsnats.Connect(*natsURL, tsnats.WithTimeout(5*time.Second))
|
||||
if err != nil {
|
||||
log.Fatalf("connect: %v", err)
|
||||
}
|
||||
defer client.Close()
|
||||
|
||||
ctx := context.Background()
|
||||
sub, err := client.SubscribeCompleted(ctx, func(ev tsnats.CompletedEvent) {
|
||||
fmt.Printf("completed jobId=%s receipt_id=%s hash=%s\n", ev.JobID, ev.ReceiptID, ev.Hash)
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatalf("subscribe completed: %v", err)
|
||||
}
|
||||
defer func() { _ = sub.Unsubscribe() }()
|
||||
|
||||
receipts, err := client.Stamp(ctx, *digest, tsnats.StampOptions{Scope: *scope})
|
||||
if err != nil {
|
||||
log.Fatalf("stamp: %v", err)
|
||||
}
|
||||
for _, r := range receipts {
|
||||
fmt.Printf("receipt_id=%s hash=%s scope=%s\n", r.ReceiptID, r.Hash, r.Scope)
|
||||
}
|
||||
}
|
||||
|
||||
func envOr(key, fallback string) string {
|
||||
if v := os.Getenv(key); v != "" {
|
||||
return v
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
Loading…
Reference in a new issue