This repository was archived by the owner on Nov 18, 2021. It is now read-only.
Replies: 1 comment
-
|
This discussion has been migrated to cue-lang/cue#463. For more details about CUE's migration to a new home, please see cue-lang/cue#1078. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Consider the following situation:
We are writing a command called
helloin Go (example.com/hellois the module path).hellois driven by a-configflag, which accepts a CUE input (seecue help inputs).-configcan appear multiple times.We want the source of truth for this configuration to be Go code. Therefore we define
Configand associated types in Go and have the CUE definitions follow from that:As authors of
hello, we usecue get go --local example.com/helloto generate#Configand associated definitions from theConfigGo type. These will then be available in theexample.com/helloCUE package for anyone who might care to use them (the definitions are effectively part of the "API" ofhelloso it makes sense to publish this "API").At runtime (i.e. when the user invokes
hello), we want to validate the configuration passed to us. First we unify the provided-configCUE instances. Next we want to validate the result against the schema generated from theConfigtype, that is to say#Configand friends.The question is: at runtime, how do get a
cuelang.org/go/cue.Valuethat is the#Configdefinition?The
cue get gogenerated.cuefiles are not guaranteed to be available; that is to say, either we are in the context of a CUE module at all, or the main module in context does not resolveexample.com/blah. Therefore, loading (viacuelang.org/go/cue/load) the definitions at runtime in this way seems brittle.The
*cuelang.org/go/encoding/gocode/gocodec.Codectype defines anExtractTypemethod. Conceivably we could call this method passingConfig{}as an argument. However:Inputin this case):The approach I am following today involves embedding the result of
cue get gointo a string constant in Go code (via ago:generatedirective) and then usingcuelang.org/go/cue.Runtime.Compile. This works and has the added benefit of being entirely consistent withexample.com/helloCUE package.However I'm raising this for discussion to get thoughts/ideas/feedback from others.
Thanks in advance
Beta Was this translation helpful? Give feedback.
All reactions