Configuration

Overview

GoCamel supports multiple configuration strategies for credentials, endpoints, and component settings.

Credential Sources

gocamel.GetConfigValue(url, key) is the single entry point that every component uses to resolve a configuration value. It checks four sources in the following order — the first non-empty result wins:

  1. Exact-name environment variable. The key is used verbatim. Example: GetConfigValue(_, "OPENAI_API_KEY") reads os.Getenv("OPENAI_API_KEY").
  2. Scheme-prefixed environment variable. Built by uppercasing scheme + "_" + key. For an ftp:// URI and key password, the lookup is os.Getenv("FTP_PASSWORD").
  3. URI query parameter. Example: ftp://host?password=secret.
  4. URI userinfo, for the well-known keys username/user and password/pass only. Example: ftp://user:pass@host.

Set sensitive data via environment variables:

export FTP_USERNAME="myuser"
export FTP_PASSWORD="secret"
export TELEGRAM_AUTHORIZATIONTOKEN="bot-token"
export OPENAI_API_KEY="api-key"

Routes then reference the option directly — the env var is picked up automatically:

builder.From("ftp://host?username=myuser")  // FTP_PASSWORD comes from env

Query Parameters

Pass options as URI query parameters:

builder.From("ftp://host?username=admin&password=secret")
Credentials in URI queries are flagged at runtime

URI strings routinely leak into connection-error logs, audit trails, crash reports and proxy access logs. When GetConfigValue resolves a credential-like key (password, pass, secret, token, apikey, api_key, accesskey, access_key, clientsecret, privatekey) from a query parameter, it emits a WARN log recommending env vars. The warning carries only the scheme and the key name — never the value — and is deduped per (scheme, key) pairing so a polling consumer cannot flood the logs.

Use environment variables in production. The userinfo form (user:pass@host) is treated as the conventional URI way of carrying credentials and is not warned about — you opted into it explicitly.

Direct in URI (userinfo form)

builder.From("ftp://user:pass@host:21/path")

Context Configuration

ctx := gocamel.NewCamelContext()

// Custom configuration
cfg := ctx.Config()

Security

Never hardcode credentials:

// ❌ BAD
endpoint := "ftp://user:secret@host"

// ✅ GOOD
endpoint := "ftp://host?username=${env:FTP_USER}"

Proxy

os.Setenv("HTTP_PROXY", "http://proxy.company:8080")
os.Setenv("HTTPS_PROXY", "http://proxy.company:8080")
os.Setenv("NO_PROXY", "localhost,127.0.0.1")

Component Registration

Standard Components

ctx.AddComponent("ftp", gocamel.NewFTPComponent())
ctx.AddComponent("http", gocamel.NewHTTPComponent())
ctx.AddComponent("timer", gocamel.NewTimerComponent())
ctx.AddComponent("direct", gocamel.NewDirectComponent())

Scheduled Components

ctx.AddComponent("cron", gocamel.NewCronComponent())

Messaging Components

ctx.AddComponent("telegram", gocamel.NewTelegramComponent())

AI Components

ctx.AddComponent("openai", gocamel.NewOpenAIComponent())

Database Components

import "database/sql"
import _ "github.com/mattn/go-sqlite3"

db, _ := sql.Open("sqlite3", "./app.db")

sqlComp := gocamel.NewSQLComponent()
sqlComp.RegisterDataSource("appdb", db)
ctx.AddComponent("sql", sqlComp)

Data Source Configuration

SQL Component

// Multiple datasources
sqlComp.RegisterDataSource("primary", db1)
sqlComp.RegisterDataSource("secondary", db2)

// Default datasource
sqlComp.SetDefaultDataSource(db)

SQL-Stored Component

sqlStored := gocamel.NewSQLStoredComponent()
sqlStored.RegisterDataSource("mydb", db)
ctx.AddComponent("sql-stored", sqlStored)

Route Configuration

Setting Route ID

route := context.CreateRouteBuilder().
    From("timer:tick").
    SetID("timer-route-1").
    To("direct:output").
    Build()

Common Options

// Polling delay
builder.From("file://input?delay=10s&delete=true")

// HTTP method
builder.To("http://api?httpMethod=POST")

Environment Variable Mapping

ComponentVariableDescription
FTPFTP_USERNAME, FTP_PASSWORDFTP credentials
SFTPSFTP_USERNAME, SFTP_PASSWORD, SFTP_PRIVATE_KEY_FILESSH credentials
TelegramTELEGRAM_AUTHORIZATIONTOKENBot token
OpenAIOPENAI_AUTHORIZATIONTOKEN, OPENAI_API_KEYAPI keys
MailMAIL_USERNAME, MAIL_PASSWORDEmail credentials

Best Practices

  1. Never commit secrets — Use env vars or secret managers
  2. Use different configs per environment — Dev/staging/prod
  3. Document required env vars — In README or deployment docs
  4. Validate config at startup — Fail fast on missing config