2
This commit is contained in:
@@ -3,30 +3,22 @@ package common
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
commonv1 "management/internal/erpserver/biz/v1/common"
|
||||
v1 "management/internal/erpserver/service/v1"
|
||||
"management/internal/pkg/config"
|
||||
"management/internal/pkg/tpl"
|
||||
)
|
||||
|
||||
type CaptchaHandler interface {
|
||||
Captcha(w http.ResponseWriter, r *http.Request)
|
||||
}
|
||||
|
||||
// captchaHandler 是 CaptchaHandler 接口的实现.
|
||||
type captchaHandler struct {
|
||||
conf *config.Captcha
|
||||
render tpl.Renderer
|
||||
biz commonv1.CaptchaBiz
|
||||
svc v1.CaptchaService
|
||||
}
|
||||
|
||||
// 确保 captchaHandler 实现了 CaptchaHandler 接口.
|
||||
var _ CaptchaHandler = (*captchaHandler)(nil)
|
||||
|
||||
func NewCaptchaHandler(conf *config.Captcha, render tpl.Renderer, biz commonv1.CaptchaBiz) *captchaHandler {
|
||||
func NewCaptchaHandler(conf *config.Captcha, render tpl.Renderer, svc v1.CaptchaService) *captchaHandler {
|
||||
return &captchaHandler{
|
||||
conf: conf,
|
||||
render: render,
|
||||
biz: biz,
|
||||
svc: svc,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +32,7 @@ type CaptchaResponse struct {
|
||||
func (h *captchaHandler) Captcha(w http.ResponseWriter, r *http.Request) {
|
||||
keyLong := h.conf.KeyLong
|
||||
oc := h.conf.OpenCaptcha
|
||||
id, b64s, _, err := h.biz.Generate(h.conf.ImgHeight, h.conf.ImgWidth, keyLong, 0.7, 80)
|
||||
id, b64s, _, err := h.svc.Generate(h.conf.ImgHeight, h.conf.ImgWidth, keyLong, 0.7, 80)
|
||||
if err != nil {
|
||||
h.render.JSON(w, tpl.Response{Success: false, Message: "获取验证码失败"})
|
||||
return
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
commonv1 "management/internal/erpserver/biz/v1/common"
|
||||
"management/internal/pkg/config"
|
||||
"management/internal/pkg/tpl"
|
||||
)
|
||||
|
||||
type CommonHandler interface {
|
||||
CaptchaHandler() CaptchaHandler
|
||||
UploadHandler() UploadHandler
|
||||
}
|
||||
|
||||
type commonHandler struct {
|
||||
conf *config.Config
|
||||
render tpl.Renderer
|
||||
biz commonv1.CommonBiz
|
||||
}
|
||||
|
||||
var _ CommonHandler = (*commonHandler)(nil)
|
||||
|
||||
func NewCommonHandler(conf *config.Config, render tpl.Renderer, biz commonv1.CommonBiz) *commonHandler {
|
||||
return &commonHandler{
|
||||
conf: conf,
|
||||
render: render,
|
||||
biz: biz,
|
||||
}
|
||||
}
|
||||
|
||||
func (h *commonHandler) CaptchaHandler() CaptchaHandler {
|
||||
return NewCaptchaHandler(&h.conf.Captcha, h.render, h.biz.CaptchaBiz())
|
||||
}
|
||||
|
||||
func (h *commonHandler) UploadHandler() UploadHandler {
|
||||
return NewUploadHandler(h.render)
|
||||
}
|
||||
@@ -8,18 +8,10 @@ import (
|
||||
"management/internal/pkg/tpl"
|
||||
)
|
||||
|
||||
type UploadHandler interface {
|
||||
Img(w http.ResponseWriter, r *http.Request)
|
||||
File(w http.ResponseWriter, r *http.Request)
|
||||
MutilFiles(w http.ResponseWriter, r *http.Request)
|
||||
}
|
||||
|
||||
type uploadHandler struct {
|
||||
render tpl.Renderer
|
||||
}
|
||||
|
||||
var _ UploadHandler = (*uploadHandler)(nil)
|
||||
|
||||
func NewUploadHandler(render tpl.Renderer) *uploadHandler {
|
||||
return &uploadHandler{
|
||||
render: render,
|
||||
|
||||
Reference in New Issue
Block a user