Dir Golang SDK provides a simple way to interact with the Directory API. It allows developers to integrate and use Directory functionality from their applications with ease.
The Directory SDK provides comprehensive access to all Directory APIs with a simple, intuitive interface:
- Record Management: Push records to the store and pull them by reference
- Metadata Operations: Look up record metadata without downloading full content
- Data Lifecycle: Delete records permanently from the store
- Referrer Support: Push and pull artifacts for existing records
- Sync Management: Manage storage synchronization policies between Directory servers
- Flexible Search: Search stored records using text, semantic, and structured queries
- Advanced Filtering: Filter results by metadata, content type, and other criteria
- Network Publishing: Publish records to make them discoverable across the network
- Content Discovery: List and query published records across the network
- Network Management: Unpublish records to remove them from network discovery
- Local Signing: Sign records locally using private keys or OIDC-based authentication.
- Remote Verification: Verify record signatures using the Directory gRPC API
- Async Support: Non-blocking operations with streaming responses for large datasets
- Error Handling: Comprehensive gRPC error handling with detailed error messages
- Configuration: Flexible configuration via environment variables or direct instantiation
- Initialize the project:
go mod init example.com/myapp- Add the SDK to your project:
go get github.com/agntcy/dir/clientThe SDK can be configured via environment variables or direct instantiation.
| Variable | Description | Default |
|---|---|---|
DIRECTORY_CLIENT_SERVER_ADDRESS |
Directory server address | 0.0.0.0:8888 |
DIRECTORY_CLIENT_AUTH_MODE |
Authentication mode: x509, jwt, or empty for insecure |
"" (insecure) |
DIRECTORY_CLIENT_SPIFFE_SOCKET_PATH |
SPIFFE Workload API socket path | "" |
DIRECTORY_CLIENT_JWT_AUDIENCE |
JWT audience for JWT authentication | "" |
The SDK supports three authentication modes:
For local development only. Not recommended for production.
Environment Variables:
export DIRECTORY_CLIENT_SERVER_ADDRESS="localhost:8888"
# AUTH_MODE is empty or not setCode Example:
import (
"context"
"github.com/agntcy/dir/client"
)
ctx := context.Background()
config := &client.Config{
ServerAddress: "localhost:8888",
// AuthMode is empty - insecure connection
}
c, err := client.New(ctx, client.WithConfig(config))
if err != nil {
// handle error
}
defer c.Close() // Always close to cleanup resourcesRecommended for production. Requires SPIRE agent.
Environment Variables:
export DIRECTORY_CLIENT_SERVER_ADDRESS="localhost:8888"
export DIRECTORY_CLIENT_AUTH_MODE="x509"
export DIRECTORY_CLIENT_SPIFFE_SOCKET_PATH="unix:///run/spire/agent-sockets/api.sock"Code Example:
import (
"context"
"github.com/agntcy/dir/client"
)
ctx := context.Background()
config := &client.Config{
ServerAddress: "localhost:8888",
AuthMode: "x509",
SpiffeSocketPath: "unix:///run/spire/agent-sockets/api.sock",
}
c, err := client.New(ctx, client.WithConfig(config))
if err != nil {
// handle error
}
defer c.Close() // Always close to cleanup resourcesAlternative to X.509 for client authentication. Requires SPIRE agent.
Note: In JWT mode, the server presents its X.509-SVID via TLS for server authentication and encryption, while the client authenticates using a JWT-SVID. This provides both transport security and client authentication, following the official SPIFFE JWT pattern.
Environment Variables:
export DIRECTORY_CLIENT_SERVER_ADDRESS="localhost:8888"
export DIRECTORY_CLIENT_AUTH_MODE="jwt"
export DIRECTORY_CLIENT_SPIFFE_SOCKET_PATH="unix:///run/spire/agent-sockets/api.sock"
export DIRECTORY_CLIENT_JWT_AUDIENCE="spiffe://example.org/dir-server"Code Example:
import (
"context"
"github.com/agntcy/dir/client"
)
ctx := context.Background()
config := &client.Config{
ServerAddress: "localhost:8888",
AuthMode: "jwt",
SpiffeSocketPath: "unix:///run/spire/agent-sockets/api.sock",
JWTAudience: "spiffe://example.org/dir-server",
}
c, err := client.New(ctx, client.WithConfig(config))
if err != nil {
// handle error
}
defer c.Close() // Always close to cleanup resources- Golang - Go programming language
Option A: Local Development Server
# Clone the repository and start the server using Taskfile
task server:startOption B: Custom Server
# Set your Directory server address
export DIRECTORY_CLIENT_SERVER_ADDRESS="your-server:8888"# Add the Directory SDK
go get github.com/agntcy/dir/client