代码拉取完成,页面将自动刷新
package notify
import "github.com/humpback/gounits/httpx"
import "github.com/humpback/gounits/logger"
import (
"context"
"time"
"net"
"net/http"
)
// APIEndPoint is exported
type APIEndPoint struct {
IEndPoint
EndPoint
client *httpx.HttpClient
}
// NewAPIEndPoint is exported
func NewAPIEndPoint(endpoint EndPoint) IEndPoint {
client := httpx.NewClient().
SetTransport(&http.Transport{
Proxy: http.ProxyFromEnvironment,
DialContext: (&net.Dialer{
Timeout: 45 * time.Second,
KeepAlive: 90 * time.Second,
}).DialContext,
DisableKeepAlives: false,
MaxIdleConns: 10,
MaxIdleConnsPerHost: 10,
IdleConnTimeout: 90 * time.Second,
TLSHandshakeTimeout: http.DefaultTransport.(*http.Transport).TLSHandshakeTimeout,
ExpectContinueTimeout: http.DefaultTransport.(*http.Transport).ExpectContinueTimeout,
})
return &APIEndPoint{
EndPoint: endpoint,
client: client,
}
}
// DoEvent is exported
func (endpoint *APIEndPoint) DoEvent(event *Event, data interface{}) {
if !endpoint.Enabled {
return
}
value := map[string]interface{}{
"From": endpoint.Sender,
"To": event.ContactInfo,
"Subject": event.makeSubjectText(),
"Body": data,
"ContentType": "HTML",
"MailType": "Smtp",
"SmtpSetting": map[string]interface{}{},
}
response, err := endpoint.client.PostJSON(context.Background(), endpoint.URL, nil, value, endpoint.Headers)
if err != nil {
logger.ERROR("[#notify#] api endpoint error: %s", err.Error())
return
}
defer response.Close()
if response.StatusCode() >= http.StatusBadRequest {
logger.ERROR("[#notify#] api endpoint response code: %d", response.StatusCode())
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。