{"id":13613960,"url":"https://github.com/go-netty/go-netty","last_synced_at":"2025-05-15T10:00:23.646Z","repository":{"id":41284384,"uuid":"219640800","full_name":"go-netty/go-netty","owner":"go-netty","description":"Extensible network application framework inspired by netty","archived":false,"fork":false,"pushed_at":"2025-03-10T11:48:52.000Z","size":175,"stargazers_count":505,"open_issues_count":7,"forks_count":94,"subscribers_count":16,"default_branch":"master","last_synced_at":"2025-04-14T16:53:35.984Z","etag":null,"topics":["go-netty","net","netty"],"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/go-netty.png","metadata":{"files":{"readme":"README-zh.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-11-05T02:32:21.000Z","updated_at":"2025-04-07T03:53:34.000Z","dependencies_parsed_at":"2024-11-29T17:03:19.348Z","dependency_job_id":"cd437bbd-4d6b-44ba-be41-ceb0c8994131","html_url":"https://github.com/go-netty/go-netty","commit_stats":{"total_commits":61,"total_committers":1,"mean_commits":61.0,"dds":0.0,"last_synced_commit":"e152cb73e74332a6355af05499da3b953f523a09"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-netty%2Fgo-netty","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-netty%2Fgo-netty/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-netty%2Fgo-netty/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-netty%2Fgo-netty/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/go-netty","download_url":"https://codeload.github.com/go-netty/go-netty/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254319715,"owners_count":22051072,"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":["go-netty","net","netty"],"created_at":"2024-08-01T20:00:55.267Z","updated_at":"2025-05-15T10:00:23.000Z","avatar_url":"https://github.com/go-netty.png","language":"Go","funding_links":[],"categories":["开源类库","Open source library","Go"],"sub_categories":["网络","The Internet"],"readme":"# GO-NETTY\n\n[![GoDoc][1]][2] [![license-Apache 2][3]][4] [![Go Report Card][5]][6] [![Build Status][9]][10] [![Coverage Status][11]][12]\n\n\u003c!--[![Downloads][7]][8]--\u003e\n\n[1]: https://godoc.org/github.com/go-netty/go-netty?status.svg\n[2]: https://godoc.org/github.com/go-netty/go-netty\n[3]: https://img.shields.io/badge/license-Apache%202-blue.svg\n[4]: LICENSE\n[5]: https://goreportcard.com/badge/github.com/go-netty/go-netty\n[6]: https://goreportcard.com/report/github.com/go-netty/go-netty\n[7]: https://img.shields.io/github/downloads/go-netty/go-netty/total.svg?maxAge=1800\n[8]: https://github.com/go-netty/go-netty/releases\n[9]: https://travis-ci.org/go-netty/go-netty.svg?branch=master\n[10]: https://travis-ci.org/go-netty/go-netty\n[11]: https://codecov.io/gh/go-netty/go-netty/branch/master/graph/badge.svg\n[12]: https://codecov.io/gh/go-netty/go-netty\n\n## 介绍\n\ngo-netty 是一款受netty启发的Go语言可扩展的高性能网络库\n\n## 特性\n\n* 可扩展多种传输协议，并且默认实现了 TCP, [UDP, QUIC, KCP, Websocket](https://github.com/go-netty/go-netty-transport)\n* 可扩展多种解码器，默认实现了常见的编解码器\n* 基于责任链模型的流程控制\n* 核心库零依赖\n\n## 文档\n* [GoDoc](https://godoc.org/github.com/go-netty/go-netty)\n\n## 示例\n\n* [chat_server (基于websocket的聊天室)](https://github.com/go-netty/go-netty-samples/blob/master/chat_server/main.go)  \n* [file_server (基于http的文件浏览器)](https://github.com/go-netty/go-netty-samples/blob/master/file_server/main.go)  \n* [tcp_server (自义定tcp服务器)](https://github.com/go-netty/go-netty-samples/blob/master/tcp_server/main.go)  \n* [redis_cli (简单的redis客户端)](https://github.com/go-netty/go-netty-samples/blob/master/redis_cli/main.go)\n* [go-netty-samples (更多例子)](https://github.com/go-netty/go-netty-samples)  \n\n## 快速开始\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"strings\"\n\n\t\"github.com/go-netty/go-netty\"\n\t\"github.com/go-netty/go-netty/codec/format\"\n\t\"github.com/go-netty/go-netty/codec/frame\"\n)\n\nfunc main() {\n\n    // 子连接的流水线配置\n    var childInitializer = func(channel netty.Channel) {\n        channel.Pipeline().\n            // 最大允许包长128字节，使用\\n分割包, 丢弃分隔符\n            AddLast(frame.DelimiterCodec(128, \"\\n\", true)).\n            // 解包出来的bytes转换为字符串\n            AddLast(format.TextCodec()).\n            // 日志处理器, 打印连接建立断开消息，收到的消息\n            AddLast(LoggerHandler{}).\n            // 业务处理器 (将字符串全部大写)\n            AddLast(UpperHandler{})\n    }\n\n\t// 创建Bootstrap \u0026 监听端口 \u0026 接受连接\n\tnetty.NewBootstrap(netty.WithChildInitializer(childInitializer)).\n\t\tListen(\":9527\").Sync()\n}\n\ntype LoggerHandler struct {}\n\nfunc (LoggerHandler) HandleActive(ctx netty.ActiveContext) {\n    fmt.Println(\"go-netty:\", \"-\u003e\", \"active:\", ctx.Channel().RemoteAddr())\n    // 写入欢迎信息\n    ctx.Write(\"Hello I'm \" + \"go-netty\")\n}\n\nfunc (LoggerHandler) HandleRead(ctx netty.InboundContext, message netty.Message) {\n    fmt.Println(\"go-netty:\", \"-\u003e\", \"handle read:\", message)\n    // 交给下一个处理器处理(按照处理器的注册顺序, 此例下一个处理器应该是UpperHandler)\n    ctx.HandleRead(message)\n}\n\nfunc (LoggerHandler) HandleInactive(ctx netty.InactiveContext, ex netty.Exception) {\n    fmt.Println(\"go-netty:\", \"-\u003e\", \"inactive:\", ctx.Channel().RemoteAddr(), ex)\n    // 连接断开了，默认处理是关闭连接\n    ctx.HandleInactive(ex)\n}\n\ntype UpperHandler struct {}\n\nfunc (UpperHandler) HandleRead(ctx netty.InboundContext, message netty.Message) {\n    // 业务逻辑，将字符串大写化\n    text := message.(string)\n    upText := strings.ToUpper(text)\n    // 写入返回结果给客户端\n    ctx.Write(text + \" -\u003e \" + upText)\n}\n```\n\n使用\u003ccode\u003eNetcat\u003c/code\u003e发送消息  \n```bash\n$ echo -n -e \"Hello Go-Netty\\nhttps://go-netty.com\\n\" | nc 127.0.0.1 9527\nHello I'm go-netty\nHello Go-Netty -\u003e HELLO GO-NETTY\nhttps://go-netty.com -\u003e HTTPS://GO-NETTY.COM\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgo-netty%2Fgo-netty","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgo-netty%2Fgo-netty","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgo-netty%2Fgo-netty/lists"}