{"id":20213715,"url":"https://github.com/go-spring/starter-grpc","last_synced_at":"2025-05-07T07:33:11.307Z","repository":{"id":57537792,"uuid":"286250623","full_name":"go-spring/starter-grpc","owner":"go-spring","description":"「仅发布」 gRPC 启动器 ( starter for gRPC )","archived":true,"fork":false,"pushed_at":"2022-10-09T09:39:46.000Z","size":2037,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-30T08:01:52.496Z","etag":null,"topics":["go-spring","grpc"],"latest_commit_sha":null,"homepage":"https://go-spring.com","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/go-spring.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}},"created_at":"2020-08-09T14:14:35.000Z","updated_at":"2023-10-01T09:51:01.000Z","dependencies_parsed_at":"2022-09-07T16:41:24.740Z","dependency_job_id":null,"html_url":"https://github.com/go-spring/starter-grpc","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-spring%2Fstarter-grpc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-spring%2Fstarter-grpc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-spring%2Fstarter-grpc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-spring%2Fstarter-grpc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/go-spring","download_url":"https://codeload.github.com/go-spring/starter-grpc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252833917,"owners_count":21811276,"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":["go-spring","grpc"],"created_at":"2024-11-14T06:11:08.037Z","updated_at":"2025-05-07T07:33:10.994Z","avatar_url":"https://github.com/go-spring.png","language":"Go","readme":"# starter-grpc\n\n[English](README_EN.md)\n\n[仅发布] 该项目仅为最终发布，不要向该项目直接提交代码，开发请关注 [go-spring](https://github.com/go-spring/go-spring) 项目。\n\n## Installation\n\n### Prerequisites\n\n- Go \u003e= 1.12\n\n### Using go get\n\n```\ngo get github.com/go-spring/starter-grpc@v1.1.0-rc2 \n```\n\n## Quick Start\n\n### gRPC Server\n\n```\nimport \"github.com/go-spring/starter-grpc/server\"\n```\n\n`main.go`\n\n```\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"log\"\n\n\t\"github.com/go-spring/spring-core/grpc\"\n\t\"github.com/go-spring/spring-core/gs\"\n\tpb \"github.com/go-spring/starter-grpc/example/helloworld\"\n\n\t_ \"github.com/go-spring/starter-grpc/server\"\n)\n\nfunc init() {\n\tgs.Object(new(GreeterServer)).Init(func(s *GreeterServer) {\n\t\tgs.GrpcServer(\"helloworld.Greeter\", \u0026grpc.Server{\n\t\t\tRegister: pb.RegisterGreeterServer,\n\t\t\tService:  s,\n\t\t})\n\t})\n}\n\ntype GreeterServer struct {\n\tAppName string `value:\"${spring.application.name}\"`\n}\n\nfunc (s *GreeterServer) SayHello(ctx context.Context, in *pb.HelloRequest) (*pb.HelloReply, error) {\n\tlog.Printf(\"Received: %v\", in.GetName())\n\treturn \u0026pb.HelloReply{Message: \"Hello \" + in.GetName() + \" from \" + s.AppName}, nil\n}\n\nfunc main() {\n\tgs.Property(\"spring.application.name\", \"GreeterServer\")\n\tgs.Property(\"grpc.server.port\", 50051)\n\tfmt.Println(\"application exit: \", gs.Web(false).Run())\n}\n```\n\n### gRPC Client\n\n```\nimport \"github.com/go-spring/starter-grpc/client\"\n```\n\n`main.go`\n\n```\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\n\t\"github.com/go-spring/spring-core/gs\"\n\t\"github.com/go-spring/spring-core/web\"\n\tpb \"github.com/go-spring/starter-grpc/example/helloworld\"\n\n\t_ \"github.com/go-spring/starter-grpc/client\"\n)\n\nconst (\n\tdefaultName = \"world\"\n)\n\nfunc init() {\n\tgs.GrpcClient(pb.NewGreeterClient, \"greeter\")\n\tgs.Object(\u0026runner{}).Export((*gs.AppRunner)(nil))\n}\n\ntype runner struct {\n\tGreeterClient pb.GreeterClient `autowire:\"\"`\n}\n\nfunc (r *runner) Run(ctx gs.Context) {\n\tresp, err := r.GreeterClient.SayHello(context.TODO(), \u0026pb.HelloRequest{Name: defaultName})\n\tweb.ERROR.Panic(err).When(err != nil)\n\tfmt.Println(\"Greeting: \" + resp.GetMessage())\n\tgo gs.ShutDown()\n}\n\nfunc main() {\n\tgs.Property(\"grpc.endpoint.greeter.address\", \"127.0.0.1:50051\")\n\tgs.Property(\"spring.application.name\", \"GreeterClient\")\n\tfmt.Println(\"application exit: \", gs.Web(false).Run())\n}\n```\n\n## Configuration\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgo-spring%2Fstarter-grpc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgo-spring%2Fstarter-grpc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgo-spring%2Fstarter-grpc/lists"}