标准化一些注释

This commit is contained in:
GoEdgeLab
2021-04-19 19:29:32 +08:00
parent cf52510399
commit 724f498260
4 changed files with 16 additions and 14 deletions

View File

@@ -1,6 +1,8 @@
package caches package caches
import "compress/gzip" import (
"compress/gzip"
)
type gzipWriter struct { type gzipWriter struct {
rawWriter Writer rawWriter Writer

View File

@@ -5,13 +5,13 @@ import (
"net/http" "net/http"
) )
// HTTP客户端 // HTTPClient HTTP客户端
type HTTPClient struct { type HTTPClient struct {
rawClient *http.Client rawClient *http.Client
accessAt int64 accessAt int64
} }
// 获取新客户端对象 // NewHTTPClient 获取新客户端对象
func NewHTTPClient(rawClient *http.Client) *HTTPClient { func NewHTTPClient(rawClient *http.Client) *HTTPClient {
return &HTTPClient{ return &HTTPClient{
rawClient: rawClient, rawClient: rawClient,
@@ -19,22 +19,22 @@ func NewHTTPClient(rawClient *http.Client) *HTTPClient {
} }
} }
// 获取原始客户端对象 // RawClient 获取原始客户端对象
func (this *HTTPClient) RawClient() *http.Client { func (this *HTTPClient) RawClient() *http.Client {
return this.rawClient return this.rawClient
} }
// 更新访问时间 // UpdateAccessTime 更新访问时间
func (this *HTTPClient) UpdateAccessTime() { func (this *HTTPClient) UpdateAccessTime() {
this.accessAt = utils.UnixTime() this.accessAt = utils.UnixTime()
} }
// 获取访问时间 // AccessTime 获取访问时间
func (this *HTTPClient) AccessTime() int64 { func (this *HTTPClient) AccessTime() int64 {
return this.accessAt return this.accessAt
} }
// 关闭 // Close 关闭
func (this *HTTPClient) Close() { func (this *HTTPClient) Close() {
this.rawClient.CloseIdleConnections() this.rawClient.CloseIdleConnections()
} }

View File

@@ -14,17 +14,17 @@ import (
"time" "time"
) )
// HTTP客户端池单例 // SharedHTTPClientPool HTTP客户端池单例
var SharedHTTPClientPool = NewHTTPClientPool() var SharedHTTPClientPool = NewHTTPClientPool()
// 客户端池 // HTTPClientPool 客户端池
type HTTPClientPool struct { type HTTPClientPool struct {
clientExpiredDuration time.Duration clientExpiredDuration time.Duration
clientsMap map[string]*HTTPClient // backend key => client clientsMap map[string]*HTTPClient // backend key => client
locker sync.Mutex locker sync.Mutex
} }
// 获取新对象 // NewHTTPClientPool 获取新对象
func NewHTTPClientPool() *HTTPClientPool { func NewHTTPClientPool() *HTTPClientPool {
pool := &HTTPClientPool{ pool := &HTTPClientPool{
clientExpiredDuration: 3600 * time.Second, clientExpiredDuration: 3600 * time.Second,
@@ -36,7 +36,7 @@ func NewHTTPClientPool() *HTTPClientPool {
return pool return pool
} }
// 根据地址获取客户端 // Client 根据地址获取客户端
func (this *HTTPClientPool) Client(req *http.Request, origin *serverconfigs.OriginConfig, originAddr string) (rawClient *http.Client, err error) { func (this *HTTPClientPool) Client(req *http.Request, origin *serverconfigs.OriginConfig, originAddr string) (rawClient *http.Client, err error) {
if origin.Addr == nil { if origin.Addr == nil {
return nil, errors.New("origin addr should not be empty (originId:" + strconv.FormatInt(origin.Id, 10) + ")") return nil, errors.New("origin addr should not be empty (originId:" + strconv.FormatInt(origin.Id, 10) + ")")

View File

@@ -28,7 +28,7 @@ var bytePool1k = utils.NewBytePool(20480, 1024)
var bytePool32k = utils.NewBytePool(20480, 32*1024) var bytePool32k = utils.NewBytePool(20480, 32*1024)
var bytePool128k = utils.NewBytePool(20480, 128*1024) var bytePool128k = utils.NewBytePool(20480, 128*1024)
// HTTP请求 // HTTPRequest HTTP请求
type HTTPRequest struct { type HTTPRequest struct {
// 外部参数 // 外部参数
RawReq *http.Request RawReq *http.Request
@@ -95,7 +95,7 @@ func (this *HTTPRequest) init() {
this.requestFromTime = time.Now() this.requestFromTime = time.Now()
} }
// 执行请求 // Do 执行请求
func (this *HTTPRequest) Do() { func (this *HTTPRequest) Do() {
// 初始化 // 初始化
this.init() this.init()
@@ -433,7 +433,7 @@ func (this *HTTPRequest) configureWeb(web *serverconfigs.HTTPWebConfig, isTop bo
return nil return nil
} }
// 利用请求参数格式化字符串 // Format 利用请求参数格式化字符串
func (this *HTTPRequest) Format(source string) string { func (this *HTTPRequest) Format(source string) string {
if len(source) == 0 { if len(source) == 0 {
return "" return ""