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.go
toold_main.go
- read from
old_main.go
line 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.go
file
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 generate
properly? - How can i pass in arguments from
go generate
command line to the target script