casdoor/object/webhook_util.go

43 lines
1.1 KiB
Go
Raw Normal View History

2021-11-07 23:53:17 +08:00
// Copyright 2021 The casbin Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package object
import (
"net/http"
"strings"
2022-01-20 14:11:46 +08:00
"github.com/casdoor/casdoor/util"
2021-11-07 23:53:17 +08:00
)
func sendWebhook(webhook *Webhook, record *Record) error {
client := &http.Client{}
body := strings.NewReader(util.StructToJson(record))
2021-12-26 19:56:02 +08:00
req, err := http.NewRequest(webhook.Method, webhook.Url, body)
2021-11-07 23:53:17 +08:00
if err != nil {
return err
}
req.Header.Set("Content-Type", webhook.ContentType)
2021-12-26 20:40:13 +08:00
for _, header := range webhook.Headers {
req.Header.Set(header.Name, header.Value)
}
2021-11-07 23:53:17 +08:00
_, err = client.Do(req)
return err
}