You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Iam using pkl files for config and generated go files for it. In the process of loading config Iam using LoadFromPath() this function expects a pkl file as parameter so for this I need to have pkl executable in my system.My query is when we are already generating go file from pkl why do we need to give pkl file path again.Is there any way to load pkl files from generated code without giving path to .pkl file??
The text was updated successfully, but these errors were encountered:
The generated Go code is the structure of the configuration (the schema, or template). It does not contain the values of the configuration. Those, you load at runtime (so that you can change configuration out-of-sync with your application code).
Phil is right about the generated code only being the structure, and not the values.
With that said, though, there are a couple options that you have to embed values from Pkl into your application.
Embed pkl files
One option is to use go:embed to embed those Pkl files as an embed.FS. You can then evaluate those modules straight from the embedded file system. Here is a commit that demonstrates that: bioball/pkl-go-examples@3b843c3
The benefit of this approach is that because Pkl happens at runtime, you can pass in external variables into the Pkl program. For example, you can pass in environment variables and use read("env:") within Pkl to read those environment variables. This is especially helpful for things like reading in secret values into Pkl.
The drawback is that you still need to include the pkl CLI in the deployed environment of your application.
Pre-evaluate Pkl into binary
If you really don't want to include the pkl CLI at runtime, there's another option here, which is to first evaluate Pkl into a binary format, and then embed that binary into your application. Then, you can use pkl.Unmarshal to turn that binary into your app config.
Iam using pkl files for config and generated go files for it. In the process of loading config Iam using LoadFromPath() this function expects a pkl file as parameter so for this I need to have pkl executable in my system.My query is when we are already generating go file from pkl why do we need to give pkl file path again.Is there any way to load pkl files from generated code without giving path to .pkl file??
The text was updated successfully, but these errors were encountered: