Togo MQ uses token-based authentication to secure your messaging infrastructure. Each API token represents a secure credential that grants access to publish and subscribe to messages in your account.
First, you need to be logged in to your Togo MQ account:
{danger} Important! Your token will only be displayed once. Make sure to copy it immediately and store it securely.
After creating the token:
Visit your Dashboard to view all your active API tokens. You'll see:
If a token is compromised or no longer needed:
{warning} Revoked tokens cannot be restored. Any applications using a revoked token will immediately lose access. Make sure to update your applications with a new token before revoking the old one.
DO:
.env files (and add to .gitignore)DON'T:
In your .env file:
TOGOMQ_TOKEN=your-token-here
In your Go application:
import (
"os"
"github.com/TogoMQ/togomq-sdk-go"
)
func main() {
token := os.Getenv("TOGOMQ_TOKEN")
config := togomq.NewConfig(
togomq.WithToken(token),
)
client, err := togomq.NewClient(config)
// ... rest of your code
}
Once you have your API token, you can use it to authenticate with the Togo MQ SDK:
import "github.com/TogoMQ/togomq-sdk-go"
// Create configuration with your token
config := togomq.NewConfig(
togomq.WithToken("your-token-here"),
)
// Create client
client, err := togomq.NewClient(config)
if err != nil {
log.Fatal(err)
}
defer client.Close()
Development:
config := togomq.NewConfig(
togomq.WithToken(os.Getenv("TOGOMQ_DEV_TOKEN")),
togomq.WithLogLevel("debug"), // Enable debug logging
)
Production:
config := togomq.NewConfig(
togomq.WithToken(os.Getenv("TOGOMQ_PROD_TOKEN")),
togomq.WithLogLevel("error"), // Only log errors
)
{success} Next: Learn about SDK Configuration to customize your client settings.