Generate code from launch YML
Build it
make build
Run it
./bin/launch-gen <path-to-launch-yml>
This assumes you have a go mod
repo.
- Grab the latest version of
launch-gen
.
go get github.com/Clever/launch-gen
- Within your repo's
Makefile
, declarelaunch-gen
to be built on everyinstall_deps
invocation. Example:
install_deps:
go mod vendor
go build -o bin/launch-gen -mod=vendor ./vendor/github.com/Clever/launch-gen
-
Include as a blank import, to make sure
launch-gen
is declared as a dependency ingo.mod
. See Clever/template-wag for an example. -
On the entry point of your application, include a stanza to generate the config. This should match the launch YAML in
launch/
.
// generate launch config
//go:generate sh -c "$PWD/bin/launch-gen -o launch.go -p main $PWD/launch/<your-application>.yml"
If you scope the current project's /bin/
to the Makefile's path, then you can simplify the stanza:
// generate launch config
//go:generate launch-gen -o launch.go -p main $PWD/launch/<your-application>.yml
- Ensure you call
go generate ./...
in the Makefile for paths that would be relevant for building or running the application. This allows the//go:generate
stanza to run, which helps with building.
For example:
PKGS := $(shell go list ./... | grep -v /vendor | grep -v tools)
$(PKGS): generate golang-test-all-strict-deps
$(call golang-test-all-strict,$@)
# Before the `test` recipe is called, `make generate` is called as a prerequisite.
test: $(PKGS)
# Before the `build` recipe is called, `make generate` is called as a prerequisite.
build: generate
$(call golang-build,$(PKG),$(EXECUTABLE))
# Create a target that will run `go generate` when `make generate` is called.
generate:
go generate ./...
-
Run
make generate
.launch.go
should be within the specified directory. -
Call
InitLaunchConfig()
during startup of your program, and use it when needed.