45 lines
849 B
Go
45 lines
849 B
Go
package app
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.guxuan/haibei/internal/config"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.guxuan/haibei/internal/mods/app/api"
|
|
"github.guxuan/haibei/internal/mods/app/schema"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type App struct {
|
|
DB *gorm.DB
|
|
AppAPI *api.App
|
|
}
|
|
|
|
func (a *App) AutoMigrate(ctx context.Context) error {
|
|
return a.DB.AutoMigrate(new(schema.App))
|
|
}
|
|
|
|
func (a *App) Init(ctx context.Context) error {
|
|
if config.C.Storage.DB.AutoMigrate {
|
|
if err := a.AutoMigrate(ctx); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (a *App) RegisterV1Routers(ctx context.Context, v1 *gin.RouterGroup) error {
|
|
app := v1.Group("apps")
|
|
{
|
|
app.POST("login", a.AppAPI.Login)
|
|
app.GET("sms/:phone", a.AppAPI.SendSms)
|
|
app.POST("bind", a.AppAPI.BindPhone)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (a *App) Release(ctx context.Context) error {
|
|
return nil
|
|
}
|