更新自定义 DI 注入
我算是明白了,别说 go wire 了,勾八连 GO 这个语言能不能靠得住都挺难说的。既然如此,还是大胆一点吧。俗话说得好,所有让人难绷的细节都是为了宏观上的达成意图的方便。那就来吧。
This commit is contained in:
@@ -13,7 +13,6 @@ import (
|
||||
|
||||
func getApplication() (*application.Application, error) {
|
||||
wire.Build(
|
||||
CtrlCollector,
|
||||
application.NewApplication,
|
||||
database.GetDataBaseClient,
|
||||
database.GetQuery,
|
||||
@@ -22,9 +21,3 @@ func getApplication() (*application.Application, error) {
|
||||
)
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func CtrlCollector(
|
||||
c1 *userpak.UserCtl,
|
||||
) []application.Ctrl {
|
||||
return []application.Ctrl{c1}
|
||||
}
|
||||
|
||||
4
srv/cmd/tool/lab/bluePrint.go
Normal file
4
srv/cmd/tool/lab/bluePrint.go
Normal file
@@ -0,0 +1,4 @@
|
||||
package lab
|
||||
|
||||
func main() {
|
||||
}
|
||||
5
srv/cmd/tool/lab/interface.go
Normal file
5
srv/cmd/tool/lab/interface.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package lab
|
||||
|
||||
type Animal interface {
|
||||
sound() string
|
||||
}
|
||||
21
srv/cmd/tool/lab/pasture/dog.go
Normal file
21
srv/cmd/tool/lab/pasture/dog.go
Normal 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}
|
||||
}
|
||||
13
srv/cmd/tool/lab/pasture/sheep.go
Normal file
13
srv/cmd/tool/lab/pasture/sheep.go
Normal 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}
|
||||
}
|
||||
1
srv/cmd/tool/main.go
Normal file
1
srv/cmd/tool/main.go
Normal file
@@ -0,0 +1 @@
|
||||
package main
|
||||
@@ -35,11 +35,8 @@ func (app *Application) Stop() {
|
||||
}
|
||||
}
|
||||
|
||||
func NewApplication(cs []Ctrl, p *sql.DB) *Application {
|
||||
func NewApplication(ct Ctrl, p *sql.DB) *Application {
|
||||
route := gin.Default()
|
||||
for _, ctrl := range cs {
|
||||
ctrl.RegisterRoutes(route)
|
||||
}
|
||||
srv := &http.Server{
|
||||
Addr: ":8443",
|
||||
Handler: route,
|
||||
|
||||
Reference in New Issue
Block a user