-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3f6c387
commit f1fac84
Showing
5 changed files
with
114 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
type Meta struct{} | ||
type Message struct { | ||
msg string | ||
r Meta | ||
} | ||
type Mouth struct{ Message Message } | ||
type Hand struct{ Message Message } | ||
type People struct { | ||
Mouth Mouth | ||
Hand Hand | ||
//.. | ||
} | ||
|
||
func main_() { | ||
meta := NewMeta() | ||
message := NewMessage("A Hi To U", meta) | ||
aMouth := NewMouth(message) | ||
aHand := NewHand(message) | ||
people := NewPeople(aMouth, aHand) | ||
people.Hi() | ||
} | ||
|
||
//use wire | ||
func main() { | ||
p := InitAPeople("Nice to meet you!") | ||
p.Hi() | ||
} | ||
func NewMeta() Meta { | ||
return Meta{} | ||
} | ||
func NewMessage(msg string, r Meta) Message { | ||
return Message{ | ||
msg: msg, | ||
r: r, | ||
} | ||
} | ||
func NewMouth(m Message) Mouth { | ||
return Mouth{Message: m} | ||
} | ||
func NewHand(m Message) Hand { | ||
return Hand{Message: m} | ||
} | ||
func NewPeople(g Mouth, t Hand) People { | ||
return People{Mouth: g, Hand: t} | ||
} | ||
|
||
func (p People) Hi() { | ||
msg := p.Mouth.Greet() | ||
fmt.Println(msg) | ||
} | ||
func (g Mouth) Greet() string { | ||
return g.Message.msg | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
//go:build wireinject | ||
// +build wireinject | ||
|
||
package main | ||
|
||
import "github.com/google/wire" | ||
|
||
func InitAPeople(msg string) People { | ||
wire.Build( | ||
NewPeople, | ||
NewMouth, | ||
NewHand, | ||
//.. | ||
NewMessage, | ||
NewMeta) | ||
return People{} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters