{"id":19416380,"url":"https://github.com/scriptllh/tfg","last_synced_at":"2025-04-24T13:32:35.752Z","repository":{"id":57498332,"uuid":"195398308","full_name":"scriptllh/tfg","owner":"scriptllh","description":"基于epoll+协程池的golang网络库。支持epoll事件触发，读数据和业务逻辑处理分离，最大化利用cpu，防止内存急剧暴涨，适用于长连接、短连接，支持请求对象池和连接对象池","archived":false,"fork":false,"pushed_at":"2019-07-28T07:17:40.000Z","size":1112,"stargazers_count":31,"open_issues_count":1,"forks_count":10,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-10-16T09:28:50.913Z","etag":null,"topics":["epoll","golang","goroutine-pool","networking","pool","socket","tcp"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/scriptllh.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":"2019-07-05T11:30:04.000Z","updated_at":"2024-01-28T17:43:48.000Z","dependencies_parsed_at":"2022-08-28T17:12:47.182Z","dependency_job_id":null,"html_url":"https://github.com/scriptllh/tfg","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scriptllh%2Ftfg","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scriptllh%2Ftfg/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scriptllh%2Ftfg/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scriptllh%2Ftfg/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/scriptllh","download_url":"https://codeload.github.com/scriptllh/tfg/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223954897,"owners_count":17231187,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["epoll","golang","goroutine-pool","networking","pool","socket","tcp"],"created_at":"2024-11-10T12:47:19.381Z","updated_at":"2024-11-10T12:47:20.251Z","avatar_url":"https://github.com/scriptllh.png","language":"Go","readme":"\u003ch1 align=\"center\"\u003eWelcome to tfg 👋\u003c/h1\u003e\n\n\n\n### 🏠 [Homepage](https://github.com/scriptllh/tfg)\n\n## Install\n\n```sh\ngo get -u github.com/scriptllh/tfg\n```\n\n\n## Usage\n\n```sh\necho\n\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/scriptllh/tfg\"\n\tlog \"github.com/sirupsen/logrus\"\n\t\"time\"\n)\n\ntype HandleConn struct {\n\ttfg.BaseHandleConn\n}\n\nfunc (hc *HandleConn) PreOpen(c tfg.Conn) {\n\tlog.Infof(\"pre conn open: [conn:%v]\", c)\n}\n\ntype req struct {\n\ts string\n}\n\n/**\n * req : in =\u003e 请求读出来的字节    lastRemain =\u003e 上一次read 操作没有处理完的数据\n *\n * resp: packet =\u003e 处理完后生成业务的结构数据   remain =\u003e 这一节数据不够转换成业务数据下次read的时候再处理\n *    isFinRead =\u003e 是否继续处理这次留下来的remain，如果为false,则下次数据会按顺序过来，加上这次留下的remain，且是同一个协程处理\n *         如果为true =\u003e 则下次数据不会带上remain，且下次read是下一个协程来处理\n *    isHandle =\u003e 是否有数据packet给handle执行 ，因为handle是异步执行的\n */\nfunc (hc *HandleConn) Read(in []byte, lastRemain []byte) (packet interface{}, remain []byte, isFinRead bool, isHandle bool, err error) {\n\ts := string(in)\n\treq := \u0026req{\n\t\ts: s,\n\t}\n\tlog.Infof(\"read [data:%v]\", req)\n\treturn req, nil, false, true, nil\n}\n\n/**\n * req : conn =\u003e 连接    packet =\u003e read 处理过后的业务数据packet\n *\n */\n\nfunc (hc *HandleConn) Handle(conn tfg.Conn, packet interface{}, err error) {\n\treq := packet.(*req)\n\tlog.Infof(\"handle req [data:%v]\", req)\n\ttime.Sleep(time.Millisecond * time.Duration(10))\n\tn, err := conn.Write([]byte(\"tfg la la la\"))\n\tif err != nil {\n\t\tfmt.Println(err)\n\t\treturn\n\t}\n\tlog.Infof(\"handle write [n:%v]\", n)\n}\n\nfunc main() {\n\tvar handleConn HandleConn\n\ts, err := tfg.NewServer(\":6000\", \u0026handleConn, 0, tfg.RoundRobin)\n\tif err != nil {\n\t\tlog.Errorf(\"new server [err:%v]\", err)\n\t\treturn\n\t}\n\tlog.Infof(\"server start :%v\", \"6000\")\n\tif err := s.Serve(); err != nil {\n\t\tlog.Errorf(\"serve [err:%v]\", err)\n\t\treturn\n\t}\n}\n\n\n```\n\n## Run\n\n```sh\ngit clone https://github.com/scriptllh/tfg-example.git\n1. echo \n     * make dev\n     * 用PacketSender访问\n2. http\n    * make http\n    * 用Postman访问\n```\n\n\n\n## 🤝 Contributing\n\nContributions, issues and feature requests are welcome!\u003cbr /\u003eFeel free to check [issues page](https://github.com/scriptllh/tfg/issues).\n\n## Show your support\n\nGive a ⭐️ if this project helped you!\n\n\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscriptllh%2Ftfg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fscriptllh%2Ftfg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscriptllh%2Ftfg/lists"}