package logic import ( "context" "fusenapi/server/collection/internal/svc" "fusenapi/server/collection/internal/types" "fusenapi/utils/auth" "fusenapi/utils/basic" "fusenapi/utils/pdf" "github.com/zeromicro/go-zero/core/logx" ) type TestPdfLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext } func NewTestPdfLogic(ctx context.Context, svcCtx *svc.ServiceContext) *TestPdfLogic { return &TestPdfLogic{ Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx, } } // 处理进入前逻辑w,r // func (l *TestPdfLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) { // } func (l *TestPdfLogic) TestPdf(req *types.TestPdfReq, userinfo *auth.UserInfo) (resp *basic.Response) { switch req.Type { case "url": case "html": default: return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "invalid type") } res, err := pdf.HtmlToPdfBase64(req.Content, req.Type) if err != nil { return resp.SetStatusWithMessage(basic.CodeServiceErr, err.Error()) } return resp.SetStatus(basic.CodeOK, res) } // 处理逻辑后 w,r 如:重定向, resp 必须重新处理 // func (l *TestPdfLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) { // // httpx.OkJsonCtx(r.Context(), w, resp) // }