Skip to content

Commit

Permalink
chore: 简化入口函数
Browse files Browse the repository at this point in the history
  • Loading branch information
TBXark committed Jan 2, 2025
1 parent 5963b8c commit 001c33c
Show file tree
Hide file tree
Showing 16 changed files with 122 additions and 270 deletions.
14 changes: 0 additions & 14 deletions cmd/api/Dockerfile

This file was deleted.

20 changes: 0 additions & 20 deletions cmd/api/main.go

This file was deleted.

16 changes: 0 additions & 16 deletions cmd/api/wire.go

This file was deleted.

43 changes: 0 additions & 43 deletions cmd/api/wire_gen.go

This file was deleted.

40 changes: 40 additions & 0 deletions cmd/app/builder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package main

import (
"github.com/TBXark/sphere/internal/biz/task"
"github.com/TBXark/sphere/internal/server/api"
"github.com/TBXark/sphere/internal/server/bot"
"github.com/TBXark/sphere/internal/server/dash"
"github.com/TBXark/sphere/internal/server/docs"
"github.com/TBXark/sphere/pkg/utils/boot"
)

func newApplication(dash *dash.Web, api *api.Web, docs *docs.Web, initialize *task.DashInitialize, cleaner *task.ConnectCleaner) *boot.Application {
return boot.NewApplication(
dash,
api,
docs,
initialize,
cleaner,
)
}

func newAPIApplication(api *api.Web, initialize *task.DashInitialize, cleaner *task.ConnectCleaner) *boot.Application {
return boot.NewApplication(
api,
initialize,
cleaner,
)
}

func newDashApplication(dash *dash.Web, initialize *task.DashInitialize, cleaner *task.ConnectCleaner) *boot.Application {
return boot.NewApplication(
dash,
initialize,
cleaner,
)
}

func newBotApplication(app *bot.Bot) *boot.Application {
return boot.NewApplication(app)
}
30 changes: 15 additions & 15 deletions cmd/app/main.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
package main

import (
"github.com/TBXark/sphere/internal/biz/task"
"flag"
"github.com/TBXark/sphere/internal/config"
"github.com/TBXark/sphere/internal/pkg/app"
"github.com/TBXark/sphere/internal/server/api"
"github.com/TBXark/sphere/internal/server/dash"
"github.com/TBXark/sphere/internal/server/docs"
"github.com/TBXark/sphere/pkg/utils/boot"
)

func main() {
app.Execute(NewApplication)
}

func newApplication(dash *dash.Web, api *api.Web, docs *docs.Web, initialize *task.DashInitialize, cleaner *task.ConnectCleaner) *boot.Application {
return boot.NewApplication(
dash,
api,
docs,
initialize,
cleaner,
)
mode := flag.String("mode", "app", "run mode: app, api, dash, bot")
app.Execute(func(config *config.Config) (*boot.Application, error) {
switch *mode {
case "api":
return NewAPIApplication(config)
case "dash":
return NewDashApplication(config)
case "bot":
return NewBotApplication(config)
default:
return NewApplication(config)
}
})
}
15 changes: 15 additions & 0 deletions cmd/app/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,18 @@ func NewApplication(conf *config.Config) (*boot.Application, error) {
wire.Build(internal.ProviderSet, wire.NewSet(newApplication))
return &boot.Application{}, nil
}

func NewAPIApplication(conf *config.Config) (*boot.Application, error) {
wire.Build(internal.ProviderSet, wire.NewSet(newAPIApplication))
return &boot.Application{}, nil
}

func NewDashApplication(conf *config.Config) (*boot.Application, error) {
wire.Build(internal.ProviderSet, wire.NewSet(newDashApplication))
return &boot.Application{}, nil
}

func NewBotApplication(conf *config.Config) (*boot.Application, error) {
wire.Build(internal.ProviderSet, wire.NewSet(newBotApplication))
return &boot.Application{}, nil
}
52 changes: 52 additions & 0 deletions cmd/app/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 0 additions & 14 deletions cmd/bot/Dockerfile

This file was deleted.

15 changes: 0 additions & 15 deletions cmd/bot/main.go

This file was deleted.

16 changes: 0 additions & 16 deletions cmd/bot/wire.go

This file was deleted.

24 changes: 0 additions & 24 deletions cmd/bot/wire_gen.go

This file was deleted.

14 changes: 0 additions & 14 deletions cmd/dash/Dockerfile

This file was deleted.

20 changes: 0 additions & 20 deletions cmd/dash/main.go

This file was deleted.

16 changes: 0 additions & 16 deletions cmd/dash/wire.go

This file was deleted.

Loading

0 comments on commit 001c33c

Please sign in to comment.