feat: update framework

This commit is contained in:
Rogee
2024-11-29 15:03:47 +08:00
parent f7d95418a2
commit 391f217bd8
17 changed files with 368 additions and 132 deletions

View File

@@ -0,0 +1,42 @@
package http
import (
"backend/providers/app"
"backend/providers/http/fiber"
"git.ipao.vip/rogeecn/atom"
"git.ipao.vip/rogeecn/atom/container"
"git.ipao.vip/rogeecn/atom/contracts"
"github.com/spf13/cobra"
"go.uber.org/dig"
)
func Default(providers ...container.ProviderContainer) container.Providers {
return append(container.Providers{
app.DefaultProvider(),
fiber.DefaultProvider(),
}, providers...)
}
func Command() atom.Option {
return atom.Command(
atom.Name("serve"),
atom.Short("run http server"),
atom.RunE(Serve),
atom.Providers(Default()),
)
}
type Http struct {
dig.In
Service contracts.HttpService
Initials []contracts.Initial `group:"initials"`
Routes []contracts.HttpRoute `group:"routes"`
}
func Serve(cmd *cobra.Command, args []string) error {
return container.Container.Invoke(func(http Http) error {
return http.Service.Serve()
})
}