wire
wire copied to clipboard
wire.go file
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
same issue.
If you only want to generate wire_test.go
for a subpackage, try one of the options below:
- Run
wire
in the directory of that subpackage - 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.