To set up BAML with Go do the following:
https://marketplace.visualstudio.com/items?itemName=boundary.baml-extension
This command will:
baml_src directoryThe BAML generator uses gofmt and goimports to format the generated Go code. Install these tools:
These tools are required by the on_generate command in your generator configuration and ensure the generated code is properly formatted.
baml_client Go package from .baml filesOne of the files in your baml_src directory will have a generator block. This tells BAML how to generate the baml_client directory, which will have auto-generated Go code to call your BAML functions.
Any types defined in .baml files will be converted into Go structs in the baml_client directory.
You can modify your build process to always call baml-cli generate before building.
See What is baml_client to learn more about how this works.
If you set up the VSCode extension, it will automatically run baml-cli generate on saving a BAML file.
BAML integrates seamlessly with Go modules. Make sure your go.mod file includes the BAML dependency:
The generated baml_client package will use your module path, so you can import it as:
All BAML Go functions require a context.Context as the first parameter, allowing you to:
You’re all set! Continue on to the Deployment Guides for your language to learn how to deploy your BAML code or check out the Interactive Examples to see more examples.