From 4cab2f6ff320fe36b150a5aff9c0c6b16ef94b84 Mon Sep 17 00:00:00 2001 From: des <18638715007@163.com> Date: Wed, 25 Feb 2026 08:08:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=20DI=20=E6=B3=A8=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 我算是明白了,别说 go wire 了,勾八连 GO 这个语言能不能靠得住都挺难说的。既然如此,还是大胆一点吧。俗话说得好,所有让人难绷的细节都是为了宏观上的达成意图的方便。那就来吧。 --- srv/cmd/gatekeeper/wire.go | 7 ------- srv/cmd/tool/lab/bluePrint.go | 4 ++++ srv/cmd/tool/lab/interface.go | 5 +++++ srv/cmd/tool/lab/pasture/dog.go | 21 +++++++++++++++++++++ srv/cmd/tool/lab/pasture/sheep.go | 13 +++++++++++++ srv/cmd/tool/main.go | 1 + srv/internal/application/appliceation.go | 5 +---- 7 files changed, 45 insertions(+), 11 deletions(-) create mode 100644 srv/cmd/tool/lab/bluePrint.go create mode 100644 srv/cmd/tool/lab/interface.go create mode 100644 srv/cmd/tool/lab/pasture/dog.go create mode 100644 srv/cmd/tool/lab/pasture/sheep.go create mode 100644 srv/cmd/tool/main.go diff --git a/srv/cmd/gatekeeper/wire.go b/srv/cmd/gatekeeper/wire.go index 808bdd8..605e1ed 100644 --- a/srv/cmd/gatekeeper/wire.go +++ b/srv/cmd/gatekeeper/wire.go @@ -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} -} diff --git a/srv/cmd/tool/lab/bluePrint.go b/srv/cmd/tool/lab/bluePrint.go new file mode 100644 index 0000000..7fcd33c --- /dev/null +++ b/srv/cmd/tool/lab/bluePrint.go @@ -0,0 +1,4 @@ +package lab + +func main() { +} diff --git a/srv/cmd/tool/lab/interface.go b/srv/cmd/tool/lab/interface.go new file mode 100644 index 0000000..0e726f3 --- /dev/null +++ b/srv/cmd/tool/lab/interface.go @@ -0,0 +1,5 @@ +package lab + +type Animal interface { + sound() string +} diff --git a/srv/cmd/tool/lab/pasture/dog.go b/srv/cmd/tool/lab/pasture/dog.go new file mode 100644 index 0000000..5c62e63 --- /dev/null +++ b/srv/cmd/tool/lab/pasture/dog.go @@ -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} +} diff --git a/srv/cmd/tool/lab/pasture/sheep.go b/srv/cmd/tool/lab/pasture/sheep.go new file mode 100644 index 0000000..3885458 --- /dev/null +++ b/srv/cmd/tool/lab/pasture/sheep.go @@ -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} +} diff --git a/srv/cmd/tool/main.go b/srv/cmd/tool/main.go new file mode 100644 index 0000000..06ab7d0 --- /dev/null +++ b/srv/cmd/tool/main.go @@ -0,0 +1 @@ +package main diff --git a/srv/internal/application/appliceation.go b/srv/internal/application/appliceation.go index e120230..016e184 100644 --- a/srv/internal/application/appliceation.go +++ b/srv/internal/application/appliceation.go @@ -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,