{"id":17647469,"url":"https://github.com/qneyrat/go-grpc-endpoints","last_synced_at":"2025-05-07T05:48:18.200Z","repository":{"id":77547436,"uuid":"145593806","full_name":"qneyrat/go-grpc-endpoints","owner":"qneyrat","description":"protoc plugin to auto-generate endpoints layer","archived":false,"fork":false,"pushed_at":"2019-02-11T15:39:33.000Z","size":174,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-31T07:01:33.992Z","etag":null,"topics":["grpc","protobuf","protoc"],"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/qneyrat.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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-08-21T16:57:28.000Z","updated_at":"2019-02-11T16:32:07.000Z","dependencies_parsed_at":null,"dependency_job_id":"516ff6fe-5333-4fbf-a24f-a2fce06fe8d7","html_url":"https://github.com/qneyrat/go-grpc-endpoints","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/qneyrat%2Fgo-grpc-endpoints","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qneyrat%2Fgo-grpc-endpoints/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qneyrat%2Fgo-grpc-endpoints/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qneyrat%2Fgo-grpc-endpoints/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/qneyrat","download_url":"https://codeload.github.com/qneyrat/go-grpc-endpoints/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252823689,"owners_count":21809708,"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":["grpc","protobuf","protoc"],"created_at":"2024-10-23T11:13:32.708Z","updated_at":"2025-05-07T05:48:18.177Z","avatar_url":"https://github.com/qneyrat.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-grpc-endpoints\n\nProtoc plugin to use composition on gRPC server.\n\n## Installing and using\n\nInstall with `go get`:\n```\n\u003e $ go get github.com/qneyrat/go-grpc-endpoints/protoc-gen-goendpoints\n\u003e $ go install github.com/qneyrat/go-grpc-endpoints/protoc-gen-goendpoints\n```\n\nAdd `--goendpoints_out=` flag to generage endpoints layer with protoc:\n```\n\u003e $ protoc -I . ./translator.proto --go_out=plugins=grpc:. --goendpoints_out=.:.   \n```\n\n## Plugin and endpoints layer usage\n\nPlugin auto-generate strucs and func for endpoints layer from your proto files.\n\nEndpointsWrapper is gRPC server. It's implement gRPC server interface and call endpoints\n\nEndpoints struct is endpoints group to create EndpointsWrapper.\n\nYou can just write EndpointFunc constructor to hydrate Endpoints struct:\n\n- create EndpointFunc constructor:\n```go \nfunc NewTranslateEndpoint(t translate.Translator) TranslateEndpointFunc {\n  return func(ctx context.Context, req *proto.TranslateRequest) (*proto.TranslateResponse, error) {\n     // use t.Translate here\n  }\n}\n```\n\n- register EndpointsWrapper on gRPC server:\n```go\n\ttranslator := translate.NewGoogleTranslator()\n\twrapper := NewTranslatorEndpointsWrapper(TranslatorEndpoints{\n\t\tTranslateEndpoint: NewTranslateEndpoint(translator),\n\t})\n\n\ts := grpc.NewServer()\n\tproto.RegisterTranslatorServer(s, wrapper)\n\ts.Serve(lis)\n```\n\n## Theory\n\nServiceX represents application services like database repository or domain service.\n\n### gRPC Server without composition\n```Go\ntype Server struct{\n  service1 Service1\n  service2 Service2\n  service3 Service3\n  // ...\n}\n\nfunc (s *Server) Method(ctx context.Context, req *proto.Req) (*proto.Res, error) {\n  // use services here like s.service1.Foo()\n}\n```\n\n### gRPC Server with composition and introduce endpoints layer\n```Go\ntype EndpointFunc1 func(ctx context.Context, req *proto.Req) (*proto.Res, error)\n\nfunc NewEndpointFunc1(service1 Service1,  service2 Service2) EndpointFunc1 {\n  return func(ctx context.Context, req *proto.Req) (*proto.Res, error) {\n      // use services here like s.service1.Foo()\n  }\n}\n\ntype Server struct{\n  endpoint1 EndpointFunc1\n  // ...\n}\n\nfunc (s *Server) Method(ctx context.Context, req *proto.Req) (*proto.Res, error) {\n  return s.endpoint1(ctx, req)\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqneyrat%2Fgo-grpc-endpoints","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fqneyrat%2Fgo-grpc-endpoints","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqneyrat%2Fgo-grpc-endpoints/lists"}