You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 25, 2025. It is now read-only.
Repository navigation
This repository was archived by the owner on Aug 25, 2025. It is now read-only.
Missing go run or go build example of generated code #362
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.
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:
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.
Activity
troyatomic commentedon Jun 14, 2022
Yeah, I think there is something missing in the instructions as well. If I do
go run main.go, I get...doing
go buildfirst then it runs fine when using the built executable.raza-basit commentedon Aug 14, 2022
@troyatomic you need to execute the
wirecommand to generate the bindings.https://github.com/google/wire/blob/main/_tutorial/README.md#using-wire-to-generate-code
colececil commentedon Jun 24, 2023
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 generatingwire_gen.go, I get something like this when I run that command: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 togo runorgo build. I eventually figured out I could run it by switching to my project'scmd/myprojectdirectory and then usinggo 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: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 commentedon Jun 24, 2023
Whoops, didn't notice till just now that @cglotr has a pull request out for this. 😅 Thanks, @cglotr!