Library Quickstart
This page builds the objects of one application from your own Go program, with the same
checks kurel build runs, in the same order. The program below is the Example in
pkg/oam (ExampleTransformer_Transform), which the test suite runs, so the code and the
output on this page are tested.
Set up a module
Then copy the replace lines of launcher’s go.mod at that version into your own
go.mod, as Install explains. Without them the
build fails.
Tested version: the program is the same file at v0.2.0-beta.5 and at main. It needs
registry.DeclareTypes and the two-value ValidateAuthoredPropertiesForTarget. The
earlier prerelease, v0.2.0-beta.4, does not have them. v0.2.0-beta.5 is a published
prerelease (see Status words). When a newer tag exists, you can pin that tag
instead.
The program
Save this as main.go:
Run it with go run .. It prints:
What each step is for
- Register and declare.
registryreturns every built-in handler and lowering rule.DeclareTypesdeclares identities such aswebservice@v1that a document may author, so it runs after the registration. - Parse.
ParseWithExtraTypesrejects an unknown field in the document. TheLowerableTypesargument names the types a lowering rule claims. - Evaluate the profile. The profile’s capability choices become the bindings the transform uses.
- Validate.
ValidateAuthoredPropertiesForTargetchecks every authored property against its type’s schema, plus the properties the engine reads itself (a trait’sscope, for example), and returns a normalized copy. Pass that copy toTransform. CallingTransformon the parsed document skips this check. A profile that setsspec.featureGatesneedsValidateAuthoredPropertiesForTargetWithGatesinstead, andTransformContext.TargetVersionandFeatureGateson theTransformcall, so the overrides reach the Service name check too.ValidateAuthoredPropertiesForTargetWithGatesandFeatureGatesare not inv0.2.0-beta.5: pinmainor a newer tag to use them (see the OAM schemas and contract). - Transform, generate, check.
Transformlowers the document into a kureCluster.GenerateApplicationsbuilds the objects, andCheckInDocumentCollisionsfails if two applications of the document generate the same object.
Encoding the objects as YAML, writing a layout, or handing them to a delivery tool is your program’s job; launcher stops at the objects. The OAM Model reference documents each call, and Concepts explains the model behind them.