feat: add new module cmd
This commit is contained in:
16
templates/module/controller.go.tpl
Normal file
16
templates/module/controller.go.tpl
Normal file
@@ -0,0 +1,16 @@
|
||||
package {{.ModuleName}}
|
||||
|
||||
import (
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// @provider
|
||||
type Controller struct {
|
||||
svc *Service
|
||||
log *log.Entry `inject:"false"`
|
||||
}
|
||||
|
||||
func (c *Controller) Prepare() error {
|
||||
c.log = log.WithField("module", "{{.ModuleName}}.Controller")
|
||||
return nil
|
||||
}
|
||||
1
templates/module/dto.go.tpl
Normal file
1
templates/module/dto.go.tpl
Normal file
@@ -0,0 +1 @@
|
||||
package {{.ModuleName}}
|
||||
9
templates/module/provider.gen.go.tpl
Executable file
9
templates/module/provider.gen.go.tpl
Executable file
@@ -0,0 +1,9 @@
|
||||
package {{.ModuleName}}
|
||||
|
||||
import (
|
||||
"git.ipao.vip/rogeecn/atom/utils/opt"
|
||||
)
|
||||
|
||||
func Provide(opts ...opt.Option) error {
|
||||
return nil
|
||||
}
|
||||
29
templates/module/router.go.tpl
Executable file
29
templates/module/router.go.tpl
Executable file
@@ -0,0 +1,29 @@
|
||||
package {{.ModuleName}}
|
||||
|
||||
import (
|
||||
_ "git.ipao.vip/rogeecn/atom"
|
||||
_ "git.ipao.vip/rogeecn/atom/contracts"
|
||||
"github.com/gofiber/fiber/v3"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// @provider:except contracts.HttpRoute atom.GroupRoutes
|
||||
type Router struct {
|
||||
log *log.Entry `inject:"false"`
|
||||
|
||||
controller *Controller
|
||||
}
|
||||
|
||||
func (r *Router) Name() string {
|
||||
return "{{.ModuleName}}"
|
||||
}
|
||||
|
||||
func (r *Router) Prepare() error {
|
||||
r.log = log.WithField("http.group", r.Name())
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *Router) Register(router fiber.Router) {
|
||||
group := router.Group(r.Name())
|
||||
_ = group
|
||||
}
|
||||
20
templates/module/service.go.tpl
Normal file
20
templates/module/service.go.tpl
Normal file
@@ -0,0 +1,20 @@
|
||||
package {{.ModuleName}}
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
|
||||
. "github.com/go-jet/jet/v2/postgres"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// @provider:except
|
||||
type Service struct {
|
||||
db *sql.DB
|
||||
log *log.Entry `inject:"false"`
|
||||
}
|
||||
|
||||
func (svc *Service) Prepare() error {
|
||||
svc.log = log.WithField("module", "{{.ModuleName}}.service")
|
||||
_ = Int(1)
|
||||
return nil
|
||||
}
|
||||
37
templates/module/service_test.go.tpl
Normal file
37
templates/module/service_test.go.tpl
Normal file
@@ -0,0 +1,37 @@
|
||||
package {{.ModuleName}}
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"backend/pkg/service/testx"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
"github.com/stretchr/testify/suite"
|
||||
"go.uber.org/dig"
|
||||
)
|
||||
|
||||
type ServiceInjectParams struct {
|
||||
dig.In
|
||||
Svc *Service
|
||||
}
|
||||
|
||||
type ServiceTestSuite struct {
|
||||
suite.Suite
|
||||
ServiceInjectParams
|
||||
}
|
||||
|
||||
func Test_DiscoverMedias(t *testing.T) {
|
||||
providers := testx.Default().With(
|
||||
Provide,
|
||||
)
|
||||
|
||||
testx.Serve(providers, t, func(params ServiceInjectParams) {
|
||||
suite.Run(t, &ServiceTestSuite{ServiceInjectParams: params})
|
||||
})
|
||||
}
|
||||
|
||||
func (s *ServiceTestSuite) Test_Service() {
|
||||
Convey("Test Service", s.T(), func() {
|
||||
So(s.Svc, ShouldNotBeNil)
|
||||
})
|
||||
}
|
||||
@@ -4,3 +4,6 @@ import "embed"
|
||||
|
||||
//go:embed project
|
||||
var Project embed.FS
|
||||
|
||||
//go:embed module
|
||||
var Module embed.FS
|
||||
|
||||
Reference in New Issue
Block a user