fusenapi/server/feishu-sync/internal/handler/webhookhandler.go
laodaming 03af6aa70e fix
2023-11-06 18:25:37 +08:00

44 lines
953 B
Go

package handler
import (
"encoding/json"
"net/http"
"reflect"
"fusenapi/utils/basic"
"fusenapi/server/feishu-sync/internal/logic"
"fusenapi/server/feishu-sync/internal/svc"
"fusenapi/server/feishu-sync/internal/types"
)
func WebhookHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.WebhookReq
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
if err != nil {
return
}
//验证连接(直接返回)
if req.Type == "url_verification" {
challengeRsp := map[string]string{
"challenge": req.Challenge,
}
b, _ := json.Marshal(challengeRsp)
w.Write(b)
return
}
// 创建一个业务逻辑层实例
l := logic.NewWebhookLogic(r.Context(), svcCtx)
rl := reflect.ValueOf(l)
basic.BeforeLogic(w, r, rl)
resp := l.Webhook(&req, userinfo)
if !basic.AfterLogic(w, r, rl, resp) {
basic.NormalAfterLogic(w, r, resp)
}
}
}