Following the example of googlewire, we can initialize the event structure in the following way
message.go:
type message string func newmessage() message { //tbd }
event.go
func newevent(g message ) event { return event{message : g} } type event struct { message message } func (e event) start() { fmt.println(msg) }
We can initialize via line:
func main() { e := initializeevent() e.start() } func initializeevent() event { wire.build(newevent, newmessage) return event{} }
Is there a way to make the init function return multiple values, but we only need one return value to inject, for example:
func newmessage() (message,error ){ //tbd }
or
func NewMessage() (Message,Greeter) { //TBD }
To declare a function with multiple return values, you need to put them in parentheses:
func NewMessage() (Message, error) { return Message(“TBD”), nil }
EDIT: Your question (whether it is possible to return an error from the init function) will be answered in the next part of the wire tutorial - https://github.com/google/wire/ tree/main/_tutorial#making-changes -with line
The above is the detailed content of Wire google Inject with multiple returns of provider function. For more information, please follow other related articles on the PHP Chinese website!