{"id":34171688,"url":"https://github.com/tsmask/go-oam","last_synced_at":"2026-06-06T09:01:28.175Z","repository":{"id":303561647,"uuid":"1015890007","full_name":"TsMask/go-oam","owner":"TsMask","description":"【Go】Go OAM SDK — 网元（NE）与网管（NMS）之间的运维通信框架。","archived":false,"fork":false,"pushed_at":"2026-05-29T08:46:10.000Z","size":656,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-05-29T10:09:56.304Z","etag":null,"topics":["5gc","oam"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TsMask.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":"AGENTS.md","dco":null,"cla":null}},"created_at":"2025-07-08T07:27:04.000Z","updated_at":"2026-05-29T08:13:16.000Z","dependencies_parsed_at":"2025-07-08T09:20:24.747Z","dependency_job_id":"d89431a1-5471-4070-8a75-23eeccc2e9c2","html_url":"https://github.com/TsMask/go-oam","commit_stats":null,"previous_names":["tsmask/go-oam"],"tags_count":19,"template":false,"template_full_name":null,"purl":"pkg:github/TsMask/go-oam","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TsMask%2Fgo-oam","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TsMask%2Fgo-oam/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TsMask%2Fgo-oam/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TsMask%2Fgo-oam/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TsMask","download_url":"https://codeload.github.com/TsMask/go-oam/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TsMask%2Fgo-oam/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33975476,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-06T02:00:07.033Z","response_time":107,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["5gc","oam"],"created_at":"2025-12-15T11:25:06.977Z","updated_at":"2026-06-06T09:01:28.169Z","avatar_url":"https://github.com/TsMask.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-oam\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/olekukonko/tablewriter.svg)](https://pkg.go.dev/github.com/tsmask/go-oam)\n[![Go Report Card](https://goreportcard.com/badge/github.com/tsmask/go-oam)](https://goreportcard.com/report/github.com/tsmask/go-oam)\n[![License](https://img.shields.io/badge/license-BSD3-blue.svg)](LICENSE)\n[![Tag](https://img.shields.io/badge/TAG-list-success)](https://proxy.golang.org/github.com/tsmask/go-oam/@v/list)\n\nGo OAM SDK — 网元（NE）与网管（NMS）之间的运维通信框架。\n\n提供 WebSocket、数据推送、系统状态采集、命令执行等完整能力，模块独立可组合。\n\n## 模块概览\n\n| 模块 | 说明 |\n|---|---|\n| `ws/` | WebSocket 通信框架（服务端 + 客户端，多编码自动检测，发布订阅） |\n| `push/` | 数据推送框架（同步/异步，Worker 池，重试，指标采集，历史记录） |\n| `pkg/` | 工具包（独立模块，不依赖其他内部包） |\n\n## 快速开始\n\n要求 Go 1.25+。\n\n```bash\ngo get github.com/tsmask/go-oam\n```\n\n### WebSocket 服务端\n\n```go\nimport \"github.com/tsmask/go-oam/ws\"\n\nserver := ws.NewServer(\n    ws.WithServerCodec(\"json\"),\n    ws.WithServerHeartbeat(30*time.Second),\n)\n\nserver.Handle(\"echo\", func(conn *ws.Conn, req *ws.Request) {\n    conn.SendOK(req.ID, req.Action, req.Data)\n})\n\nserver.OnConnect(func(conn *ws.Conn, r *http.Request) {\n    log.Printf(\"连接: %s\", conn.ID())\n})\n\nmux := http.NewServeMux()\nmux.Handle(\"/ws\", server)\nhttp.ListenAndServe(\":9092\", mux)\n```\n\n### WebSocket 客户端\n\n```go\nclient := ws.NewClient(\"ws://localhost:9092/ws\",\n    ws.WithClientAutoReconnect(true),\n)\nclient.Connect(context.Background())\ndefer client.Close()\n\nclient.OnReceive(func(resp *ws.Response) {\n    fmt.Printf(\"收到: id=%s code=%d\\n\", resp.ID, resp.Code)\n})\n\nclient.Send(\u0026ws.Request{Action: \"echo\", Data: []byte(`\"hello\"`)})\n```\n\n### 数据推送\n\n```go\nimport \"github.com/tsmask/go-oam/push\"\n\np := push.New(\n    push.WithBaseURL(\"http://localhost:8080\"),\n    push.WithTimeout(30*time.Second),\n    push.WithRetry(3),\n)\ndefer p.Close()\n\nrecord := \u0026push.Record{\n    NeUID:      \"ne-001\",\n    RecordType: \"alarm\",\n    RecordData: json.RawMessage(`{\"level\":\"critical\"}`),\n}\n\np.Send(record, nil)      // 同步\np.SendAsync(record, nil)  // 异步\n```\n\n## 模块详情\n\n### ws/ — WebSocket 通信框架\n\n基于 [coder/websocket](https://github.com/coder/websocket)，支持服务端和客户端。\n\n- **多编码自动检测** — 同一服务端同时服务 JSON/MsgPack/Protobuf 客户端，按消息类型自动切换\n- **发布订阅** — 内置 Topic 管理，Subscribe/Publish/Broadcast\n- **中间件** — 洋葱模型，按注册顺序包裹 Handler\n- **元数据** — 每连接 SetMeta/GetMeta，线程安全\n- **客户端自动重连** — 指数退避 + 抖动\n- **心跳保活** — 连续 3 次 Ping 失败断开\n- **优雅关闭** — Shutdown() 拒绝新连接 → 关闭所有已有连接\n\n→ 完整文档见 [ws/README.md](ws/README.md)\n\n### push/ — 数据推送框架\n\nHTTP 推送客户端，支持同步/异步、重试、指标采集和历史记录。\n\n- **Worker 池** — 可配置 Worker 数和队列大小，队列满时自动降级为同步发送\n- **指数退避重试** — 可重试 5xx/429/网络错误，不可重试 4xx\n- **Metrics** — 标准版和分片版两种指标采集实现\n- **History** — 泛型环形缓冲区，标准和分片两种实现\n- **Timer** — 周期回调定时器\n- **连接池复用** — http.Client + sync.Pool 复用连接和 Buffer\n\n→ 完整文档见 [push/README.md](push/README.md)\n\n### pkg/ — 工具包\n\n纯工具库，模块之间无依赖，可独立使用。\n\n| 包 | 说明 |\n|---|---|\n| `pkg/cmd` | 本地命令行执行（exec、session、check） |\n| `pkg/crypto` | AES 加密、哈希 |\n| `pkg/date` | 日期解析（字符串/数字转时间） |\n| `pkg/fetch` | HTTP 请求封装（基于 resty，含异步队列） |\n| `pkg/file` | 文件操作（列表、上传、压缩、CSV/JSON/TXT，跨平台） |\n| `pkg/generate` | ID 生成（crypto/rand） |\n| `pkg/iperf` | iperf 网络测试（PTY 终端封装） |\n| `pkg/parse` | 数据解析 |\n| `pkg/ping` | ping 功能（原生 + PTY 终端两种实现） |\n| `pkg/push` | 推送数据结构定义（alarm、cdr、kpi、nb_state、ue_ims、ue_nb） |\n| `pkg/ringbuffer` | 环形缓冲区 |\n| `pkg/socket` | TCP/UDP 客户端与服务端 |\n| `pkg/state` | 系统状态采集（CPU/内存/磁盘/网络/进程） |\n| `pkg/telnet` | Telnet 客户端与服务端 |\n\n## 示例\n\n```\nexamples/\n├── push/\n│   ├── usage/     功能测试（Record、Client、Metrics、History、Timer、综合场景）\n│   └── stats/     性能基准测试（10 项 benchmark + 正确性验证）\n└── ws/\n    ├── web/       WebSocket 服务端 + 浏览器客户端\n    └── client/    WebSocket Go 客户端\n```\n\n## 关键依赖\n\n| 依赖 | 用途 |\n|---|---|\n| `coder/websocket` | WebSocket 协议实现 |\n| `go-resty/resty/v2` | HTTP 客户端 |\n| `vmihailenco/msgpack/v5` | MsgPack 编解码 |\n| `google.golang.org/protobuf` | Protobuf 序列化 |\n| `shirou/gopsutil/v4` | 系统状态采集 |\n| `creack/pty` | PTY 终端 |\n| `prometheus-community/pro-bing` | Ping 功能 |\n\n## 构建\n\n```bash\ngo build ./...\n\n# 运行测试\ngo test ./...\n\n# 运行示例\ngo run examples/ws/web/main.go\ngo run examples/push/usage/main.go\ngo run examples/push/stats/main.go 50  # 50 并发\n```\n\n## 目录结构\n\n```\ngo-oam/\n├── oam.go                  # SDK 入口\n├── ws/                     # WebSocket 模块\n│   ├── server/             # 服务端（连接管理、发布订阅、中间件）\n│   ├── client/             # 客户端（自动重连、心跳）\n│   ├── codec/              # 编解码器（JSON/MsgPack/Protobuf）\n│   ├── types/              # Request/Response 消息结构\n│   └── protocol/           # Protobuf 定义\n├── push/                   # 推送模块\n│   ├── client/             # HTTP 客户端（Worker 池、异步队列、重试）\n│   ├── history/            # 历史记录（RingBuffer，标准/分片）\n│   ├── metrics/            # 指标采集（标准/分片）\n│   └── timer/              # 周期定时器\n├── pkg/                    # 工具包（独立模块）\n│   ├── cmd/                # 命令执行\n│   ├── crypto/             # 加密\n│   ├── date/               # 日期工具\n│   ├── fetch/              # HTTP 请求\n│   ├── file/               # 文件操作\n│   ├── generate/           # ID 生成\n│   ├── iperf/              # 网络测试\n│   ├── parse/              # 数据解析\n│   ├── ping/               # Ping\n│   ├── push/               # 推送数据结构\n│   ├── ringbuffer/         # 环形缓冲区\n│   ├── socket/             # TCP/UDP\n│   ├── state/              # 系统状态\n│   └── telnet/             # Telnet\n└── examples/               # 使用示例\n    ├── ws/                 # WebSocket 示例\n    └── push/               # Push 示例\n```\n\n## License\n\n[BSD 3-Clause](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftsmask%2Fgo-oam","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftsmask%2Fgo-oam","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftsmask%2Fgo-oam/lists"}