60 lines
995 B
Go
60 lines
995 B
Go
package mods
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/guxuan/hailin_service/internal/config"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/google/wire"
|
|
"github.com/guxuan/hailin_service/internal/mods/rbac"
|
|
)
|
|
|
|
const (
|
|
apiPrefix = "/api/"
|
|
)
|
|
|
|
// Collection of wire providers
|
|
var Set = wire.NewSet(
|
|
wire.Struct(new(Mods), "*"),
|
|
rbac.Set,
|
|
)
|
|
|
|
type Mods struct {
|
|
RBAC *rbac.RBAC
|
|
}
|
|
|
|
func (a *Mods) Init(ctx context.Context) error {
|
|
if err := a.RBAC.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)
|
|
e.Static(config.C.FileConfig.StaticPrefix, config.C.FileConfig.UploadDir)
|
|
v1 := gAPI.Group("v1")
|
|
|
|
if err := a.RBAC.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
|
|
}
|
|
|
|
return nil
|
|
}
|