Go SDK

The official CredVault SDK for Go applications. Built with Go idioms in mind, this SDK provides efficient, type-safe access to the platform.

Why Use the Go SDK?

Go excels at building high-performance backend services, and the CredVault Go SDK is designed to match. The SDK uses minimal dependencies — just the standard library — keeping your builds fast and your binaries small.

Error handling follows Go conventions with explicit error returns. No hidden exceptions or panics. Every operation that might fail returns an error value for you to handle.

The SDK is safe for concurrent use. Share a single client across goroutines without additional synchronization.

System Requirements

The SDK requires Go 1.21 or later. It uses Go modules for dependency management, the standard approach for modern Go projects.

Installation

Fetch the SDK using Go's module system. The package will be added to your go.mod file automatically:

go get github.com/credvault/credvault-edge-go

Connecting to CredVault

Create a new client with your API key. The client struct contains resource fields for accessing different parts of the platform.

package main

import (
    "os"
    "github.com/credvault/credvault-edge-go/client"
)

func main() {
    apiKey := os.Getenv("CREDVAULT_API_KEY")
    vault := credvault.New(apiKey)
    
    // vault.Data...
}

For production applications, load your API key from an environment variable rather than hardcoding it. This keeps credentials secure and makes configuration flexible.

Working with Data

All data operations return two values: a result and an error. Always check the error before using the result — this is the Go way.

Listing clusters returns a slice of cluster information. Iterate over the results to find the cluster you need.

Querying collections fetches documents matching your criteria. Pass query parameters as a map and receive matching documents in response.

Inserting documents adds new records. Prepare your data as slice of maps and insert them in one call.

Updating and deleting follow similar patterns. Specify filters and receive confirmation of the operation's effect.

Error Handling

Every SDK method returns an error value. Always check errors before proceeding:

The error value contains details about what went wrong. For network errors, consider implementing retry logic with backoff. For authentication errors, check your credentials. For not-found errors, verify the resource exists.

Resources Available

The client provides access to all platform capabilities through typed structs:

  • Auth — User authentication
  • Data — Database operations
  • Cie — Intelligence Engine
  • Webhooks — Event notifications
  • Functions — Serverless execution
  • Triggers — Event automation
  • Backups — Data protection
  • Schema — Index management
  • ApiKeys — Key lifecycle
  • Metrics — Monitoring
  • Logs — Activity logs
  • Notifications — User notifications
  • Settings — Configuration

Each resource is accessed through the corresponding field on the client struct.

Concurrency

Go applications often run many operations concurrently. The CredVault client is safe for concurrent use — share a single client across goroutines.

For bulk operations, consider using goroutines with WaitGroups to parallelize work. The client handles connection pooling internally.

Context Support

For advanced use cases, operations support context for cancellation and timeouts. Pass a context to control request lifecycle and implement graceful shutdown.

Best Practices

Create one client, reuse it. The client maintains connection pools and authentication state. Creating new clients for every request wastes resources.

Always handle errors. Never discard error returns. Log them, report them to monitoring, and handle them appropriately.

Use environment variables for configuration. Keep API keys out of source code. Use os.Getenv or a configuration library.

Implement graceful shutdown. When your application terminates, give in-flight requests time to complete.

For implementation details and additional examples, refer to the SDK's README on GitHub or explore the source code.