restructure
This commit is contained in:
24
services/http.go
Normal file
24
services/http.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package http
|
||||
|
||||
import (
|
||||
"github.com/rogeecn/atom/container"
|
||||
"github.com/rogeecn/atom/providers/http"
|
||||
"go.uber.org/dig"
|
||||
)
|
||||
|
||||
type Http struct {
|
||||
dig.In
|
||||
|
||||
Service http.Service
|
||||
Routes []http.Route `group:"route"`
|
||||
}
|
||||
|
||||
func ServeHttp() error {
|
||||
return container.Container.Invoke(func(http Http) error {
|
||||
for _, route := range http.Routes {
|
||||
route.Register()
|
||||
}
|
||||
|
||||
return http.Service.Serve()
|
||||
})
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
package http
|
||||
|
||||
import (
|
||||
_ "atom/modules"
|
||||
|
||||
"atom/contracts"
|
||||
"atom/providers/config"
|
||||
"atom/providers/http"
|
||||
"atom/providers/log"
|
||||
|
||||
"go.uber.org/dig"
|
||||
)
|
||||
|
||||
type Http struct {
|
||||
dig.In
|
||||
|
||||
Conf *config.Config
|
||||
Service *http.Service
|
||||
Routes []contracts.Route `group:"route"`
|
||||
}
|
||||
|
||||
func Serve(http Http) error {
|
||||
log.Infof("http service port %s", http.Conf.Http.Address())
|
||||
for _, route := range http.Routes {
|
||||
route.Register()
|
||||
}
|
||||
|
||||
log.Infof("starting server on %s", http.Conf.Http.Address())
|
||||
return http.Service.Serve()
|
||||
}
|
||||
Reference in New Issue
Block a user