From 7c45679d8813f0d3646ff863b34fa5442d782a84 Mon Sep 17 00:00:00 2001 From: silenceper Date: Sun, 16 Feb 2020 19:52:17 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81add=20go.mod=202=E3=80=81fix=20readme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 7 ++++--- example/main.go | 12 +++++++----- go.mod | 5 +++++ go.sum | 9 +++++++++ 4 files changed, 25 insertions(+), 8 deletions(-) create mode 100644 go.mod create mode 100644 go.sum diff --git a/README.md b/README.md index 39a02c0..61eeeaf 100644 --- a/README.md +++ b/README.md @@ -24,10 +24,11 @@ close := func(v interface{}) error { return v.(net.Conn).Close() } //ping 检测连接的方法 //ping := func(v interface{}) error { return nil } -//创建一个连接池: 初始化5,最大连接30 +//创建一个连接池: 初始化5,最大空闲连接是20,最大并发连接30 poolConfig := &pool.Config{ - InitialCap: 5, - MaxCap: 30, + InitialCap: 5,//资源池初始连接数 + MaxIdle: 20,//最大空闲连接数 + MaxCap: 30,//最大并发连接数 Factory: factory, Close: close, //Ping: ping, diff --git a/example/main.go b/example/main.go index ffa044d..e926366 100644 --- a/example/main.go +++ b/example/main.go @@ -2,15 +2,16 @@ package main import ( "fmt" - "github.com/silenceper/pool" "net" "os" "os/signal" "syscall" "time" + + "github.com/silenceper/pool" ) -const addr string = "127.0.0.1:80" +const addr string = "127.0.0.1:8080" func main() { c := make(chan os.Signal) @@ -32,10 +33,11 @@ func client() { //close 关闭连接的方法 close := func(v interface{}) error { return v.(net.Conn).Close() } - //创建一个连接池: 初始化5,最大连接30 + //创建一个连接池: 初始化2,最大连接5,空闲连接数是4 poolConfig := &pool.Config{ - InitialCap: 5, - MaxCap: 30, + InitialCap: 2, + MaxIdle: 4, + MaxCap: 5, Factory: factory, Close: close, //连接最大空闲时间,超过该时间的连接 将会关闭,可避免空闲时连接EOF,自动失效的问题 diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..49ecc4e --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module github.com/silenceper/pool + +go 1.13 + +require github.com/sirupsen/logrus v1.4.2 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..46e5ef0 --- /dev/null +++ b/go.sum @@ -0,0 +1,9 @@ +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4= +github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= +github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc= +golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=