Skip to content

Commit

Permalink
1、add go.mod 2、fix readme
Browse files Browse the repository at this point in the history
  • Loading branch information
silenceper committed Feb 16, 2020
1 parent 4f07b13 commit 7c45679
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 7 additions & 5 deletions example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,自动失效的问题
Expand Down
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/silenceper/pool

go 1.13

require github.com/sirupsen/logrus v1.4.2
9 changes: 9 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=

0 comments on commit 7c45679

Please sign in to comment.