mirror of https://github.com/go-sonic/sonic.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
989 B
Go
41 lines
989 B
Go
package admin
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/go-playground/validator/v10"
|
|
|
|
"github.com/go-sonic/sonic/handler/trans"
|
|
"github.com/go-sonic/sonic/model/param"
|
|
"github.com/go-sonic/sonic/service"
|
|
"github.com/go-sonic/sonic/util/xerr"
|
|
)
|
|
|
|
type InstallHandler struct {
|
|
InstallService service.InstallService
|
|
}
|
|
|
|
func NewInstallHandler(installService service.InstallService) *InstallHandler {
|
|
return &InstallHandler{
|
|
InstallService: installService,
|
|
}
|
|
}
|
|
|
|
func (i *InstallHandler) InstallBlog(ctx *gin.Context) (interface{}, error) {
|
|
var installParam param.Install
|
|
err := ctx.ShouldBindJSON(&installParam)
|
|
if err != nil {
|
|
e := validator.ValidationErrors{}
|
|
if errors.As(err, &e) {
|
|
return nil, xerr.WithStatus(e, xerr.StatusBadRequest).WithMsg(trans.Translate(e))
|
|
}
|
|
return nil, xerr.WithStatus(err, xerr.StatusBadRequest)
|
|
}
|
|
err = i.InstallService.InstallBlog(ctx, installParam)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return "安装完成", nil
|
|
}
|