Go:generate not working

Hello,

I am starting playing with golang. I am using QuickTemplate to generate HTML pages. QuickTemplate makes use of the //go:generate directive to generate go source that then are compiled.
As I understand it go generate starts the command before the real go build job is done.

Mymain go file has a //go:generate directive to start qtc (quick template compiler). Sadly it is not starting the qtc command rsulting in a “no go files” errors.

go version is Win10 go version go1.12.3 windows/amd64.

When starting qtc by hand and then go build it works fine.

Am I missing something ?

Thanks for your help.

Olivier

Hi. In the example for basic server they uses the directive like this

//go:generate qtc templates

Where templates is the path to the templates

It does not work better with
//go:generate qtc templates
in fact it does not even work with
//go:generate echo helloworld
or
//go:generate touch helloworld

I am missing something to make go build start the go generate task.

Hi. You have to run

go generate main.go

for example. Nothing happens on either run or build

You’re right. I have miss - readed the doc that clearly states

Go generate is never run automatically by go build, go get, go test,
and so on. It must be run explicitly.

Could be a new features nevertheless as many projects use code generation (emplating , orm and other use cases).

No. It seems it has worked like this since it was introduced in 1.4. But I’m not 100% sure.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.