Docs / Contact / sdks/go/configuration

Go SDK: Configuration

The Go SDK loads configuration from three sources, in priority order:

  1. API key parameter passed to the constructor
  2. Environment variable TENDRL_KEY
  3. Configuration file (~/.tendrl/config.json or /etc/tendrl/config.json)

Configuration File

Create ~/.tendrl/config.json or /etc/tendrl/config.json:

json

{
    "managed": true,
    "timeout_seconds": 10,
    "max_retries": 3,
    "debug": false,
    "min_batch_size": 10,
    "max_batch_size": 500,
    "max_queue_size": 1000,
    "target_cpu_percent": 70.0,
    "target_mem_percent": 80.0,
    "min_batch_interval_ms": 100,
    "max_batch_interval_ms": 1000,
    "offline_storage": true,
    "storage_path": "tendrl_storage.db",
    "offline_retry_enabled": true,
    "offline_retry_interval_seconds": 30,
    "offline_retry_limit": 5,
    "connectivity_check_enabled": true,
    "connectivity_check_interval_seconds": 30,
    "send_heartbeat": true,
    "heartbeat_interval_seconds": 30
}

You can also generate an example config file:

go

tendrl.GenerateExampleConfig("/path/to/config.json")

All Configuration Options

Core

JSON Key Type Default Description
managed bool true Managed mode (background processing) or headless (direct calls)
timeout_seconds int 10 HTTP request timeout in seconds
max_retries int 3 Maximum retry attempts for failed requests
debug bool false Enable detailed debug logging

Batching & Performance

JSON Key Type Default Description
min_batch_size int 10 Minimum messages per batch
max_batch_size int 500 Maximum messages per batch
max_queue_size int 1000 Maximum queued messages
min_batch_interval_ms int 100 Minimum ms between batch sends
max_batch_interval_ms int 1000 Maximum ms before forced send
target_cpu_percent float 70.0 Target CPU % for dynamic batch sizing
target_mem_percent float 80.0 Target memory % for dynamic batch sizing

The SDK calculates batch size dynamically: batchSize = MaxBatchSize × (cpuFactor×0.4 + memFactor×0.4 + queueFactor×0.2), clamped between min and max.

Offline Storage

JSON Key Type Default Description
offline_storage bool true (managed) Enable BoltDB message persistence
storage_path string "tendrl_storage.db" Path to BoltDB file
offline_retry_enabled bool true Automatically retry stored messages
offline_retry_interval_seconds int 30 Seconds between retry checks
offline_retry_limit int 5 Maximum retry attempts per message

Messages are stored with a 1-hour TTL. Expired messages are automatically cleaned up.

Connectivity

JSON Key Type Default Description
connectivity_check_enabled bool true Enable network monitoring
connectivity_check_interval_seconds int 30 Seconds between connectivity checks

Heartbeat

JSON Key Type Default Description
send_heartbeat bool true (managed) Send periodic heartbeats
heartbeat_interval_seconds int 30 Seconds between heartbeats

Heartbeats report memory (free/total) and disk (free/total) metrics.

Environment Variables

Variable Purpose
TENDRL_KEY API key (used when no key is passed to constructor)

Constructor Variants

go

// Managed mode with explicit API key
client, err := tendrl.NewClient(true, "your_key")

// Managed mode with TENDRL_KEY env var
client, err := tendrl.NewClientWithMode(true)

// Custom config file path
client, err := tendrl.NewClientWithConfig("/etc/myapp/tendrl.json")

// Config file + explicit API key
client, err := tendrl.NewClientWithConfigAndAPIKey("/etc/myapp/tendrl.json", "your_key")

Example Configurations

Edge Gateway (High Throughput)

json

{
    "managed": true,
    "max_batch_size": 1000,
    "max_queue_size": 5000,
    "target_cpu_percent": 85.0,
    "offline_storage": true,
    "storage_path": "/var/lib/myapp/tendrl.db",
    "heartbeat_interval_seconds": 60
}

Lightweight Sensor Device

json

{
    "managed": true,
    "max_batch_size": 50,
    "max_queue_size": 200,
    "target_cpu_percent": 50.0,
    "target_mem_percent": 60.0,
    "offline_storage": true,
    "heartbeat_interval_seconds": 120
}