Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing go run or go build example of generated code #362

Open
cglotr opened this issue Jun 11, 2022 · 4 comments · May be fixed by #363
Open

Missing go run or go build example of generated code #362

cglotr opened this issue Jun 11, 2022 · 4 comments · May be fixed by #363

Comments

@cglotr
Copy link

cglotr commented Jun 11, 2022

## Using Wire to Generate Code

I think this step is a missing example of how to run or build the generated code. Also, it's not obvious that we need also to include the generated files when executing either go run or go build like go build main.go wire_gen.go.

I think adding an extra paragraph explaining how to run or build would be very useful & prevent frustration, especially for people new to go.

When following the steps, I think most people will set seeing the word Hi there! on the console to be the goal to verify that we get the same outcome as in the non-wire code.

@cglotr cglotr linked a pull request Jun 11, 2022 that will close this issue
@troyatomic
Copy link

Yeah, I think there is something missing in the instructions as well. If I do go run main.go, I get...

# command-line-arguments
./main.go:77:12: undefined: InitializeEvent

doing go build first then it runs fine when using the built executable.

@raza-basit
Copy link

@troyatomic you need to execute the wire command to generate the bindings.

https://github.com/google/wire/blob/main/_tutorial/README.md#using-wire-to-generate-code

image

@colececil
Copy link

I agree it would be good to add some documentation about this. I'm fairly new to Go, and this was not intuitive to me. Up till now, I've been running my project with go run cmd/myproject/myproject.go. However, after integrating with Wire and generating wire_gen.go, I get something like this when I run that command:

# command-line-arguments
cmd\myproject\myproject.go:16:21: undefined: InitializeMyType

The same thing happens with go build cmd/myproject/myproject.go. Being fairly new to Go, I didn't realize I could (or needed to) pass in multiple go files to go run or go build. I eventually figured out I could run it by switching to my project's cmd/myproject directory and then using go run ..

After that, I tried to run it from my project root directory using go run cmd/myproject/, but I was confused when I got the following error:

package cmd/myproject is not in GOROOT

Finally, I figured out I need to put ./ in front of the project directory to tell Go I'm trying to run that instead of an installed package: go run ./cmd/myproject/.

Anyway, all this is to say the documentation @cglotr is suggesting would have saved me some time and frustration.

@colececil
Copy link

Whoops, didn't notice till just now that @cglotr has a pull request out for this. 😅 Thanks, @cglotr!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants