Skip to content

Commit 17498ab

Browse files
committed
use go mod
1 parent daea278 commit 17498ab

File tree

11 files changed

+40
-36
lines changed

11 files changed

+40
-36
lines changed

.gitattributes

Lines changed: 0 additions & 2 deletions
This file was deleted.

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module github.com/iwind/gofcgi
2+
3+
go 1.16

client.go renamed to pkg/client.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package gofcgi
1+
package pkg
22

33
import (
44
"errors"
@@ -38,12 +38,12 @@ func NewClient(network string, address string) *Client {
3838
expireTime: time.Now().Add(86400 * time.Second),
3939
}
4040

41-
// 处理超时
41+
// deal with expireTime
4242
go func() {
4343
for {
4444
time.Sleep(1 * time.Second)
4545
if time.Since(client.expireTime) > 0 {
46-
client.conn.Close()
46+
_ = client.conn.Close()
4747

4848
client.expireLocker.Lock()
4949
client.expireTime = time.Now().Add(86400 * time.Second)
@@ -77,7 +77,7 @@ func (this *Client) Call(req *Request) (resp *http.Response, stderr []byte, err
7777

7878
defer func() {
7979
if this.mock {
80-
time.Sleep(1 * time.Second) // 模拟占用连接
80+
time.Sleep(1 * time.Second)
8181
}
8282
this.isFree = true
8383
this.locker.Unlock()
@@ -93,12 +93,12 @@ func (this *Client) Call(req *Request) (resp *http.Response, stderr []byte, err
9393
resp, stderr, err = req.CallOn(this.conn)
9494
this.endTime()
9595

96-
// 如果失去连接,则重新连接
96+
// if lost connection, retry
9797
if err != nil {
9898
log.Println("[gofcgi]" + err.Error())
9999

100100
if err == ErrClientDisconnect {
101-
// 重试一次
101+
// retry again
102102
this.Close()
103103
err = this.Connect()
104104
if err == nil {
@@ -120,15 +120,15 @@ func (this *Client) Call(req *Request) (resp *http.Response, stderr []byte, err
120120
func (this *Client) Close() {
121121
this.isAvailable = false
122122
if this.conn != nil {
123-
this.conn.Close()
123+
_ = this.conn.Close()
124124
}
125125
this.conn = nil
126126
}
127127

128128
func (this *Client) Connect() error {
129129
this.isAvailable = false
130130

131-
// @TODO 设置并使用超时时间
131+
// @TODO set timeout
132132
conn, err := net.Dial(this.network, this.address)
133133
if err != nil {
134134
log.Println("[gofcgi]" + err.Error())

client_test.go renamed to pkg/client_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package gofcgi
1+
package pkg
22

33
import (
44
"bytes"

const.go renamed to pkg/const.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
package gofcgi
1+
package pkg
22

3-
// 参考 http://www.mit.edu/~yandros/doc/specs/fcgi-spec.html
3+
// referer: http://www.mit.edu/~yandros/doc/specs/fcgi-spec.html
44

55
const (
66
// Listening socket file number

header.go renamed to pkg/header.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package gofcgi
1+
package pkg
22

33
type Header struct {
44
Version byte

name_value.go renamed to pkg/name_value.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package gofcgi
1+
package pkg
22

33
type NameValuePair struct {
44
NameLength uint16

pool.go renamed to pkg/pool.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package gofcgi
1+
package pkg
22

33
import (
44
"errors"
@@ -39,7 +39,7 @@ func SharedPool(network string, address string, size uint) *Pool {
3939
client := NewClient(network, address)
4040
client.KeepAlive()
4141

42-
// 第一个同步连接供使用,其余的可以异步建立连接
42+
// prepare one for first request, and left for async request
4343
if i == 0 {
4444
err := client.Connect()
4545
if err != nil {
@@ -56,13 +56,13 @@ func SharedPool(network string, address string, size uint) *Pool {
5656
pool.clients = append(pool.clients, client)
5757
}
5858

59-
// 监控连接
59+
// watch connections
6060
go func() {
61-
for {
62-
time.Sleep(10 * time.Second)
61+
ticker := time.NewTicker(10 * time.Second)
62+
for range ticker.C {
6363
for _, client := range pool.clients {
6464
if !client.isAvailable {
65-
client.Connect()
65+
_ = client.Connect()
6666
}
6767
}
6868
}

pool_test.go renamed to pkg/pool_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
package gofcgi
1+
package pkg
22

33
import (
4-
"testing"
5-
"time"
64
"errors"
75
"io/ioutil"
6+
"testing"
7+
"time"
88
)
99

1010
func TestSharedPool(t *testing.T) {
1111
pool := SharedPool("tcp", "127.0.0.1:9000", 8)
1212

1313
time.Sleep(100 * time.Millisecond)
1414

15-
for i := 0; i < 3; i ++ {
15+
for i := 0; i < 3; i++ {
1616
go func() {
1717
client, err := pool.Client()
1818
if err != nil {
@@ -41,7 +41,7 @@ func TestSharedPool(t *testing.T) {
4141
"REQUEST_METHOD": "GET",
4242
})
4343

44-
resp, err := client.Call(req)
44+
resp, _, err := client.Call(req)
4545
if err != nil {
4646
t.Log(err.Error())
4747
} else {

record.go renamed to pkg/record.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package gofcgi
1+
package pkg
22

33
type UnknownTypeBody struct {
44
recordType byte

0 commit comments

Comments
 (0)