Here is how my project is structure
├── cmd
│ ├── orders
│ │ ├── main.go
└── scripts
└── codegenerator.go
the codegenerator.go file is the file where i have put my code to generate the code. Here is the logic for codegenerator.go
- rename
main.gotoold_main.go - read from
old_main.goline by line and write to a new file calledmain.go - insert new lines/code blocks based on markers/placeholder in
main.go - remove
old_main.gofile
The go:generate directive is in main.go like this
//go:generate go run ../../scripts/codegenerator.go
I ran go generate from command line and wanted to pass in 3 arguments so that they can be utilized in codegenerator.go. here is my command and the errors i got (i executed this command on path cmd/orders)
$ go generate arg_one arg_two arg_three
can't load package: package arg_one: unknown import path "arg_one": cannot find module providing package arg_one
can't load package: package arg_two: unknown import path "arg_two": cannot find module providing package arg_two
can't load package: package arg_three: unknown import path "arg_three": cannot find module providing package arg_three
So the questions are
- Am i running
go generateproperly? - How can i pass in arguments from
go generatecommand line to the target script