to options mode

This commit is contained in:
yanghao05
2023-04-27 18:30:39 +08:00
parent 8ae3d19aa9
commit 574736a878
20 changed files with 180 additions and 50 deletions

View File

@@ -5,9 +5,9 @@ import (
"time"
"github.com/rogeecn/atom/container"
"github.com/rogeecn/atom/providers"
"github.com/rogeecn/atom/providers/http"
"github.com/rogeecn/atom/providers/log"
"go.uber.org/dig"
"github.com/gin-gonic/gin"
)
@@ -32,7 +32,12 @@ func (e *Service) Serve() error {
return e.Engine.Run(e.conf.PortString())
}
func Provide(cfg *http.Config, opts ...dig.ProvideOption) error {
func Provide(o *providers.Options) error {
var config http.Config
if err := o.UnmarshalConfig(&config); err != nil {
log.Fatal(err)
}
return container.Container.Provide(func() (http.Service, error) {
gin.DefaultWriter = log.LevelWriter{Level: log.InfoLevel}
gin.DefaultErrorWriter = log.LevelWriter{Level: log.ErrorLevel}
@@ -53,6 +58,6 @@ func Provide(cfg *http.Config, opts ...dig.ProvideOption) error {
)
}))
return &Service{Engine: engine, conf: cfg}, nil
}, opts...)
return &Service{Engine: engine, conf: &config}, nil
}, o.DiOptions()...)
}