27 lines
728 B
Plaintext
27 lines
728 B
Plaintext
effect Config {
|
|
fn get(key: String): String
|
|
}
|
|
|
|
fn configure(): String with {Config, Console} = {
|
|
Console.print("Need config: api_url")
|
|
let url = Config.get("api_url")
|
|
Console.print("Got: " + url)
|
|
Console.print("Need config: timeout")
|
|
let timeout = Config.get("timeout")
|
|
Console.print("Got: " + timeout)
|
|
"Configured with url=" + url + ", timeout=" + timeout
|
|
}
|
|
|
|
handler envConfig: Config {
|
|
fn get(key) = if key == "api_url" then resume("https://api.example.com") else if key == "timeout" then resume("30") else resume("unknown")
|
|
}
|
|
|
|
fn main(): Unit with {Console} = {
|
|
let result = run configure() with {
|
|
Config = envConfig,
|
|
}
|
|
Console.print(result)
|
|
}
|
|
|
|
let output = run main() with {}
|