136 lines
2.6 KiB
Go
136 lines
2.6 KiB
Go
package mods
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/google/wire"
|
|
"gitlab.guxuan.icu/jinshan_community/internal/mods/activity"
|
|
"gitlab.guxuan.icu/jinshan_community/internal/mods/ai"
|
|
"gitlab.guxuan.icu/jinshan_community/internal/mods/app"
|
|
"gitlab.guxuan.icu/jinshan_community/internal/mods/common"
|
|
"gitlab.guxuan.icu/jinshan_community/internal/mods/customer"
|
|
"gitlab.guxuan.icu/jinshan_community/internal/mods/product"
|
|
"gitlab.guxuan.icu/jinshan_community/internal/mods/rbac"
|
|
)
|
|
|
|
const (
|
|
apiPrefix = "/api/"
|
|
)
|
|
|
|
// Collection of wire providers
|
|
var Set = wire.NewSet(
|
|
wire.Struct(new(Mods), "*"),
|
|
rbac.Set,
|
|
customer.Set,
|
|
common.Set,
|
|
activity.Set,
|
|
product.Set,
|
|
app.Set,
|
|
ai.Set,
|
|
)
|
|
|
|
type Mods struct {
|
|
RBAC *rbac.RBAC
|
|
Customer *customer.Customer
|
|
Common *common.Common
|
|
Activity *activity.Activity
|
|
Product *product.Product
|
|
App *app.App
|
|
Ai *ai.Ai
|
|
}
|
|
|
|
func (a *Mods) Init(ctx context.Context) error {
|
|
if err := a.RBAC.Init(ctx); err != nil {
|
|
return err
|
|
}
|
|
if err := a.Customer.Init(
|
|
ctx); err != nil {
|
|
return err
|
|
}
|
|
if err := a.Common.Init(
|
|
ctx); err != nil {
|
|
return err
|
|
}
|
|
if err := a.Activity.Init(ctx); err != nil {
|
|
return err
|
|
}
|
|
if err := a.Product.Init(ctx); err != nil {
|
|
return err
|
|
}
|
|
if err := a.App.Init(ctx); err != nil {
|
|
return err
|
|
}
|
|
if err := a.Ai.Init(ctx); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (a *Mods) RouterPrefixes() []string {
|
|
return []string{
|
|
apiPrefix,
|
|
}
|
|
}
|
|
|
|
func (a *Mods) RegisterRouters(ctx context.Context, e *gin.Engine) error {
|
|
gAPI := e.Group(apiPrefix)
|
|
v1 := gAPI.Group("v1")
|
|
|
|
if err := a.RBAC.RegisterV1Routers(ctx, v1); err != nil {
|
|
return err
|
|
}
|
|
if err := a.Customer.RegisterV1Routers(ctx, v1); err != nil {
|
|
return err
|
|
}
|
|
if err := a.Common.RegisterV1Routers(ctx, v1); err != nil {
|
|
return err
|
|
}
|
|
if err := a.Activity.RegisterV1Routers(ctx,
|
|
v1,
|
|
); err != nil {
|
|
return err
|
|
}
|
|
if err := a.Product.RegisterV1Routers(ctx, v1); err != nil {
|
|
return err
|
|
}
|
|
if err := a.App.RegisterV1Routers(ctx, v1); err != nil {
|
|
return err
|
|
}
|
|
if err := a.Ai.RegisterV1Routers(ctx, v1); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (a *Mods) Release(ctx context.Context) error {
|
|
if err := a.RBAC.Release(ctx); err != nil {
|
|
return err
|
|
}
|
|
if err := a.Customer.Release(ctx); err != nil {
|
|
return err
|
|
}
|
|
if err := a.Common.Release(ctx); err != nil {
|
|
return err
|
|
}
|
|
if err := a.Activity.Release(ctx); err != nil {
|
|
return err
|
|
}
|
|
if err := a.Product.Release(ctx); err != nil {
|
|
return err
|
|
}
|
|
if err := a.App.Release(
|
|
ctx); err != nil {
|
|
return err
|
|
}
|
|
if err := a.Ai.Release(
|
|
ctx,
|
|
); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|