Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,14 @@ let timeout = try await config.fetchInt(forKey: "http.timeout", default: 30)

// Fetch with context for environment-specific configuration
let dbConnectionString = try await config.fetchRequiredString(
forKey: "database.url",
context: [
"environment": "production",
"region": "us-west-2",
"service": "user-service"
],
forKey: ConfigKey(
"database.url",
context: [
"environment": "production",
"region": "us-west-2",
"service": "user-service"
]
),
isSecret: true
)
```
Expand Down Expand Up @@ -145,15 +147,19 @@ let context: [String: ConfigContextValue] = [

// Get environment-specific database configuration
let dbConfig = try await config.fetchRequiredString(
forKey: "database.connection_string",
context: context,
forKey: ConfigKey(
"database.connection_string",
context: context,
)
isSecret: true
)

// Watch for region-specific timeout adjustments
try await config.watchInt(
forKey: "api.timeout",
context: ["region": "us-west-2"],
forKey: ConfigKey(
"api.timeout",
context: ["region": "us-west-2"]
),
default: 5000
) { updates in
for await timeout in updates {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,21 +208,27 @@ All variants support the same additional features:
```swift
// Optional with context
let timeout = config.int(
forKey: "service.timeout",
context: ["environment": "production", "region": "us-east-1"]
forKey: ConfigKey(
"service.timeout",
context: ["environment": "production", "region": "us-east-1"]
)
)

// Default with context
let timeout = config.int(
forKey: "service.timeout",
context: ["environment": "production"],
forKey: ConfigKey(
"service.timeout",
context: ["environment": "production"]
),
default: 30
)

// Required with context
let timeout = try config.requiredInt(
forKey: "service.timeout",
context: ["environment": "production"]
forKey: ConfigKey(
"service.timeout",
context: ["environment": "production"]
)
)
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,16 @@ With a provider configured this way, a config reader will return the following r
let config = ConfigReader(provider: provider)
config.double(forKey: "http.client.timeout") // nil
config.double(
forKey: "http.client.timeout",
context: ["upstream": "example1.org"]
forKey: ConfigKey(
"http.client.timeout",
context: ["upstream": "example1.org"]
)
) // 15.0
config.double(
forKey: "http.client.timeout",
context: ["upstream": "example2.org"]
forKey: ConfigKey(
"http.client.timeout",
context: ["upstream": "example2.org"]
)
) // 30.0
```

Expand Down
Loading