{"id":37180372,"url":"https://github.com/fanchunke/chapic","last_synced_at":"2026-01-14T20:58:28.101Z","repository":{"id":210650686,"uuid":"727112017","full_name":"fanchunke/chapic","owner":"fanchunke","description":"A proto-gen plugin to generate a client library and an echo HTTP server specified by protocol buffers","archived":false,"fork":false,"pushed_at":"2024-09-04T13:32:38.000Z","size":30,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-09-05T17:04:10.857Z","etag":null,"topics":["autogenerated","client","echo-framework","http-server","proto-gen-go-files","protocol-buffers"],"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/fanchunke.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,"governance":null}},"created_at":"2023-12-04T07:57:44.000Z","updated_at":"2024-09-04T13:32:42.000Z","dependencies_parsed_at":"2023-12-04T09:22:28.437Z","dependency_job_id":"b6b1b743-2d47-45ff-a899-b953ed74b8b5","html_url":"https://github.com/fanchunke/chapic","commit_stats":null,"previous_names":["fanchunke/chapic"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/fanchunke/chapic","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fanchunke%2Fchapic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fanchunke%2Fchapic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fanchunke%2Fchapic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fanchunke%2Fchapic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fanchunke","download_url":"https://codeload.github.com/fanchunke/chapic/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fanchunke%2Fchapic/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28434500,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T18:57:19.464Z","status":"ssl_error","status_checked_at":"2026-01-14T18:52:48.501Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["autogenerated","client","echo-framework","http-server","proto-gen-go-files","protocol-buffers"],"created_at":"2026-01-14T20:58:27.373Z","updated_at":"2026-01-14T20:58:28.096Z","avatar_url":"https://github.com/fanchunke.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# chapic\n\nThis is a generator for API client and server libraries for APIs specified by protocol buffers. It takes a protocol buffer and uses it to generate a client library and an echo HTTP server.\n\n## Installation\n\nUse `go install` to install the latest version of the generator `protoc-gen-go-chapic`\n\n```shell\ngo install github.com/fanchunke/chapic/cmd/protoc-gen-go-chapic\n```\n\n## Usage\n\n1. define `.proto` file\n\n    ```protobuf\n    syntax = \"proto3\";\n    \n    package chapic.example.proto;\n    \n    import \"google/api/annotations.proto\";\n    import \"google/protobuf/field_mask.proto\";\n    import \"google/protobuf/struct.proto\";\n    \n    option go_package = \"github.com/fanchunke/chapic/example/proto\";\n    \n    // EchoRequest is the request for echo.\n    message EchoRequest {\n      int32 id = 1;  // @gotags: param:\"id\"\n      string message = 2;  // @gotags: query:\"message\"\n    }\n   \n    // EchoPostRequest is the request for echo.\n    message EchoPostRequest {\n      int32 id = 1;\n      string message = 2;\n    }\n    \n    // EchoResponse is the response for echo.\n    message EchoResponse {\n      int32 id = 1;\n      string message = 2;\n    }\n    \n    // Echo is the echo service.\n    service Echo {\n      // UnaryEcho is unary echo.\n      rpc UnaryEcho(EchoRequest) returns (EchoResponse) {\n        option (google.api.http) = {\n          get: \"/v1/example/{id}\",\n        };\n      }\n   \n      // UnaryEchoPost is unary echo.\n      rpc UnaryEchoPost(EchoPostRequest) returns (EchoResponse) {\n        option (google.api.http) = {\n          post: \"/v1/examples\",\n          body: \"*\"\n        };\n      }\n    }\n    ```\n   \n   **In `.proto` file, we use [protoc-go-inject-tag](https://github.com/favadi/protoc-go-inject-tag) to inject `echo` custom tags for binding.**\n\n\n2. use `buf` generate server and client code\n\n   - define `buf.gen.yaml` and `buf.yaml`\n    \n    ```text\n    # buf.gen.yaml\n    \n    version: v1\n    managed:\n      enabled: true\n      go_package_prefix:\n        default: github.com/fanchunke/chapic/example\n        except:\n          - buf.build/googleapis/googleapis\n    plugins:\n      # Use protoc-gen-go at v1.31.0\n      - plugin: buf.build/protocolbuffers/go:v1.31.0\n        out: .\n        opt: paths=source_relative\n      - plugin: go-chapic\n        out: .\n        opt:\n          - paths=source_relative\n    ```\n    \n    ```text\n    # buf.yaml\n    \n    version: v1\n    breaking:\n      use:\n        - FILE\n    deps:\n      - buf.build/googleapis/googleapis\n    lint:\n      use:\n        - DEFAULT\n    ```\n\n    - generate code\n\n    ```shell\n    buf generate\n    ```\n   \n3. inject custom tags for binding\n\n   ```shell\n   protoc-go-inject-tag -input=\"example/proto/*.pb.go\"\n   ```\n   \n4. run http server\n\n    ```go\n    package main\n\n   import (\n       \"context\"\n   \n       \"github.com/fanchunke/chapic/example/proto\"\n       \"github.com/labstack/echo/v4\"\n   )\n   \n   func main() {\n       e := echo.New()\n       proto.RegisterEchoHTTPServer(e, \u0026EchoService{})\n       e.Logger.Fatal(e.Start(\":8000\"))\n   }\n   \n   type EchoService struct {}\n   \n   func (e *EchoService) UnaryEchoPost(ctx context.Context, req *proto.EchoPostRequest) (*proto.EchoResponse, error) {\n        resp := \u0026proto.EchoResponse{\n            Id:      req.GetId(),\n            Message: req.GetMessage(),\n        }\n        return resp, nil\n   }\n   \n   func (e *EchoService) UnaryEcho(ctx context.Context, req *proto.EchoRequest) (*proto.EchoResponse, error) {\n        resp := \u0026proto.EchoResponse{\n            Id:      req.GetId(),\n            Message: req.GetMessage(),\n        }\n        return resp, nil\n   }\n\n\n    ```\n\n5. test api\n\n   ```shell\n   curl http://127.0.0.1:8000/v1/example/1\\?message\\=test\n   \n   # response\n   {\"id\":1,\"message\":\"test\"}\n   ```\n\n6. use client to call http api\n\n   ```go\n   package main\n   \n   import (\n       \"context\"\n       \"log\"\n       \"time\"\n   \n       \"github.com/fanchunke/chapic/example/proto\"\n       \"github.com/fanchunke/chapic/option\"\n       \"google.golang.org/protobuf/encoding/protojson\"\n   )\n   \n   func main() {\n       ctx := context.Background()\n       client := proto.NewEchoHTTPClient(\n           ctx,\n           option.WithEndpoint(\"http://127.0.0.1:8000\"),\n           option.WithTimeout(5*time.Second),\n       )\n       resp, err := client.UnaryEcho(ctx, \u0026proto.EchoRequest{\n           Id:      1,\n           Message: \"test\",\n       })\n       if err != nil {\n           log.Fatal(err)\n       }\n       data, err := protojson.Marshal(resp)\n       if err != nil {\n           log.Fatal(err)\n       }\n       log.Printf(\"%s\", string(data))\n   }\n   \n   ```\n   \nresult:\n\n```shell\n{\"id\":1,\"message\":\"test\"}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffanchunke%2Fchapic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffanchunke%2Fchapic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffanchunke%2Fchapic/lists"}