Skip to content
This repository was archived by the owner on Aug 25, 2025. It is now read-only.
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

Open

Description

@cglotr

## 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.

Activity

  1. troyatomic commented on Jun 14, 2022

    @troyatomic

    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.

  2. raza-basit commented on Aug 14, 2022

    @raza-basit
  3. colececil commented on Jun 24, 2023

    @colececil

    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.

  4. colececil commented on Jun 24, 2023

    @colececil

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions