gitlab.com/gitlab-org/gitaly/v14/client.
Installation
Import the client package in your Go code:Basic Connection
Dial Function
The simplest way to connect to Gitaly:DialContext
For connections with context support:Supported Address Formats
- Unix Socket:
unix:/path/to/socket - TCP (insecure):
tcp://hostname:port - TLS:
tls://hostname:port
Authentication
Add authentication tokens to your connections:Connection Pool
ThePool type manages connections efficiently, reusing them based on address and token:
Pool with Custom Options
Advanced Connection Options
Health Check Dialer
Wrap your dialer to perform health checks:Fail on Non-Temporary Errors
For checking if a listener is ready:Sidechannel Operations
Sidechannels provide high-performance data transfer for Git operations.Setting Up Sidechannel Registry
Dialing with Sidechannel Support
UploadPack (Git Fetch)
Standard streaming approach:UploadPack with Sidechannel
High-performance variant using sidechannels:ReceivePack (Git Push)
Proxy git-receive-pack sessions:Complete Example
Here’s a complete example showing connection pooling and repository operations:Connection Features
The Go client automatically configures:- Tracing: OpenTracing and correlation ID propagation
- Keepalives: TCP keepalive settings matching Gitaly’s expectations
- TLS: Automatic TLS handling based on URL scheme
- Interceptors: Request/response interceptors for observability
Best Practices
- Use Connection Pools: Reuse connections with
Poolinstead of creating new connections - Handle Contexts: Always pass context for timeout and cancellation support
- Use Sidechannels: For high-throughput operations like git fetch/push, use sidechannel variants
- Close Pools: Always defer
pool.Close()to clean up connections - Don’t Close Pool Connections: Connections from pools are managed - never call
Close()on them
API Reference
Key Types
Pool: Connection pool for managing reusable connectionsDialer: Function type for creating connectionsSidechannelRegistry: Registry for sidechannel callbacksSidechannelConn: Interface for reading/writing via sidechannel
Key Functions
Dial(address, opts): Create a new connectionDialContext(ctx, address, opts): Create connection with contextDialSidechannel(ctx, address, registry, opts): Create sidechannel connectionNewPool(opts): Create a connection poolHealthCheckDialer(dialer): Wrap dialer with health checksUploadPack: Proxy git-upload-packUploadPackWithSidechannel: High-performance git-upload-packReceivePack: Proxy git-receive-pack