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.
I've faced with silly difficulty to wire a private type from external library to an interface. This is trivial with manual wiring but took me some time with wire. I think the guide should be more helpful so people give up using wire.Bind if it involves unexported type, and switch back to non-idiomatic return interface. Although, I don't really understand the full complication, like if it will trigger some lint rules.
Alternatively, it might be helpful if there's additional API like wire.BindFieldOf to avoid returning interface.
Attached here is the example.
diff --git a/wire.go b/wire.go
index e8aa1f5..850fd68 100644
--- a/wire.go+++ b/wire.go@@ -22,13 +22,20 @@ import (
"github.com/google/wire"
)
+// providePublic provides an instance of Public from the internal S struct's PrivateType+// NOTE non-idiomatic+func providePublic(s *internal.S) Public {+ return s.PrivateType+}+
func injectedPublic() *P {
wire.Build(
provideS,
provideP,
+ providePublic,
//wire.FieldsOf(new(*internal.S), "Foo"),
- wire.FieldsOf(new(*internal.S), "PrivateType"),- wire.Bind(new(Public), new(*internal.private)),+ //wire.FieldsOf(new(*internal.S), "PrivateType"),+ //wire.Bind(new(Public), new(*internal.private)),
)
return &P{}
}
diff --git a/wire_gen.go b/wire_gen.go
index 773b89f..86b6f41 100644
--- a/wire_gen.go+++ b/wire_gen.go@@ -6,11 +6,23 @@
package main
+import (+ "github.com/giovanism/google-wire-unexported-type/internal"+)+
// Injectors from wire.go:
func injectedPublic() *P {
s := provideS()
- private := s.PrivateType- p := provideP(private)+ public := providePublic(s)+ p := provideP(public)
return p
}
++// wire.go:++// providePublic provides an instance of Public from the internal S struct's PrivateType+// NOTE non-idiomatic+func providePublic(s *internal.S) Public {+ return s.PrivateType+}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I've faced with silly difficulty to wire a private type from external library to an interface. This is trivial with manual wiring but took me some time with wire. I think the guide should be more helpful so people give up using
wire.Bind
if it involves unexported type, and switch back to non-idiomatic return interface. Although, I don't really understand the full complication, like if it will trigger some lint rules.Alternatively, it might be helpful if there's additional API like
wire.BindFieldOf
to avoid returning interface.Attached here is the example.
repo: https://github.com/giovanism/google-wire-unexported-type
also note that the below version of wire gen output is from when the type was still public
*internal.Private
Beta Was this translation helpful? Give feedback.
All reactions