github.com/kotovmak/go-admin@v1.1.1/plugins/admin/controller/delete.go (about)

     1  package controller
     2  
     3  import (
     4  	"github.com/kotovmak/go-admin/context"
     5  	"github.com/kotovmak/go-admin/modules/logger"
     6  	"github.com/kotovmak/go-admin/plugins/admin/modules/guard"
     7  	"github.com/kotovmak/go-admin/plugins/admin/modules/response"
     8  )
     9  
    10  // Delete delete the row from database.
    11  func (h *Handler) Delete(ctx *context.Context) {
    12  
    13  	param := guard.GetDeleteParam(ctx)
    14  
    15  	//token := ctx.FormValue("_t")
    16  	//
    17  	//if !auth.TokenHelper.CheckToken(token) {
    18  	//	ctx.SetStatusCode(http.StatusBadRequest)
    19  	//	ctx.WriteString(`{"code":400, "msg":"delete fail"}`)
    20  	//	return
    21  	//}
    22  
    23  	if err := h.table(param.Prefix, ctx).DeleteData(param.Id); err != nil {
    24  		logger.Error(err)
    25  		response.Error(ctx, "delete fail")
    26  		return
    27  	}
    28  
    29  	response.OkWithData(ctx, map[string]interface{}{
    30  		"token": h.authSrv().AddToken(),
    31  	})
    32  }