From faf0010e249deb13ec21a4d18a0573d0de055938 Mon Sep 17 00:00:00 2001 From: tbxark Date: Wed, 6 Nov 2024 09:53:38 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E9=87=8D=E6=9E=84wire=E6=B3=A8?= =?UTF-8?q?=E5=85=A5=E9=85=8D=E7=BD=AE=EF=BC=8C=E4=BB=8Epkg=E4=B8=AD?= =?UTF-8?q?=E5=88=A0=E9=99=A4wire?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/api/wire.go | 3 +-- cmd/app/wire.go | 3 +-- cmd/bot/wire.go | 2 +- cmd/dash/wire.go | 3 +-- internal/wire.go | 21 ++++++++++++++++++++- pkg/wire.go | 22 ---------------------- 6 files changed, 24 insertions(+), 30 deletions(-) delete mode 100644 pkg/wire.go diff --git a/cmd/api/wire.go b/cmd/api/wire.go index 07be268..34a4db9 100644 --- a/cmd/api/wire.go +++ b/cmd/api/wire.go @@ -7,11 +7,10 @@ import ( "github.com/google/wire" "github.com/tbxark/sphere/internal" "github.com/tbxark/sphere/internal/config" - "github.com/tbxark/sphere/pkg" "github.com/tbxark/sphere/pkg/utils/boot" ) func NewAPIApplication(conf *config.Config) (*boot.Application, error) { - wire.Build(config.ProviderSet, pkg.ProviderSet, internal.ProviderSet, wire.NewSet(newApplication)) + wire.Build(internal.ProviderSet, wire.NewSet(newApplication)) return &boot.Application{}, nil } diff --git a/cmd/app/wire.go b/cmd/app/wire.go index 3b8e65a..f2dda83 100644 --- a/cmd/app/wire.go +++ b/cmd/app/wire.go @@ -7,11 +7,10 @@ import ( "github.com/google/wire" "github.com/tbxark/sphere/internal" "github.com/tbxark/sphere/internal/config" - "github.com/tbxark/sphere/pkg" "github.com/tbxark/sphere/pkg/utils/boot" ) func NewApplication(conf *config.Config) (*boot.Application, error) { - wire.Build(config.ProviderSet, pkg.ProviderSet, internal.ProviderSet, wire.NewSet(newApplication)) + wire.Build(internal.ProviderSet, wire.NewSet(newApplication)) return &boot.Application{}, nil } diff --git a/cmd/bot/wire.go b/cmd/bot/wire.go index 0b9a995..12db27b 100644 --- a/cmd/bot/wire.go +++ b/cmd/bot/wire.go @@ -11,6 +11,6 @@ import ( ) func NewBotApplication(conf *config.Config) (*boot.Application, error) { - wire.Build(config.ProviderSet, internal.ProviderSet, wire.NewSet(newApplication)) + wire.Build(internal.ProviderSet, wire.NewSet(newApplication)) return &boot.Application{}, nil } diff --git a/cmd/dash/wire.go b/cmd/dash/wire.go index 8634abc..427812e 100644 --- a/cmd/dash/wire.go +++ b/cmd/dash/wire.go @@ -7,11 +7,10 @@ import ( "github.com/google/wire" "github.com/tbxark/sphere/internal" "github.com/tbxark/sphere/internal/config" - "github.com/tbxark/sphere/pkg" "github.com/tbxark/sphere/pkg/utils/boot" ) func NewDashApplication(conf *config.Config) (*boot.Application, error) { - wire.Build(config.ProviderSet, pkg.ProviderSet, internal.ProviderSet, wire.NewSet(newApplication)) + wire.Build(internal.ProviderSet, wire.NewSet(newApplication)) return &boot.Application{}, nil } diff --git a/internal/wire.go b/internal/wire.go index 2eac45b..804279c 100644 --- a/internal/wire.go +++ b/internal/wire.go @@ -3,9 +3,28 @@ package internal import ( "github.com/google/wire" "github.com/tbxark/sphere/internal/biz" + "github.com/tbxark/sphere/internal/config" "github.com/tbxark/sphere/internal/pkg" "github.com/tbxark/sphere/internal/server" "github.com/tbxark/sphere/internal/service" + "github.com/tbxark/sphere/pkg/cache" + "github.com/tbxark/sphere/pkg/cache/memory" + "github.com/tbxark/sphere/pkg/storage" + "github.com/tbxark/sphere/pkg/storage/qiniu" + "github.com/tbxark/sphere/pkg/wechat" ) -var ProviderSet = wire.NewSet(server.ProviderSet, service.ProviderSet, pkg.ProviderSet, biz.ProviderSet) +var cacheSet = wire.NewSet( + memory.NewByteCache, + wire.Bind(new(cache.ByteCache), new(*memory.Cache[[]byte])), +) + +var storageSet = wire.NewSet( + qiniu.NewQiniu, + wire.Bind(new(storage.Storage), new(*qiniu.Qiniu)), +) + +var ProviderSet = wire.NewSet( + wire.NewSet(wechat.NewWechat, storageSet, cacheSet), + server.ProviderSet, service.ProviderSet, pkg.ProviderSet, biz.ProviderSet, config.ProviderSet, +) diff --git a/pkg/wire.go b/pkg/wire.go deleted file mode 100644 index 11f0ff3..0000000 --- a/pkg/wire.go +++ /dev/null @@ -1,22 +0,0 @@ -package pkg - -import ( - "github.com/google/wire" - "github.com/tbxark/sphere/pkg/cache" - "github.com/tbxark/sphere/pkg/cache/memory" - "github.com/tbxark/sphere/pkg/storage" - "github.com/tbxark/sphere/pkg/storage/qiniu" - "github.com/tbxark/sphere/pkg/wechat" -) - -var cacheSet = wire.NewSet( - memory.NewByteCache, - wire.Bind(new(cache.ByteCache), new(*memory.Cache[[]byte])), -) - -var storageSet = wire.NewSet( - qiniu.NewQiniu, - wire.Bind(new(storage.Storage), new(*qiniu.Qiniu)), -) - -var ProviderSet = wire.NewSet(wechat.NewWechat, storageSet, cacheSet)