wire icon indicating copy to clipboard operation
wire copied to clipboard

wire.go file

Open bereyes opened this issue 3 years ago • 2 comments

Discussed in https://github.com/google/wire/discussions/304

Originally posted by bereyes August 18, 2021 Sorry , I have a question: wire.go file must be on main package? If I have wire.go in another package , when I use wire cmd I am getting "undeclared name: methodName" message, and I am not sure why. EDIT: If wire.go is in the same folder that a provider it fails: Example

func InitializeWebAPI() *Container {
	wire.Build(
		NewControllerContainer,
		api.NewPingController,
	)
	return &Container{}
}

If wire.go is out that folder wire cmd is able to generate wire_gen.go , is it a correct behavior? When my code looks like:

package infrastructure

import (
	"github.com/google/wire"
	"github.com/yyy/xxx-api-rules-test/cmd/entrypoint/api"
	"github.com/yyy/xxx-test/cmd/infrastructure/dependency"
)

func InitializeWebAPI() *dependency.Container {
	wire.Build(
		dependency.NewControllerContainer,
		api.NewPingController,
	)
	return &dependency.Container{}
}

wire works well Could you help me please?

Thanks in advance

bereyes avatar Aug 18 '21 18:08 bereyes

same issue.

git-xiaocao avatar Mar 12 '22 10:03 git-xiaocao

If you only want to generate wire_test.go for a subpackage, try one of the options below:

  1. Run wire in the directory of that subpackage
  2. Run wire gen import.path.to.subpkg, this should work in project root. I think patterns would work for import paths as well.

LMK if this solves your problem.

jayzhuang avatar Apr 17 '22 23:04 jayzhuang