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
Is your feature request related to a problem? Please describe.
When I used wire to build the code with go generics in golang:1.18, but It didn't work and throw some error.
There are some code, command and log in Additional context.
Describe the solution you'd like
I think that wire should support code with go generics as soon as possible for golang:1.18. It must a great power to help developers to build the apps.
Describe alternatives you've considered
Nothing.
Additional context
Code
main.go
package main
import "fmt"
type Message struct {
Msg string
V int
}
func NewMessage(v int) Message {
return Message{Msg: "Hi there!", V: v + 1}
}
type Greeter struct {
Message Message // <- adding a Message field
}
func NewGreeter(m Message) Greeter {
return Greeter{Message: m}
}
func (g Greeter) Greet() Message {
return g.Message
}
type V interface {
int | float32
}
func NewV[T V]() T {
return 2
}
type Event struct {
Greeter Greeter // <- adding a Greeter field
}
func NewEvent(g Greeter) Event {
return Event{Greeter: g}
}
func (e Event) Start() {
m := e.Greeter.Greet()
fmt.Println(m.Msg, m.V)
}
func main() {
e := InitializeEvent()
e.Start()
}
// func main() {
// v := NewV[int]()
// message := NewMessage(v)
// greeter := NewGreeter(message)
// event := NewEvent(greeter)
// event.Start()
// }
wire.go
//go:build wireinject
package main
// The build tag makes sure the stub is not built in the final build.
import "github.com/google/wire"
func InitializeEvent() Event {
wire.Build(NewEvent, NewGreeter, NewMessage, NewV)
return Event{}
}
Command
wire
Error log
wire: ~/test/wire/main.go:27:6: expected ';', found '|'
wire: ~/test/wire/main.go:31:2: expected '}', found 'return'
wire: ~/test/wire/main.go:31:9: expected ';', found 2
wire: ~/test/wire/main.go:27:2: int is not an interface
wire: ~/test/wire/wire.go:10:47: undeclared name: NewV
wire: generate failed
The text was updated successfully, but these errors were encountered:
Is your feature request related to a problem? Please describe.
When I used wire to build the code with go generics in golang:1.18, but It didn't work and throw some error.
There are some code, command and log in
Additional context
.Describe the solution you'd like
I think that wire should support code with go generics as soon as possible for golang:1.18. It must a great power to help developers to build the apps.
Describe alternatives you've considered
Nothing.
Additional context
Code
main.go
wire.go
Command
Error log
The text was updated successfully, but these errors were encountered: