Files
EdgeNode/internal/nodes/http_client.go

41 lines
816 B
Go
Raw Normal View History

2020-09-27 15:26:06 +08:00
package nodes
import (
"github.com/TeaOSLab/EdgeNode/internal/utils/fasttime"
2020-09-27 15:26:06 +08:00
"net/http"
)
2021-04-19 19:29:32 +08:00
// HTTPClient HTTP客户端
2020-09-27 15:26:06 +08:00
type HTTPClient struct {
rawClient *http.Client
accessAt int64
}
2021-04-19 19:29:32 +08:00
// NewHTTPClient 获取新客户端对象
2020-09-27 15:26:06 +08:00
func NewHTTPClient(rawClient *http.Client) *HTTPClient {
return &HTTPClient{
rawClient: rawClient,
accessAt: fasttime.Now().Unix(),
2020-09-27 15:26:06 +08:00
}
}
2021-04-19 19:29:32 +08:00
// RawClient 获取原始客户端对象
2020-09-27 15:26:06 +08:00
func (this *HTTPClient) RawClient() *http.Client {
return this.rawClient
}
2021-04-19 19:29:32 +08:00
// UpdateAccessTime 更新访问时间
2020-09-27 15:26:06 +08:00
func (this *HTTPClient) UpdateAccessTime() {
this.accessAt = fasttime.Now().Unix()
2020-09-27 15:26:06 +08:00
}
2021-04-19 19:29:32 +08:00
// AccessTime 获取访问时间
2020-09-27 15:26:06 +08:00
func (this *HTTPClient) AccessTime() int64 {
return this.accessAt
}
2021-04-19 19:29:32 +08:00
// Close 关闭
2020-09-27 15:26:06 +08:00
func (this *HTTPClient) Close() {
this.rawClient.CloseIdleConnections()
}