Last active
June 21, 2024 20:05
-
-
Save bioball/8fcc848cffdf11fcbce68e420647aa1e to your computer and use it in GitHub Desktop.
Pkl multiple inheritance example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module com.example.AppConfig | |
// self import | |
import "AppConfig.pkl" | |
/// The profile to use. | |
local profile = read?("prop:profile") as ("dev"|"prod")? | |
/// The modifier to apply, if any. | |
local modifier = read?("prop:modifier") as ("canary"|"ci")? | |
local includes: Listing<AppConfig> = new { | |
import("baseConfig.pkl") | |
when (profile == "dev") { | |
import("profile-dev.pkl") | |
} | |
when (profile == "prod") { | |
import("profile-prod.pkl") | |
} | |
when (modifier == "ci") { | |
import("modifier-ci.pkl") | |
} | |
when (modifier == "canary") { | |
import("modifier-canary.pkl") | |
} | |
// Import ../dev/config.pkl if it exists. | |
when (read?("../dev/config.pkl") != null) { | |
import("../dev/config.pkl") | |
} | |
} | |
hidden config: Mixin<Config> | |
/// The actual configuration value | |
fixed value: Config = includes.fold(new Config {}, (result, cfg) -> cfg.appConfig.apply(result)) | |
/// The underlying configuration | |
class Config { | |
hosts: Listing<String> | |
port: UInt16 | |
ttl: Duration | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
amends "AppConfig.pkl" | |
config { | |
ttl = 3.h | |
port = 5122 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
amends "AppConfig.pkl" | |
config { | |
hosts { | |
"canary.example.com" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
amends "AppConfig.pkl" | |
config { | |
hosts { | |
"ci.example.com" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
amends "AppConfig.pkl" | |
config { | |
hosts { | |
"dev.example.com" | |
} | |
ttl = 5.min | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
amends "AppConfig.pkl" | |
config { | |
hosts { | |
"prod.example.com" | |
} | |
ttl = 5.h | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Line 35 of
AppConfig.pkl
should now read: