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.
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:
q.togomq.io5123info| 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 |
Set a custom TogoMQ server hostname:
config := togomq.NewConfig(
togomq.WithHost("custom.togomq.io"),
togomq.WithToken("your-token"),
)
Set a custom port number:
config := togomq.NewConfig(
togomq.WithPort(9000),
togomq.WithToken("your-token"),
)
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 onlyerror - Error messages onlynone - Disable all loggingSet your authentication token (required):
config := togomq.NewConfig(
togomq.WithToken("your-token-here"),
)
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()
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
)
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
)
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
)
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.