{"id":22683503,"url":"https://github.com/notedit/oocrpc","last_synced_at":"2025-04-12T18:26:31.513Z","repository":{"id":2525670,"uuid":"3502021","full_name":"notedit/oocrpc","owner":"notedit","description":"a rpc based on bson， you can call the remote golang service from the python  or cpp  client","archived":false,"fork":false,"pushed_at":"2012-06-23T06:40:38.000Z","size":908,"stargazers_count":17,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-26T12:46:55.421Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/notedit.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-02-21T08:16:26.000Z","updated_at":"2022-03-29T02:50:40.000Z","dependencies_parsed_at":"2022-09-07T03:11:08.346Z","dependency_job_id":null,"html_url":"https://github.com/notedit/oocrpc","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/notedit%2Foocrpc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/notedit%2Foocrpc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/notedit%2Foocrpc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/notedit%2Foocrpc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/notedit","download_url":"https://codeload.github.com/notedit/oocrpc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248611988,"owners_count":21133219,"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-12-09T21:12:21.891Z","updated_at":"2025-04-12T18:26:31.490Z","avatar_url":"https://github.com/notedit.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# oocrpc\n\nThis is oocrpc, a rpc based on bson, you can call the remote golang service from the python client.\n\nso you can write the webapp's frontend with python(django tornado flask), write the webapp's backend with go.\n\n## QUICK START\n\n    $ go get  github.com/notedit/oocrpc/bson\n    $ go get  github.com/notedit/oocrpc/rpc\n    $ go test github.com/notedit/oocrpc/rpc\n\n\n# go rpc server:\n\n```go\npackage main\n                                                                                                                            \nimport (\n    \"errors\"\n    \"github.com/notedit/oocrpc/rpc\"\n)\n\ntype Args struct {\n    A, B int\n}\n\ntype Reply struct {\n    C int\n}\n\ntype Arith int\n\nfunc (t *Arith) Add(args *Args, reply *Reply) error {\n    reply.C = args.A + args.B\n    return nil\n}\n\nfunc (t *Arith) Mul(args *Args, reply *Reply) error {\n    reply.C = args.A * args.B\n    return nil\n}\n\nfunc (t *Arith) Div(args *Args, reply *Reply) error {\n    if args.B == 0 {\n        return rpc.BackendError{\"InternalError\", \"divide by zero\"}\n    }\n    reply.C = args.A / args.B\n    return nil\n}\n\n\nfunc (t *Arith) Error(args *Args, reply *Reply) error {\n    panic(\"ERROR\")\n}\n\nfunc (t *Arith) NError(args *Args, reply *Reply) error {\n    return errors.New(\"normalerror\")\n}\n\nfunc main() {\n    newServer := rpc.NewServer(\"localhost\", 9091)\n    newServer.Register(new(Arith))\n    newServer.Serv()\n}    \n```\n\n# go rpc client:\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"github.com/notedit/oocrpc/rpc\"\n)\n\ntype Args struct {\n    A, B int\n}\n\ntype Reply struct {\n    C int\n}\n\nfunc main() {\n    client := rpc.New(\"localhost:9090\")\n    // normal test\n    args := \u0026Args{7, 8}\n    reply := \u0026Reply{}\n\n    err := client.Call(\"Arith.Mul\", args, reply)\n    if err != nil {\n        fmt.Println(err.Error())\n    }\n\n    err = client.Call(\"Arith.Add\", args, reply)\n    if err != nil {\n        fmt.Println(err.Error())\n    }\n\n    // un exist method\n    err = client.Call(\"Arith.Notfound\", args, reply)\n    if err != nil {\n        fmt.Println(err.Error())\n    }\n    // un exist service\n    err = client.Call(\"Notfound.arith\", args, reply)\n    if err != nil {\n        fmt.Println(err.Error())\n    }\n    // test error \n    args = \u0026Args{7, 0}\n    reply = \u0026Reply{}\n\n    err = client.Call(\"Arith.Div\", args, reply)\n    if err != nil {\n        fmt.Println(err.Error())\n    }\n\n    // test panic\n    args = \u0026Args{7, 8}\n    reply = \u0026Reply{}\n\n    err = client.Call(\"Arith.Error\", args, reply)\n    if err != nil {\n        fmt.Println(err.Error())\n    }\n}                \n```\n\n# python rpc client:\n\n```python\nfrom client import RpcClient\n\nclient = RpcClient(host='localhost',port=9090)                                                                          \nret = client.Add({'a':7,'b':8})\nprint 'Add',ret\n\nret = client.Mul({'a':7,'b':8})\nprint 'Mul',ret\n```\n\n# cpp rpc client:\n```cpp\n\tbob b;\n\tb.append(\"a\", int(7));\n\tb.append(\"b\", int(8));\n\n\tBSONObj result;\n\tint c = 0;\n\tif ( DoRpcCall(host, \"Arith.Add\", b.obj(), \u0026result) )\t//\n\t{\n\t\t//cout \u003c\u003c result.jsonString(JS, 1) \u003c\u003c endl;\n\t\tc = result[\"c\"].Int();\n\t\tassert(c == 15);\n\t}\n\telse\n\t{\n\t\tcout \u003c\u003c result.jsonString(JS, 1) \u003c\u003c endl;\n\t\tassert(false);\n\t}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnotedit%2Foocrpc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnotedit%2Foocrpc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnotedit%2Foocrpc/lists"}