代码拉取完成,页面将自动刷新
package hooks
import (
"net/http"
"github.com/rancher/types/config"
"github.com/sirupsen/logrus"
"k8s.io/apimachinery/pkg/util/json"
)
type WebhookHandler struct {
}
func New(management *config.ScaledContext) *WebhookHandler {
webhookHandler := &WebhookHandler{}
webhookHandler.initDrivers(management)
return webhookHandler
}
func (h *WebhookHandler) initDrivers(management *config.ScaledContext) {
RegisterDrivers(management)
}
func (h *WebhookHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
for key, driver := range Drivers {
if exist := req.Header.Get(key); exist != "" {
code, err := driver.Execute(req)
if err != nil {
e := map[string]interface{}{
"type": "error",
"code": code,
"message": err.Error(),
}
logrus.Debugf("executing %s driver got error: %v", key, err)
rw.WriteHeader(code)
responseBody, _ := json.Marshal(e)
rw.Write(responseBody)
}
rw.WriteHeader(http.StatusOK)
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。