{"id":21296876,"url":"https://github.com/reddec/jsonrpc2","last_synced_at":"2025-03-15T17:27:30.091Z","repository":{"id":57507203,"uuid":"233816664","full_name":"reddec/jsonrpc2","owner":"reddec","description":"Go support library and codegen for JSON-RPC protocol","archived":false,"fork":false,"pushed_at":"2020-06-15T14:35:28.000Z","size":251,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-09T00:06:38.986Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/reddec.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":null,"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":["http://reddec.net/about/#donate"]}},"created_at":"2020-01-14T10:32:29.000Z","updated_at":"2021-09-09T12:03:00.000Z","dependencies_parsed_at":"2022-08-29T20:01:31.111Z","dependency_job_id":null,"html_url":"https://github.com/reddec/jsonrpc2","commit_stats":null,"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reddec%2Fjsonrpc2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reddec%2Fjsonrpc2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reddec%2Fjsonrpc2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reddec%2Fjsonrpc2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/reddec","download_url":"https://codeload.github.com/reddec/jsonrpc2/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243764977,"owners_count":20344510,"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":"2024-11-21T14:30:19.401Z","updated_at":"2025-03-15T17:27:30.071Z","avatar_url":"https://github.com/reddec.png","language":"Go","funding_links":["http://reddec.net/about/#donate"],"categories":[],"sub_categories":[],"readme":"# JSON-RPC 2 Go supporting library\n\n[![Documentation](https://img.shields.io/badge/documentation-latest-green)](https://godoc.org/github.com/reddec/jsonrpc2)\n[![license](https://img.shields.io/github/license/reddec/jsonrpc2.svg)](https://github.com/reddec/jsonrpc2)\n[![](https://godoc.org/github.com/reddec/jsonrpc2?status.svg)](http://godoc.org/github.com/reddec/jsonrpc2)\n[![donate](https://img.shields.io/badge/help_by️-donate❤-ff69b4)](http://reddec.net/about/#donate)\n[![Download](https://api.bintray.com/packages/reddec/debian/jsonrpc2/images/download.svg)](https://bintray.com/reddec/debian/jsonrpc2/_latestVersion)\n\n* [Formal specification](https://www.jsonrpc.org/specification)\n\nThe library aims to bring JSON-RPC 2.0 support to Go. Goals:\n\n* Type safe by code-generation\n* Reasonable good performance\n* Clean, extendable and easy-to use interface\n* Protocol-agnostic solution with adapters for common-cases (HTTP, TCP, etc...)\n\n\n# Installation\n\n* (recommended) look at  [releases](https://github.com/reddec/jsonrpc2/releases) page and download\n* build from source `go get -v github.com/reddec/jsonrpc2/cmd/...`\n* From bintray repository for most **debian**-based distribution (`trusty`, `xenial`, `bionic`, `buster`, `wheezy`):\n```bash\nsudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 379CE192D401AB61\necho \"deb https://dl.bintray.com/reddec/debian {distribution} main\" | sudo tee -a /etc/apt/sources.list\nsudo apt install jsonrpc2\n```\n\n## Build requirements\n\n* go 1.13+\n\n\n# Usage as library\n\nPlease see [package documentation](https://godoc.org/github.com/reddec/jsonrpc2)\n\n\n# Usage as CLI for type-safe generation\n\n```\nUsage:\n  jsonrpc2-gen [OPTIONS]\n\nGenerate tiny wrapper for JSON-RPC router\nAuthor: Baryshnikov Aleksandr \u003cdev@baryshnikov.net\u003e\nVersion: dev\n\nApplication Options:\n  -i, --file=                                File to scan [$GOFILE]\n  -I, --interface=                           Interface to wrap [$INTERFACE]\n      --namespace=                           Custom namespace for functions. If not defined - interface name will be used [$NAMESPACE]\n  -w, --wrapper=                             Wrapper function name. If not defined - Register\u003cinterface\u003e name will be used [$WRAPPER]\n  -o, --output=                              Generated output destination (- means STDOUT) (default: -) [$OUTPUT]\n  -p, --package=                             Package name (can be override by output dir) (default: events) [$PACKAGE]\n  -d, --doc=                                 Generate markdown documentation [$DOC]\n  -c, --case=[keep|camel|pascal|snake|kebab] Method name case style (default: keep) [$CASE]\n      --url=                                 URL for examples in documentation (default: https://example.com/api) [$URL]\n  -C, --interceptor                          add interceptor for each method [$INTERCEPTOR]\n\nHelp Options:\n  -h, --help                                 Show this help message\n\n```\n\n## Example\n\nAssume you have an interface file (`user.go`) like this:\n\n```go\npackage abc\n\n// General user profile access\ntype User interface {\n\t// Get user profile\n\tProfile(token string) (*Profile, error)\n}\n\n```\n\nJust invoke `jsonrpc2-gen -i user.go -o user_gen.go -I User -p abc`\n\nYou will get `user_gen.go` file like that:\n\n\n```go\n// Code generated by jsonrpc2-gen. DO NOT EDIT.\n//go:generate jsonrpc2-gen -i user.go -o user_gen.go -I User -p abc\npackage abc\n\nimport (\n\t\"encoding/json\"\n\tjsonrpc2 \"github.com/reddec/jsonrpc2\"\n)\n\nfunc RegisterUser(router *jsonrpc2.Router, wrap User) []string {\n\trouter.RegisterFunc(\"User.Profile\", func(params json.RawMessage, positional bool) (interface{}, error) {\n\t\tvar args struct {\n\t\t\tArg0 string `json:\"token\"`\n\t\t}\n\t\tvar err error\n\t\tif positional {\n\t\t\terr = jsonrpc2.UnmarshalArray(params, \u0026args.Arg0)\n\t\t} else {\n\t\t\terr = json.Unmarshal(params, \u0026args)\n\t\t}\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\treturn wrap.Profile(args.Arg0)\n\t})\n\n\treturn []string{\"User.Profile\"}\n}\n```\n\n### Generate documentation\n\nAdd `-doc user.md` to generate documentations as described bellow. It will be generated and saved to the provided file (`user.md`) \n\n```markdown\n# User\n\nGeneral user profile access\n\n\n## User.Profile\n\nGet user profile\n\n* Method: `User.Profile`\n* Returns: `*Profile`\n* Arguments:\n\n| Position | Name | Type |\n|----------|------|------|\n| 0 | token | `string` |\n```\n\n\n## KTOR (kotlin) generator\n\n* Supports `time/Time`\n* (TBD) `time/Duration`\n\n\nGradle requirements\n\n\n```groovy\n\ndef ktor_version = '1.3.1'\n\nrepositories {\n    mavenCentral()\n}\n\ndependencies {\n    implementation(\"io.ktor:ktor-client-cio:$ktor_version\") // \u003c-- you can choose another\n    implementation(\"io.ktor:ktor-client-gson:$ktor_version\")\n}\n\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freddec%2Fjsonrpc2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Freddec%2Fjsonrpc2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freddec%2Fjsonrpc2/lists"}