Skip to content

Commit

Permalink
perf: 重构wire注入配置,从pkg中删除wire
Browse files Browse the repository at this point in the history
  • Loading branch information
TBXark committed Nov 6, 2024
1 parent 53024ef commit faf0010
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 30 deletions.
3 changes: 1 addition & 2 deletions cmd/api/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
3 changes: 1 addition & 2 deletions cmd/app/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion cmd/bot/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
3 changes: 1 addition & 2 deletions cmd/dash/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
21 changes: 20 additions & 1 deletion internal/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
22 changes: 0 additions & 22 deletions pkg/wire.go

This file was deleted.

0 comments on commit faf0010

Please sign in to comment.