SDK Configuration


Overview

The Togo MQ SDK supports flexible configuration with sensible defaults. You only need to provide your authentication token to get started, but you can customize various settings to suit your needs.

Default Configuration

The simplest way to create a client with default settings:

import "github.com/TogoMQ/togomq-sdk-go"

// Create client with defaults (only token is required)
config := togomq.NewConfig(
    togomq.WithToken("your-token-here"),
)

client, err := togomq.NewClient(config)
if err != nil {
    log.Fatal(err)
}
defer client.Close()

Default values:

  • Host: q.togomq.io
  • Port: 5123
  • LogLevel: info
  • Token: (required - no default)

Configuration Options

Option Default Value Description
Host q.togomq.io TogoMQ server hostname
Port 5123 TogoMQ server port
LogLevel info Logging level: debug, info, warn, error, none
Token (required) Authentication token from your dashboard

WithHost(host string)

Set a custom TogoMQ server hostname:

config := togomq.NewConfig(
    togomq.WithHost("custom.togomq.io"),
    togomq.WithToken("your-token"),
)

WithPort(port int)

Set a custom port number:

config := togomq.NewConfig(
    togomq.WithPort(9000),
    togomq.WithToken("your-token"),
)

WithLogLevel(level string)

Control logging verbosity:

config := togomq.NewConfig(
    togomq.WithLogLevel("debug"), // debug, info, warn, error, none
    togomq.WithToken("your-token"),
)

Log Levels:

  • debug - All logs including debug information (verbose)
  • info - Informational messages and above (default)
  • warn - Warnings and errors only
  • error - Error messages only
  • none - Disable all logging

WithToken(token string)

Set your authentication token (required):

config := togomq.NewConfig(
    togomq.WithToken("your-token-here"),
)

Custom Configuration

Combine multiple options for a fully customized setup:

config := togomq.NewConfig(
    togomq.WithHost("custom.togomq.io"),
    togomq.WithPort(9000),
    togomq.WithLogLevel("debug"),
    togomq.WithToken("your-token-here"),
)

client, err := togomq.NewClient(config)
if err != nil {
    log.Fatal(err)
}
defer client.Close()

Environment-Specific Configuration

Development Environment

For development, use verbose logging to help with debugging:

import "os"

config := togomq.NewConfig(
    togomq.WithToken(os.Getenv("TOGOMQ_DEV_TOKEN")),
    togomq.WithLogLevel("debug"), // Verbose logging
)

Production Environment

For production, minimize logging and use production tokens:

import "os"

config := togomq.NewConfig(
    togomq.WithToken(os.Getenv("TOGOMQ_PROD_TOKEN")),
    togomq.WithLogLevel("error"), // Only log errors
)

Testing Environment

For testing, you might want to use a different host or disable logging:

import "os"

config := togomq.NewConfig(
    togomq.WithHost("test.togomq.io"),
    togomq.WithToken(os.Getenv("TOGOMQ_TEST_TOKEN")),
    togomq.WithLogLevel("none"), // Disable logging in tests
)

Complete Example

Here's a complete example with environment-aware configuration:

package main

import (
    "log"
    "os"

    "github.com/TogoMQ/togomq-sdk-go"
)

func main() {
    // Get environment (dev, prod, test)
    env := os.Getenv("APP_ENV")
    if env == "" {
        env = "dev"
    }

    // Create configuration based on environment
    var config *togomq.Config

    switch env {
    case "prod":
        config = togomq.NewConfig(
            togomq.WithToken(os.Getenv("TOGOMQ_PROD_TOKEN")),
            togomq.WithLogLevel("error"),
        )
    case "test":
        config = togomq.NewConfig(
            togomq.WithToken(os.Getenv("TOGOMQ_TEST_TOKEN")),
            togomq.WithLogLevel("none"),
        )
    default: // dev
        config = togomq.NewConfig(
            togomq.WithToken(os.Getenv("TOGOMQ_DEV_TOKEN")),
            togomq.WithLogLevel("debug"),
        )
    }

    // Create client
    client, err := togomq.NewClient(config)
    if err != nil {
        log.Fatalf("Failed to create client: %v", err)
    }
    defer client.Close()

    log.Printf("Connected to TogoMQ in %s mode", env)

    // Your application logic here...
}

{success} Next: Learn how to install the SDK and start publishing messages.