Exemplos de TOML

Exemplos de formato TOML (Tom's Obvious, Minimal Language) de estruturas simples a complexas

⚙️ Arquivo de Configuração Básico

🟢 simple

Exemplo simples de arquivo de configuração TOML

# Basic TOML Configuration File
# This is a comment

# String values
app_name = "MyWebApp"
version = "1.0.0"
environment = "production"

# Integer values
port = 3000
max_connections = 100
timeout = 30

# Boolean values
debug = false
enable_ssl = true
use_cache = true

# Float values
cpu_threshold = 0.8
memory_limit = 1024.5
retry_delay = 1.5

# Date and time values
created_at = 2024-01-15T10:30:00Z
last_updated = 2024-01-20 15:45:00+08:00

# Array of strings
allowed_origins = [
  "https://example.com",
  "https://app.example.com",
  "https://admin.example.com"
]

# Array of integers
error_codes = [400, 401, 403, 404, 500]

⚙️ Configuração de Banco de Dados

🟡 intermediate

Exemplo de configuração de conexão de banco de dados

# Database Configuration
[database]
# Primary database connection
type = "postgresql"
host = "localhost"
port = 5432
name = "myapp_production"
ssl_enabled = true
max_connections = 20

# Connection pool settings
[database.pool]
min_connections = 5
max_connections = 20
connection_timeout = 30
idle_timeout = 300
max_lifetime = 3600

# Database credentials
[database.credentials]
username = "db_user"
password = "secure_password_123"
use_ssl_cert = true

# SSL configuration
[database.ssl]
cert_file = "/etc/ssl/certs/db-client.crt"
key_file = "/etc/ssl/private/db-client.key"
ca_file = "/etc/ssl/certs/db-ca.crt"
verify_mode = "required"

# Replica database configuration
[database.replica]
enabled = true
host = "replica.example.com"
port = 5432
name = "myapp_replica"
read_only = true

[database.replica.credentials]
username = "replica_user"
password = "replica_password"

# Redis cache configuration
[database.redis]
enabled = true
host = "redis.example.com"
port = 6379
db_number = 0
password = "redis_password"

[database.redis.cluster]
enabled = false
nodes = ["redis1.example.com", "redis2.example.com", "redis3.example.com"]

# Database migration settings
[database.migrations]
auto_migrate = true
migration_path = "./migrations"
backup_before_migrate = true

⚙️ Configuração de Servidor Web

🟡 intermediate

Configuração de servidor de aplicação web

# Web Server Configuration
[server]
name = "Production Web Server"
environment = "production"
worker_processes = "auto"
user = "www-data"
group = "www-data"

# HTTP configuration
[server.http]
enabled = true
port = 80
bind_address = "0.0.0.0"
keepalive_timeout = 75
client_max_body_size = "10M"

# HTTPS configuration
[server.https]
enabled = true
port = 443
bind_address = "0.0.0.0"
force_redirect = true

[server.https.tls]
cert_file = "/etc/ssl/certs/server.crt"
key_file = "/etc/ssl/private/server.key"
protocols = ["TLSv1.2", "TLSv1.3"]
ciphers = [
  "ECDHE-RSA-AES256-GCM-SHA384",
  "ECDHE-RSA-AES128-GCM-SHA256",
  "ECDHE-RSA-AES256-SHA384"
]

# Logging configuration
[server.logging]
level = "info"
format = "combined"
access_log = "/var/log/nginx/access.log"
error_log = "/var/log/nginx/error.log"
log_rotation = true
max_log_size = "100M"

# Security headers
[server.security]
add_security_headers = true
frame_options = "DENY"
content_type_options = "nosniff"
strict_transport_security = "max-age=31536000; includeSubDomains"

# Rate limiting
[server.rate_limiting]
enabled = true
requests_per_minute = 100
burst_size = 20
whitelist = ["127.0.0.1", "::1"]

# Compression settings
[server.compression]
enabled = true
level = 6
min_length = 1000
types = [
  "text/html",
  "text/css",
  "text/javascript",
  "application/javascript",
  "application/json"
]

# Virtual hosts
[[server.virtual_hosts]]
domain = "example.com"
root = "/var/www/example.com"
index = ["index.html", "index.htm"]
ssl_enabled = true

[[server.virtual_hosts]]
domain = "api.example.com"
root = "/var/www/api.example.com"
proxy_pass = "http://localhost:3000"
ssl_enabled = true

# Load balancing
[server.load_balancer]
enabled = true
method = "round_robin"
health_check_interval = 30
health_check_path = "/health"

[[server.load_balancer.upstreams]]
address = "192.168.1.10:3000"
weight = 1
max_fails = 3

[[server.load_balancer.upstreams]]
address = "192.168.1.11:3000"
weight = 2
max_fails = 3

⚙️ Configurações do Usuário

🟡 intermediate

Configuração de configurações de usuário de aplicativo

# User Settings Configuration
# Generated on 2024-01-15T10:30:00Z

[user]
id = "user_123456789"
username = "john.doe"
email = "[email protected]"
display_name = "John Doe"
status = "active"
created_at = 2024-01-10T09:15:00Z
last_login = 2024-01-15T14:30:00Z

# Profile information
[user.profile]
first_name = "John"
last_name = "Doe"
date_of_birth = 1990-05-15
bio = "Software developer passionate about creating amazing applications."
avatar_url = "https://cdn.example.com/avatars/john-doe.jpg"
location = "San Francisco, CA"
website = "https://johndoe.dev"

# Contact information
[user.contact]
phone = "+1-555-0123"
secondary_email = "[email protected]"
linkedin = "https://linkedin.com/in/johndoe"
twitter = "@johndoe"
github = "johndoe"

# Preferences
[preferences]
theme = "dark"
language = "en"
timezone = "America/Los_Angeles"
date_format = "MM/DD/YYYY"
time_format = "24h"

# Notification settings
[preferences.notifications]
email_enabled = true
push_enabled = true
sms_enabled = false
digest_frequency = "daily"

[preferences.notifications.email]
marketing = false
security_alerts = true
product_updates = true
weekly_summary = true

[preferences.notifications.push]
friend_requests = true
messages = true
mentions = true
activity_updates = false

# Privacy settings
[preferences.privacy]
profile_visibility = "public"
show_email = false
show_phone = false
allow_friend_requests = true
search_indexing = false

[preferences.privacy.data_sharing]
analytics = true
improvement_program = true
third_party_sharing = false

# Security settings
[security]
two_factor_enabled = true
two_factor_method = "totp"
session_timeout = 3600
password_last_changed = 2023-12-01
failed_login_attempts = 0
account_locked = false

[security.sessions]
current_sessions = 3
max_concurrent_sessions = 5
remember_device = true
session_devices = [
  { name = "iPhone 13", last_used = 2024-01-15T12:00:00Z, ip_address = "192.168.1.100" },
  { name = "MacBook Pro", last_used = 2024-01-15T14:30:00Z, ip_address = "192.168.1.101" },
  { name = "Windows PC", last_used = 2024-01-14T20:15:00Z, ip_address = "192.168.1.102" }
]

# Subscription and billing
[subscription]
plan = "premium"
status = "active"
started_at = 2023-01-01
renews_at = 2024-01-01
cancel_at_period_end = false

[subscription.features]
storage_limit_gb = 100
api_calls_per_month = 100000
collaborators = 10
custom_domains = 5

# Usage statistics
[usage]
storage_used_gb = 23.5
api_calls_this_month = 45234
login_count_this_month = 45
last_activity = 2024-01-15T16:45:00Z

# Custom settings
[custom_settings]
dashboard_layout = "grid"
default_page_size = 25
auto_save_interval = 300
keyboard_shortcuts = true
beta_features = true

# Application-specific integrations
[integrations]
slack_enabled = true
slack_webhook_url = "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX"
github_connected = true
github_username = "johndoe"
google_connected = true
google_email = "[email protected]"

# API keys and tokens
[api_keys]
# Note: These are example tokens
public_key = "pk_live_1234567890abcdef"
webhook_secret = "whsec_abcdef1234567890"
rate_limit_key = "rl_key_johndoe_123456"

# Recent activity
[[recent_activity]]
type = "login"
timestamp = 2024-01-15T14:30:00Z
details = "Logged in from MacBook Pro"
ip_address = "192.168.1.101"

[[recent_activity]]
type = "file_upload"
timestamp = 2024-01-15T13:15:00Z
details = "Uploaded project-report.pdf (2.3MB)"
ip_address = "192.168.1.101"

[[recent_activity]]
type = "api_call"
timestamp = 2024-01-15T12:00:00Z
details = "Made 150 API calls"
ip_address = "192.168.1.100"

⚙️ Informações do Pacote

🔴 complex

Configuração de gerenciamento de pacotes tipo Cargo.toml

# Package.toml - Package Configuration

[package]
name = "awesome-web-framework"
version = "2.1.0"
description = "A modern, fast, and secure web framework for Node.js"
authors = ["John Smith <[email protected]>"]
maintainers = ["Jane Doe <[email protected]>"]
license = "MIT"
repository = "https://github.com/example/awesome-web-framework"
homepage = "https://example.com"
documentation = "https://docs.example.com"
keywords = ["web", "framework", "node", "express", "fast"]
categories = ["Web Framework", "HTTP Server", "API"]

[package.build]
target = "node"
compiler = "typescript"
min_node_version = "14.0.0"
optimization_level = 3

# Dependencies
[dependencies]
express = "^4.18.0"
helmet = "^7.0.0"
cors = "^2.8.5"
compression = "^1.7.4"
dotenv = "^16.0.0"

[dependencies.dev]
jest = "^29.0.0"
eslint = "^8.0.0"
prettier = "^3.0.0"
nodemon = "^3.0.0"
typescript = "^5.0.0"

# Build dependencies
[dependencies.build]
webpack = "^5.75.0"
babel-core = "^6.26.3"
babel-loader = "^8.0.0"

# Features
[features]
default = ["security", "performance"]
security = ["helmet", "cors", "rate-limiting"]
performance = ["compression", "caching"]
monitoring = ["metrics", "logging"]
database = ["mysql", "redis"]
websocket = ["socket.io"]

# Optional dependencies
[optional-dependencies]
mysql2 = "^3.0.0"
redis = "^4.0.0"
socket.io = "^4.5.0"
mongodb = "^5.0.0"

# Scripts
[scripts]
start = "node dist/index.js"
dev = "nodemon src/index.ts"
build = "tsc && webpack --mode production"
test = "jest"
test:watch = "jest --watch"
test:coverage = "jest --coverage"
lint = "eslint src/**/*.ts"
format = "prettier --write src/**/*.ts"
clean = "rm -rf dist node_modules"

# Development configuration
[development]
debug = true
hot_reload = true
source_maps = true
verbose_logging = true

# Production configuration
[production]
debug = false
optimization = true
minification = true
cache_headers = true
gzip_compression = true

# Testing configuration
[testing]
framework = "jest"
coverage_threshold = 80
test_timeout = 5000
parallel_tests = true

# Documentation
[documentation]
format = "javadoc"
source_link = "https://github.com/example/awesome-web-framework/blob/master/{file}#L{line}"
logo = "https://example.com/logo.png"
favicon = "https://example.com/favicon.ico"

# Release configuration
[release]
changelog_file = "CHANGELOG.md"
release_notes = "RELEASE_NOTES.md"
tag_format = "v{version}"
create_github_release = true

# Performance benchmarks
[benchmarks]
enable = true
framework_comparison = true
benchmark_tools = ["autocannon", "wrk"]

# Code quality
[code-quality]
tools = ["eslint", "prettier", "husky"]
pre_commit_hooks = ["lint", "format"]
pre_push_hooks = ["test"]

# Security
[security]
dependency_check = true
vulnerability_scanner = true
security_headers = true
encryption_at_rest = true

# Monitoring and metrics
[monitoring]
metrics_enabled = true
health_check_endpoint = "/health"
metrics_endpoint = "/metrics"
logging_level = "info"

# Internationalization
[internationalization]
default_locale = "en"
supported_locales = ["en", "es", "fr", "de", "zh", "ja"]
translation_files = "./locales"

⚙️ Configuração de Monitoramento

🔴 complex

Configuração de monitoramento de sistema e registro

# Monitoring and Observability Configuration
# System monitoring, logging, and alerting setup

[monitoring]
enabled = true
environment = "production"
service_name = "web-application"
version = "2.1.0"
data_retention_days = 30

# Metrics collection
[monitoring.metrics]
enabled = true
collection_interval = 15
export_format = "prometheus"
port = 9090

[monitoring.metrics.counters]
http_requests_total = true
request_duration_seconds = true
active_connections = true
error_rate = true
database_connections = true

[monitoring.metrics.gauges]
memory_usage_bytes = true
cpu_usage_percent = true
disk_usage_percent = true
queue_length = true
cache_hit_ratio = true

[monitoring.metrics.histograms]
request_duration_seconds = true
response_size_bytes = true
database_query_duration = true
file_upload_size = true

# Application logs
[monitoring.logging]
enabled = true
level = "info"
format = "json"
output = ["file", "stdout"]

[monitoring.logging.file]
path = "/var/log/application.log"
max_size = "100MB"
max_files = 10
compression = true

[monitoring.logging.console]
enabled = true
colors = false
timestamps = true

[monitoring.logging.structure]
include_trace_id = true
include_user_id = true
include_request_id = true
include_span_id = true

# Log levels per component
[monitoring.logging.levels]
app = "info"
database = "warn"
external_apis = "info"
auth = "info"
security = "warn"

# Health checks
[monitoring.health_checks]
enabled = true
port = 8080
endpoint = "/health"
check_interval = 30
timeout = 10

[[monitoring.health_checks.checks]]
name = "database"
type = "sql"
connection_string = "${DATABASE_URL}"
query = "SELECT 1"
timeout = 5

[[monitoring.health_checks.checks]]
name = "redis"
type = "tcp"
address = "redis.example.com:6379"
timeout = 3

[[monitoring.health_checks.checks]]
name = "external_api"
type = "http"
url = "https://api.example.com/ping"
timeout = 5
expected_status = 200

# Alerting configuration
[monitoring.alerts]
enabled = true
webhook_url = "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX"
notification_channels = ["slack", "email"]

[monitoring.alerts.email]
smtp_server = "smtp.example.com"
smtp_port = 587
username = "[email protected]"
password = "${SMTP_PASSWORD}"
from_address = "[email protected]"
to_addresses = ["[email protected]", "[email protected]"]

# Alert rules
[[monitoring.alerts.rules]]
name = "high_error_rate"
condition = "error_rate > 0.05"
duration = "5m"
severity = "critical"
description = "Error rate exceeded 5% for 5 minutes"

[[monitoring.alerts.rules]]
name = "high_memory_usage"
condition = "memory_usage_percent > 85"
duration = "10m"
severity = "warning"
description = "Memory usage exceeded 85% for 10 minutes"

[[monitoring.alerts.rules]]
name = "database_connection_failed"
condition = "database_health_check != 1"
duration = "1m"
severity = "critical"
description = "Database health check failed"

# Performance monitoring
[monitoring.performance]
enabled = true
profiling_enabled = false
sampling_rate = 0.1

[monitoring.performance.apm]
service_name = "web-application"
environment = "production"
sample_rate = 0.1
max_spans_per_second = 1000

# Trace configuration
[monitoring.tracing]
enabled = true
service_name = "web-application"
jaeger_endpoint = "http://jaeger.example.com:14268/api/traces"
sampling_rate = 0.1

[monitoring.tracing.spans]
http_request = true
database_query = true
external_api_call = true
cache_operation = true
custom_business_logic = true

# Error tracking
[monitoring.error_tracking]
enabled = true
service_name = "web-application"
environment = "production"
dsn = "https://user:[email protected]/project-id"

[monitoring.error_tracking.filters]
exclude_exceptions = ["HttpError", "ValidationError"]
exclude_paths = ["/health", "/metrics"]
include_stacktraces = true
include_user_context = true

# Distributed tracing
[monitoring.distributed_tracing]
enabled = true
propagation_format = "w3c"
service_graph = true

[monitoring.distributed_tracing.services]
web_app = { name = "web-application", version = "2.1.0" }
api_service = { name = "api-service", version = "1.5.2" }
database = { name = "postgresql", version = "15.0" }
cache = { name = "redis", version = "7.0" }

# Custom business metrics
[monitoring.custom_metrics]
user_registrations_total = true
order_processing_time_seconds = true
payment_success_rate = true
feature_usage_counter = true

# Dashboard configuration
[monitoring.dashboards]
enabled = true
refresh_interval = 30
auto_refresh = true

[[monitoring.dashboards.panels]]
title = "Request Rate"
metric = "http_requests_total"
type = "timeseries"
unit = "requests/second"

[[monitoring.dashboards.panels]]
title = "Error Rate"
metric = "error_rate"
type = "gauge"
unit = "percentage"

[[monitoring.dashboards.panels]]
title = "Response Time"
metric = "request_duration_seconds"
type = "histogram"
unit = "seconds"

# Resource limits and thresholds
[monitoring.thresholds]
cpu_warning = 70
cpu_critical = 90
memory_warning = 80
memory_critical = 95
disk_warning = 85
disk_critical = 95

[monitoring.thresholds.response_times]
slow_request_warning = 1000
slow_request_critical = 5000
database_query_warning = 500
database_query_critical = 2000

# Backup and retention
[monitoring.backup]
enabled = true
frequency = "daily"
retention_days = 90
compression = true
encryption = true

[monitoring.backup.destination]
type = "s3"
bucket = "monitoring-backups"
region = "us-west-2"
access_key = "${AWS_ACCESS_KEY}"
secret_key = "${AWS_SECRET_KEY}"