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
I've recently started playing with wire in order to achieve the DI in go. I came across the problem that go sees two declarations of function InitializeEvent I've been following along with the tutorial in order to get a better grasp of how DI works in go. when I add
two lines of //go:build !wireinject followed with // +build !wireinject the compiler doesn't complain but after running go build I received "wire.go: multiple //go:build comments". So am I doing something wrong or did someone had similar issue with wire?
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
-
Greetings
I've recently started playing with wire in order to achieve the DI in go. I came across the problem that go sees two declarations of function InitializeEvent I've been following along with the tutorial in order to get a better grasp of how DI works in go. when I add
two lines of //go:build !wireinject followed with // +build !wireinject the compiler doesn't complain but after running go build I received "wire.go: multiple //go:build comments". So am I doing something wrong or did someone had similar issue with wire?
wire.go
`//go:build !wireinject
//go:build !wireinject
// +build !wireinject
package wire
import (
. "wireTutorial/models"
)
func InitializeEvent(phrase string) (Event,error) {
wire.Build(NewEvent, NewGreeter,NewMessage)
} `
models.go
`package models
import (
"errors"
"fmt"
)
type Message string
type Greeter struct {
Message Message
Grumpy bool
}
type Event struct {
Greeter Greeter
}
func (g Greeter) Greet() Message {
return g.Message
}
func (e Event) Start() {
msg := e.Greeter.Greet()
fmt.Println(msg)
}
func NewMessage(phrase string) Message {
return Message(phrase)
}
func NewGreeter(m Message) Greeter {
return Greeter{Message: m, Grumpy: true}
}
func NewEvent(g Greeter) (Event,error){
if g.Grumpy {
return Event{}, errors.New("couldn't create event, event greeter is grumpy")
}
}
`
Beta Was this translation helpful? Give feedback.
All reactions