37 Star 395 Fork 72

GVPrancher/rancher

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
Clone or Download
handler.go 981 Bytes
Copy Edit Raw Blame History
phli authored 2018-02-13 21:33 . add pipeline support
package hooks
import (
"github.com/rancher/types/config"
"github.com/sirupsen/logrus"
"k8s.io/apimachinery/pkg/util/json"
"net/http"
)
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.Errorf("executing %s driver got error: %v", key, err)
rw.WriteHeader(code)
responseBody, _ := json.Marshal(e)
rw.Write(responseBody)
}
rw.WriteHeader(http.StatusOK)
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rancher/rancher.git
git@gitee.com:rancher/rancher.git
rancher
rancher
rancher
v2.0.8-rc6

Search

Cb406eda 1850385 E526c682 1850385