Skip to content

Commit

Permalink
BREAKING: Changed SimpleClientFactory function signature
Browse files Browse the repository at this point in the history
* Remove the new obsoleted limit argument. No longer support in
  the new idPool implementation. Please discuss in issue track
  if you want this back.
  • Loading branch information
yookoala committed Feb 19, 2021
1 parent f4daef5 commit 4ea507d
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 22 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func main() {
// route all requests to a single php file
http.Handle("/", gofast.NewHandler(
gofast.NewFileEndpoint("/var/www/html/index.php")(gofast.BasicSession),
gofast.SimpleClientFactory(connFactory, 0),
gofast.SimpleClientFactory(connFactory),
))

// serve at 8080 port
Expand Down Expand Up @@ -153,7 +153,7 @@ func main() {
// route all requests to relevant PHP file
http.Handle("/", gofast.NewHandler(
gofast.NewPHPFS("/var/www/html")(gofast.BasicSession),
gofast.SimpleClientFactory(connFactory, 0),
gofast.SimpleClientFactory(connFactory),
))

// serve at 8080 port
Expand Down Expand Up @@ -229,7 +229,7 @@ func main() {
// route all requests to a single php file
http.Handle("/", gofast.NewHandler(
gofast.NewFileEndpoint("/var/www/html/index.php")(sess),
gofast.SimpleClientFactory(connFactory, 0),
gofast.SimpleClientFactory(connFactory),
))

// serve at 8080 port
Expand Down Expand Up @@ -308,7 +308,7 @@ func myApp() http.Handler {
func main() {
address := os.Getenv("FASTCGI_ADDR")
connFactory := gofast.SimpleConnFactory("tcp", address)
clientFactory := gofast.SimpleClientFactory(connFactory, 0)
clientFactory := gofast.SimpleClientFactory(connFactory)

// authorization with php
authSess := gofast.Chain(
Expand Down Expand Up @@ -361,7 +361,7 @@ import (
func main() {
address := os.Getenv("FASTCGI_ADDR")
connFactory := gofast.SimpleConnFactory("tcp", address)
clientFactory := gofast.SimpleClientFactory(connFactory, 0)
clientFactory := gofast.SimpleClientFactory(connFactory)

// Note: The local file system "/var/www/html/" only need to be
// local to web server. No need for the FastCGI application to access
Expand Down Expand Up @@ -420,7 +420,7 @@ func main() {
// handle all scripts in document root
// extra pooling layer
pool := gofast.NewClientPool(
gofast.SimpleClientFactory(connFactory, 0),
gofast.SimpleClientFactory(connFactory),
10, // buffer size for pre-created client-connection
30*time.Second, // life span of a client before expire
)
Expand Down
5 changes: 1 addition & 4 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,10 +386,7 @@ type ClientFactory func() (Client, error)

// SimpleClientFactory returns a ClientFactory implementation
// with the given ConnFactory.
//
// limit is UNUSED.
//
func SimpleClientFactory(connFactory ConnFactory, limit uint32) ClientFactory {
func SimpleClientFactory(connFactory ConnFactory) ClientFactory {
return func() (c Client, err error) {
// connect to given network address
conn, err := connFactory()
Expand Down
2 changes: 0 additions & 2 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ func testHandlerForCancel(t *testing.T, p *appServer, w http.ResponseWriter, r *

c, err := gofast.SimpleClientFactory(
gofast.SimpleConnFactory(p.Network(), p.Address()),
0,
)()
if err != nil {
http.Error(w, "failed to connect to FastCGI application", http.StatusBadGateway)
Expand Down Expand Up @@ -203,7 +202,6 @@ func TestClient_StdErr(t *testing.T) {
doRequest := func(w http.ResponseWriter, r *http.Request) (errStr string) {
c, err := gofast.SimpleClientFactory(
gofast.SimpleConnFactory(p.Network(), p.Address()),
0,
)()
if err != nil {
errStr = "web server: unable to connect to FastCGI application: " + err.Error()
Expand Down
4 changes: 2 additions & 2 deletions example/nodejs/nodejs.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
func NewHandler(entrypoint, network, address string) http.Handler {
connFactory := gofast.SimpleConnFactory(network, address)
pool := gofast.NewClientPool(
gofast.SimpleClientFactory(connFactory, 0),
gofast.SimpleClientFactory(connFactory),
10,
60*time.Second,
)
Expand Down Expand Up @@ -59,7 +59,7 @@ func NewMuxHandler(
// common client pool for both filter and responder handler
connFactory := gofast.SimpleConnFactory(network, address)
pool := gofast.NewClientPool(
gofast.SimpleClientFactory(connFactory, 0),
gofast.SimpleClientFactory(connFactory),
10,
60*time.Second,
)
Expand Down
4 changes: 2 additions & 2 deletions example/php/php.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func NewSimpleHandler(docroot, network, address string) http.Handler {
connFactory := gofast.SimpleConnFactory(network, address)
h := gofast.NewHandler(
gofast.NewPHPFS(docroot)(gofast.BasicSession),
gofast.SimpleClientFactory(connFactory, 0),
gofast.SimpleClientFactory(connFactory),
)
return h
}
Expand All @@ -41,7 +41,7 @@ func NewFileEndpointHandler(filepath, network, address string) http.Handler {
connFactory := gofast.SimpleConnFactory(network, address)
h := gofast.NewHandler(
gofast.NewFileEndpoint(filepath)(gofast.BasicSession),
gofast.SimpleClientFactory(connFactory, 0),
gofast.SimpleClientFactory(connFactory),
)
return h
}
2 changes: 1 addition & 1 deletion example/python3/python3.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
func NewHandler(entrypoint, network, address string) http.Handler {
connFactory := gofast.SimpleConnFactory(network, address)
pool := gofast.NewClientPool(
gofast.SimpleClientFactory(connFactory, 0),
gofast.SimpleClientFactory(connFactory),
10,
60*time.Second,
)
Expand Down
1 change: 0 additions & 1 deletion host_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ func TestHandler(t *testing.T) {
l.Addr().Network(),
l.Addr().String(),
),
0,
),
)
w := httptest.NewRecorder()
Expand Down
8 changes: 4 additions & 4 deletions pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func TestClientPool_CreateClient_withErr(t *testing.T) {
cpHasError := NewClientPool(
SimpleClientFactory(func() (net.Conn, error) {
return nil, fmt.Errorf("dummy error")
}, 10),
}),
10, 1*time.Millisecond,
)
c, err := cpHasError.CreateClient()
Expand All @@ -117,7 +117,7 @@ func TestClientPool_CreateClient_withErr(t *testing.T) {
cpHasError = NewClientPool(
SimpleClientFactory(func() (net.Conn, error) {
return nil, fmt.Errorf("dummy error")
}, 0),
}),
0, 1*time.Millisecond,
)
c, err = cpHasError.CreateClient()
Expand All @@ -143,7 +143,7 @@ func TestClientPool_CreateClient_Return_0(t *testing.T) {
conn := mockConn(false)
atomic.AddUint64(&counter, 1)
return &conn, nil
}, 0),
}),
0, 1000*time.Millisecond,
)

Expand Down Expand Up @@ -195,7 +195,7 @@ func TestClientPool_CreateClient_Return_40(t *testing.T) {
conn := mockConn(false)
atomic.AddUint64(&counter, 1)
return &conn, nil
}, 0),
}),
40, 1000*time.Millisecond,
)

Expand Down

0 comments on commit 4ea507d

Please sign in to comment.