Skip to main content

SDK Configuration

This page covers configuration options for Mesh SDK clients. All generated SDK clients follow the same patterns and provide consistent configuration options regardless of the specific service.

Client Configuration Patterns

All Mesh SDK clients are generated from the same template per language and provide consistent configuration options across Go, Python, Java, and TypeScript implementations. You can configure:

  • Connection settings - URL, port, TLS/SSL options
  • Authentication - API key, group ID, or environment-based credentials
  • Timeouts - Request and connection timeouts
client-config.go
package main

import (
"context"
"log"
"time"

api_userv1 "github.com/meshtrade/api/go/iam/api_user/v1"
)

func main() {
// Option 1: Zero configuration (auto-discovers credentials, connects to Mesh API)
client1, err := api_userv1.NewApiUserServiceGRPCClient()
if err != nil {
log.Fatalf("Failed to create client: %v", err)
}
defer client1.Close()

// Option 2: Direct API key and group configuration
client2, err := api_userv1.NewApiUserServiceGRPCClient(
api_userv1.WithAPIKey("your-api-key-here"),
api_userv1.WithGroup("groups/your-group-id"),
)
if err != nil {
log.Fatalf("Failed to create client: %v", err)
}
defer client2.Close()

// Option 3: Full custom configuration
client3, err := api_userv1.NewApiUserServiceGRPCClient(
api_userv1.WithAddress("custom-endpoint.example.com", 443),
api_userv1.WithTLS(true),
api_userv1.WithTimeout(30*time.Second),
api_userv1.WithAPIKey("your-api-key-here"),
api_userv1.WithGroup("groups/your-group-id"),
)
if err != nil {
log.Fatalf("Failed to create client: %v", err)
}
defer client3.Close()

// All clients have the same interface
ctx := context.Background()
response, err := client1.ListApiUsers(ctx, &api_userv1.ListApiUsersRequest{})
if err != nil {
log.Fatalf("Failed to list users: %v", err)
}
log.Printf("Found %d API users", len(response.ApiUsers))
}

Go Configuration Options:

OptionDefaultDescription
WithAddress(host, port)Mesh API endpoint, 443Custom host and port
WithTLS(enabled)trueEnable/disable TLS
WithAPIKey(key)Auto-discoveredAPI key for authentication
WithGroup(groupID)Auto-discoveredGroup context (groups/{id})
WithTimeout(duration)30sRequest timeout
WithTracer(tracer)NoneOpenTelemetry tracer

Authentication Methods

Automatic Credential Discovery (Go, Python, Java)

The Go, Python, and Java SDKs automatically discover credentials from the filesystem. Place your credentials.json in the platform-specific directory:

  • Linux: ~/.config/mesh/credentials.json
  • macOS: ~/Library/Application Support/mesh/credentials.json
  • Windows: C:\Users\<user>\AppData\Roaming\mesh\credentials.json

Or set the MESH_API_CREDENTIALS environment variable:

export MESH_API_CREDENTIALS=/path/to/your/credentials.json
credentials.json
{
"api_key": "your-api-key-here",
"group_id": "groups/your-group-id"
}

Direct Configuration

For programmatic control, set credentials directly in the client options:

  • API Key - Your authentication token
  • Group ID - The group context (format: groups/your-group-id)

Connection Management

All generated clients include proper connection management:

  • Go: Use defer client.Close() to ensure cleanup
  • Python: Use with client: context manager for automatic cleanup
  • Java: Use try-with-resources or explicit close
  • TypeScript: No explicit cleanup required

Error Handling

All clients follow consistent error handling patterns:

  • Go: Returns error as second value
  • Python: Raises exceptions
  • Java: Throws exceptions
  • TypeScript: Returns promises (use async/await with try/catch)

Advanced Features

OpenTelemetry Tracing (Go SDK)

The Go SDK supports distributed tracing:

import (
"go.opentelemetry.io/otel"
api_userv1 "github.com/meshtrade/api/go/iam/api_user/v1"
)

tracer := otel.Tracer("my-application")
client, err := api_userv1.NewApiUserServiceGRPCClient(
api_userv1.WithTracer(tracer),
)

Context Timeouts (Go SDK)

The Go SDK respects context deadlines, allowing per-request timeout control:

ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

response, err := client.GetApiUser(ctx, request)