Skip to content

Commit 001c33c

Browse files
committed
chore: 简化入口函数
1 parent 5963b8c commit 001c33c

16 files changed

+122
-270
lines changed

cmd/api/Dockerfile

-14
This file was deleted.

cmd/api/main.go

-20
This file was deleted.

cmd/api/wire.go

-16
This file was deleted.

cmd/api/wire_gen.go

-43
This file was deleted.

cmd/app/builder.go

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package main
2+
3+
import (
4+
"github.com/TBXark/sphere/internal/biz/task"
5+
"github.com/TBXark/sphere/internal/server/api"
6+
"github.com/TBXark/sphere/internal/server/bot"
7+
"github.com/TBXark/sphere/internal/server/dash"
8+
"github.com/TBXark/sphere/internal/server/docs"
9+
"github.com/TBXark/sphere/pkg/utils/boot"
10+
)
11+
12+
func newApplication(dash *dash.Web, api *api.Web, docs *docs.Web, initialize *task.DashInitialize, cleaner *task.ConnectCleaner) *boot.Application {
13+
return boot.NewApplication(
14+
dash,
15+
api,
16+
docs,
17+
initialize,
18+
cleaner,
19+
)
20+
}
21+
22+
func newAPIApplication(api *api.Web, initialize *task.DashInitialize, cleaner *task.ConnectCleaner) *boot.Application {
23+
return boot.NewApplication(
24+
api,
25+
initialize,
26+
cleaner,
27+
)
28+
}
29+
30+
func newDashApplication(dash *dash.Web, initialize *task.DashInitialize, cleaner *task.ConnectCleaner) *boot.Application {
31+
return boot.NewApplication(
32+
dash,
33+
initialize,
34+
cleaner,
35+
)
36+
}
37+
38+
func newBotApplication(app *bot.Bot) *boot.Application {
39+
return boot.NewApplication(app)
40+
}

cmd/app/main.go

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
package main
22

33
import (
4-
"github.com/TBXark/sphere/internal/biz/task"
4+
"flag"
5+
"github.com/TBXark/sphere/internal/config"
56
"github.com/TBXark/sphere/internal/pkg/app"
6-
"github.com/TBXark/sphere/internal/server/api"
7-
"github.com/TBXark/sphere/internal/server/dash"
8-
"github.com/TBXark/sphere/internal/server/docs"
97
"github.com/TBXark/sphere/pkg/utils/boot"
108
)
119

1210
func main() {
13-
app.Execute(NewApplication)
14-
}
15-
16-
func newApplication(dash *dash.Web, api *api.Web, docs *docs.Web, initialize *task.DashInitialize, cleaner *task.ConnectCleaner) *boot.Application {
17-
return boot.NewApplication(
18-
dash,
19-
api,
20-
docs,
21-
initialize,
22-
cleaner,
23-
)
11+
mode := flag.String("mode", "app", "run mode: app, api, dash, bot")
12+
app.Execute(func(config *config.Config) (*boot.Application, error) {
13+
switch *mode {
14+
case "api":
15+
return NewAPIApplication(config)
16+
case "dash":
17+
return NewDashApplication(config)
18+
case "bot":
19+
return NewBotApplication(config)
20+
default:
21+
return NewApplication(config)
22+
}
23+
})
2424
}

cmd/app/wire.go

+15
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,18 @@ func NewApplication(conf *config.Config) (*boot.Application, error) {
1414
wire.Build(internal.ProviderSet, wire.NewSet(newApplication))
1515
return &boot.Application{}, nil
1616
}
17+
18+
func NewAPIApplication(conf *config.Config) (*boot.Application, error) {
19+
wire.Build(internal.ProviderSet, wire.NewSet(newAPIApplication))
20+
return &boot.Application{}, nil
21+
}
22+
23+
func NewDashApplication(conf *config.Config) (*boot.Application, error) {
24+
wire.Build(internal.ProviderSet, wire.NewSet(newDashApplication))
25+
return &boot.Application{}, nil
26+
}
27+
28+
func NewBotApplication(conf *config.Config) (*boot.Application, error) {
29+
wire.Build(internal.ProviderSet, wire.NewSet(newBotApplication))
30+
return &boot.Application{}, nil
31+
}

cmd/app/wire_gen.go

+52
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/bot/Dockerfile

-14
This file was deleted.

cmd/bot/main.go

-15
This file was deleted.

cmd/bot/wire.go

-16
This file was deleted.

cmd/bot/wire_gen.go

-24
This file was deleted.

cmd/dash/Dockerfile

-14
This file was deleted.

cmd/dash/main.go

-20
This file was deleted.

cmd/dash/wire.go

-16
This file was deleted.

0 commit comments

Comments
 (0)