First non-Rust client SDK for quicproquo ecosystem. - Cap'n Proto codegen: generated 6487-line Go types from node.capnp with all 24 RPC methods (NodeService, Auth, Envelope) - QUIC transport: quic-go + TLS 1.3, ALPN "capnp", single bidi stream, 300s idle timeout, InsecureSkipVerify for dev, custom CA cert support - High-level qpq package: Connect, Health, ResolveUser, CreateChannel, Send/SendWithTTL, Receive/ReceiveWait, DeleteAccount, OPAQUE wrappers - Auth management: session token storage, version/token/deviceID on all RPCs - Example program and README with API reference All tests pass: go test ./..., go vet, go build
56 lines
1.4 KiB
Go
56 lines
1.4 KiB
Go
// Command example demonstrates basic usage of the quicproquo Go SDK.
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
|
|
"quicproquo.dev/sdk/go/qpq"
|
|
)
|
|
|
|
func main() {
|
|
addr := "127.0.0.1:5001"
|
|
if len(os.Args) > 1 {
|
|
addr = os.Args[1]
|
|
}
|
|
|
|
ctx := context.Background()
|
|
|
|
client, err := qpq.Connect(ctx, qpq.Options{
|
|
Addr: addr,
|
|
InsecureSkipVerify: true,
|
|
})
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, "connect failed: %v\n", err)
|
|
os.Exit(1)
|
|
}
|
|
defer client.Close()
|
|
|
|
status, err := client.Health(ctx)
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, "health check failed: %v\n", err)
|
|
os.Exit(1)
|
|
}
|
|
fmt.Printf("Server health: %s\n", status)
|
|
|
|
fmt.Println("\nUsage:")
|
|
fmt.Println(" // Authenticate with a pre-existing session token")
|
|
fmt.Println(" client.SetSessionToken(token)")
|
|
fmt.Println()
|
|
fmt.Println(" // Resolve a user's identity key")
|
|
fmt.Println(" key, err := client.ResolveUser(ctx, \"alice\")")
|
|
fmt.Println()
|
|
fmt.Println(" // Create a DM channel")
|
|
fmt.Println(" chID, wasNew, err := client.CreateChannel(ctx, peerKey)")
|
|
fmt.Println()
|
|
fmt.Println(" // Send a message")
|
|
fmt.Println(" seq, err := client.Send(ctx, recipientKey, payload)")
|
|
fmt.Println()
|
|
fmt.Println(" // Receive messages")
|
|
fmt.Println(" msgs, err := client.Receive(ctx, recipientKey)")
|
|
fmt.Println()
|
|
fmt.Println(" // Long-poll for messages (5 second timeout)")
|
|
fmt.Println(" msgs, err := client.ReceiveWait(ctx, recipientKey, 5000)")
|
|
}
|