{"id":29251684,"url":"https://github.com/macrat/go-jsonrpc2","last_synced_at":"2025-10-29T15:13:59.751Z","repository":{"id":270662392,"uuid":"911074270","full_name":"macrat/go-jsonrpc2","owner":"macrat","description":"A super easy JSON-RPC 2.0 client and server library for Go.","archived":false,"fork":false,"pushed_at":"2025-01-02T07:48:43.000Z","size":0,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-02T08:28:04.828Z","etag":null,"topics":[],"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/macrat.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}},"created_at":"2025-01-02T07:23:11.000Z","updated_at":"2025-01-02T07:33:36.000Z","dependencies_parsed_at":"2025-01-02T08:40:23.591Z","dependency_job_id":null,"html_url":"https://github.com/macrat/go-jsonrpc2","commit_stats":null,"previous_names":["macrat/go-jsonrpc2"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/macrat/go-jsonrpc2","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/macrat%2Fgo-jsonrpc2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/macrat%2Fgo-jsonrpc2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/macrat%2Fgo-jsonrpc2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/macrat%2Fgo-jsonrpc2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/macrat","download_url":"https://codeload.github.com/macrat/go-jsonrpc2/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/macrat%2Fgo-jsonrpc2/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263427317,"owners_count":23464845,"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":[],"created_at":"2025-07-04T01:08:10.721Z","updated_at":"2025-10-29T15:13:54.699Z","avatar_url":"https://github.com/macrat.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Go JSON-RPC 2.0\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/macrat/go-jsonrpc2.svg)](https://pkg.go.dev/github.com/macrat/go-jsonrpc2)\n\nA super easy [JSON-RPC 2.0](https://www.jsonrpc.org/specification) client and server library for Go.\n\n## Example\n### Server\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"log\"\n\n\t\"github.com/macrat/go-jsonrpc2\"\n)\n\nfunc main() {\n\tserver := jsonrpc2.NewServer()\n\n\t// Add a method.\n\tserver.On(\"sum\", jsonrpc2.Call(func(ctx context.Context, xs []int) (int, error) {\n\t\tsum := 0\n\t\tfor _, x := range xs {\n\t\t\tsum += x\n\t\t}\n\t\treturn sum, nil\n\t}))\n\n\t// Add a notification handler.\n\tserver.On(\"notify\", jsonrpc2.Notify(func(ctx context.Context, message string) error {\n\t\tlog.Printf(\"notify: %s\", message)\n\t\treturn nil\n\t}))\n\n\tl, err := jsonrpc2.NewTCPListener(\":1234\")\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\tlog.Fatal(server.Serve(l))\n}\n```\n\n### Client\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"net\"\n\n\t\"github.com/macrat/go-jsonrpc2\"\n)\n\nfunc main() {\n\tconn, err := net.Dial(\"tcp\", \"localhost:1234\")\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\tctx := context.Background()\n\n\tclient := jsonrpc2.NewClient(conn)\n\n\t// Call\t`sum` method.\n\tvar sum int\n\terr := client.Call(ctx, \"sum\", []int{1, 2, 3}, \u0026sum)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\tlog.Printf(\"sum: %d\", sum)\n\n\t// Send `notify` notification.\n\terr = client.Notify(ctx, \"notify\", \"Hello, World!\")\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmacrat%2Fgo-jsonrpc2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmacrat%2Fgo-jsonrpc2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmacrat%2Fgo-jsonrpc2/lists"}