更新自定义 DI 注入

我算是明白了,别说 go wire 了,勾八连 GO 这个语言能不能靠得住都挺难说的。既然如此,还是大胆一点吧。俗话说得好,所有让人难绷的细节都是为了宏观上的达成意图的方便。那就来吧。
This commit is contained in:
des
2026-02-25 08:08:21 +08:00
parent 731f1d01e6
commit 4cab2f6ff3
7 changed files with 45 additions and 11 deletions

View File

@@ -0,0 +1,4 @@
package lab
func main() {
}

View File

@@ -0,0 +1,5 @@
package lab
type Animal interface {
sound() string
}

View File

@@ -0,0 +1,21 @@
package pasture
type Dog struct {
lines string
weapon string
}
func (d *Dog) Sound() string {
return d.lines
}
func (d *Dog) Dangers() bool {
if len(d.weapon) == 0 {
return false
}
return true
}
func NewDog(line string) *Dog {
return &Dog{lines: line}
}

View File

@@ -0,0 +1,13 @@
package pasture
type Sheep struct {
lines string
}
func (s *Sheep) Sound() string {
return s.lines
}
func NewSheep(line string) *Sheep {
return &Sheep{lines: line}
}