{"id":37112510,"url":"https://github.com/emove/connpool","last_synced_at":"2026-01-14T13:18:27.159Z","repository":{"id":62258783,"uuid":"553020709","full_name":"Emove/connpool","owner":"Emove","description":"a connection pool for every reusable connection","archived":false,"fork":false,"pushed_at":"2022-10-29T09:59:48.000Z","size":23,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-06-21T13:12:57.324Z","etag":null,"topics":["backoff","connection-pool","dynamic-register","network"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Emove.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-10-17T15:32:29.000Z","updated_at":"2024-06-21T13:12:57.324Z","dependencies_parsed_at":"2022-10-29T11:00:35.679Z","dependency_job_id":null,"html_url":"https://github.com/Emove/connpool","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/Emove/connpool","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Emove%2Fconnpool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Emove%2Fconnpool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Emove%2Fconnpool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Emove%2Fconnpool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Emove","download_url":"https://codeload.github.com/Emove/connpool/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Emove%2Fconnpool/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28420996,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T10:47:48.104Z","status":"ssl_error","status_checked_at":"2026-01-14T10:46:19.031Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["backoff","connection-pool","dynamic-register","network"],"created_at":"2026-01-14T13:18:26.468Z","updated_at":"2026-01-14T13:18:27.145Z","avatar_url":"https://github.com/Emove.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# connpool\n\n[![GoDoc][1]][2] [![Go Report Card][3]][4]\n\n\u003c!--[![Downloads][7]][8]--\u003e\n\n[1]: https://godoc.org/github.com/emove/connpool?status.svg\n\n[2]: https://godoc.org/github.com/emove/connpool\n\n[3]: https://goreportcard.com/badge/github.com/emove/connpool\n\n[4]: https://goreportcard.com/report/github.com/emove/connpool\n\n## 介绍\n一个面向所有可复用链接的连接池。\n\n## 特性\n- 提供连接池最基本的功能，包括核心连接数，最大连接数，链接最大空闲时间，等待超时等\n- 提供连接重试功能，包括定时重试，指数退避重试\n- 允许在连接失败超过一定次数或时间后剔除连接地址\n- 允许动态注入连接地址\n- 允许自定义WarmUp功能\n\n## 安装\n```shell\ngo get github.com/emove/connpool\n```\n\n## 示例\n### 快速开始\n```go\nimport (\n    \"fmt\"\n    \"net\"\n    \n    \"github.com/emove/connpool\"\n)\n\nfunc main() {\n    // 创建一个连接池，传入三个基本参数\n    // 连接地址，创建链接的方法，关闭链接的方法\n    pool := connpool.NewPool([]string{addr}, dial, close,\n        connpool.CoreNums(5), // 配置单个地址链接的核心连接数，默认配置为1\n        connpool.MaxNums(20), // 配置单个地址链接的最大连接数，默认配置为10\n        connpool.MaxIdleTime(10*time.Second), // 配置链接的最大空闲时间，默认配置为30秒\n        connpool.WaitTimeout(5*time.Second), // 配置获取链接的超时时间，默认配置为3秒\n    )\n    con, err := pool.Get()\n    if err != nil {\n        fmt.Printf(\"get connection err: %v\\n\", err)\n        return\n    }\n    \n    conn := con.(net.Conn)\n    _, err = conn.Write([]byte(\"hello world\"))\n    if err != nil {\n        // 使用中发生错误，交由连接池销毁该连接\n        pool.Discard(con)\n    } else {\n        // 将可用链接归还给连接池，等待复用\n        pool.Put(con)\n    }\n    \n    // 关闭连接池\n    pool.Close()\n}\n\n\n// 定义连接函数，创建并返回一个tcp连接\nfunc dial(addr string) (interface{}, error) {\n    return net.Dial(\"tcp\", addr)\n}\n\n// 定义连接关闭函数\nfunc close(con interface{}) {\n    if c, ok := con.(net.Conn); ok {\n    \t_ = c.Close()\n    }\n}\n```\n\n### 更多用法\n[connpool-example](https://github.com/Emove/connpool/tree/main/example)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femove%2Fconnpool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Femove%2Fconnpool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femove%2Fconnpool/lists"}