This template generates Go structures as a package for building event-driven applications.
The go
code generated by this template has the following structure:
channels.gen.go
- contains all the channels defined in the AsyncAPI document.payloads.gen.go
- contains all the payloads.servers.gen.go
- contains servers addresses.version.gen.go
- contains version constants.
Watch the example output in the example directory.
- 1.1.0 =< Generator < 2.0.0
- Generator specific requirements
This template must be used with the AsyncAPI Generator. You can find all available options here.
$ npm install -g @asyncapi/generator
# clone this repository and navigate to this repository
$ ag ./example/asyncapi.yaml ./ -o ./example/generated -p packageName=your_go_package_name
Following are the options that can be passed to the generator
packageName
: name of the go package to be generated
Additionally, you can use the docker image:
Registry | Image |
---|---|
GitHub Container Registry | ghcr.io/spiral/asyncapi-go-template |
Using the
latest
tag for the docker image is highly discouraged because of possible backward-incompatible changes during major upgrades. Please, use tags inX.Y.Z
format
$ docker run --rm -u "$(id -u):$(id -g)" -v "${PWD}:/host:rw" -w "/host" \
ghcr.io/spiral/asyncapi-go-template ./example/asyncapi.yaml @spiral/asyncapi-go-template \
-o ./example/generated \
-p packageName=your_go_package_name \
--force-write
In addition, the docker image contains installed @asyncapi/markdown-template
and @asyncapi/html-template
. You can use them to generate documentation for your AsyncAPI document.
You can configure this template by passing different parameters in the Generator CLI: -p PARAM1_NAME=PARAM1_VALUE -p PARAM2_NAME=PARAM2_VALUE
Name | Description | Required | Example |
---|---|---|---|
packageName |
Name for the generated Go package | false | asyncapi |
New versions publishing is very simple - just make required changes in this repository, update changelog file and "publish" new release using repo releases page.
Docker image & npm package will be build and published automatically.
New release will overwrite the
latest
docker image tag.