{"id":37126296,"url":"https://github.com/killlowkey/go-micro-example","last_synced_at":"2026-01-14T14:35:45.767Z","repository":{"id":242172994,"uuid":"808873366","full_name":"killlowkey/go-micro-example","owner":"killlowkey","description":"go-micro grpc example","archived":false,"fork":false,"pushed_at":"2024-06-01T03:59:21.000Z","size":35,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-07-13T09:14:32.529Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/killlowkey.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":"2024-06-01T03:21:20.000Z","updated_at":"2024-06-01T03:59:24.000Z","dependencies_parsed_at":"2024-06-01T04:58:58.775Z","dependency_job_id":null,"html_url":"https://github.com/killlowkey/go-micro-example","commit_stats":null,"previous_names":["killlowkey/go-micro-example"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/killlowkey/go-micro-example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/killlowkey%2Fgo-micro-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/killlowkey%2Fgo-micro-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/killlowkey%2Fgo-micro-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/killlowkey%2Fgo-micro-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/killlowkey","download_url":"https://codeload.github.com/killlowkey/go-micro-example/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/killlowkey%2Fgo-micro-example/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28423755,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T13:30:50.153Z","status":"ssl_error","status_checked_at":"2026-01-14T13:29:08.907Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5: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":[],"created_at":"2026-01-14T14:35:45.177Z","updated_at":"2026-01-14T14:35:45.754Z","avatar_url":"https://github.com/killlowkey.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"## 参考文档\n1. https://github.com/go-micro/generator\n2. https://github.com/go-micro/examples/tree/main/greeter\n\n## 安装工具库\n```shell\ngo install google.golang.org/protobuf/cmd/protoc-gen-go@latest\ngo install github.com/go-micro/generator/cmd/protoc-gen-micro@latest\n```\n\n## 创建项目并安装依赖\n```shell\nmkdir -p example\ncd example\ngo mod init github.com/killlowkey/go-micro-example\n\ngo get google.golang.org/protobuf\ngo get go-micro.dev/v4\n```\n\n## 编写 proto 文件\n在 proto 目录下创建 greeter.proto 文件，并填充如下内容\n```proto\nsyntax = \"proto3\";\n\npackage pb;\noption go_package = \"pkg/proto;pb\";\n\nservice Greeter {\n\trpc Hello(Request) returns (Response) {}\n}\n\nmessage Request {\n\tstring name = 1;\n}\n\nmessage Response {\n\tstring msg = 1;\n}\n```\n\n## 生成代码\n```shell\nprotoc --proto_path=. --micro_out=. --go_out=. proto/greeter.proto\n```\n\n## 服务端代码\ncmd/server/main.go\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"github.com/killlowkey/go-micro-example/pkg/proto\"\n\t\"go-micro.dev/v4\"\n\t\"google.golang.org/grpc\"\n\t\"log\"\n\t\"time\"\n)\n\ntype Greeter struct{}\n\nfunc (g *Greeter) Hello(ctx context.Context, req *pb.Request, rsp *pb.Response) error {\n\trsp.Msg = \"Hello \" + req.Name\n\treturn nil\n}\n\nfunc main() {\n\tgo func() {\n\t\tfor {\n\t\t\tgrpc.DialContext(context.TODO(), \"127.0.0.1:9091\")\n\t\t\ttime.Sleep(time.Second)\n\t\t}\n\t}()\n\n\tservice := micro.NewService(\n\t\tmicro.Name(\"go.micro.srv.greeter\"),\n\t)\n\n\t// optionally setup command line usage\n\tservice.Init()\n\n\t// Register Handlers\n\tif err := pb.RegisterGreeterHandler(service.Server(), \u0026Greeter{}); err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\t// Run server\n\tif err := service.Run(); err != nil {\n\t\tlog.Fatal(err)\n\t}\n}\n```\n\n## 客户端代码\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\n\t\"github.com/killlowkey/go-micro-example/pkg/proto\"\n\t\"go-micro.dev/v4\"\n)\n\nfunc main() {\n\t// create a new service\n\tservice := micro.NewService()\n\n\t// parse command line flags\n\tservice.Init()\n\n\t// Use the generated client stub\n\tcl := pb.NewGreeterService(\"go.micro.srv.greeter\", service.Client())\n\n\t// Make request\n\trsp, err := cl.Hello(context.Background(), \u0026pb.Request{\n\t\tName: \"John\",\n\t})\n\tif err != nil {\n\t\tfmt.Println(err)\n\t\treturn\n\t}\n\n\tfmt.Println(rsp.Msg)\n}\n```\n## 运行服务端\n\u003e 运行之前执行 go mod tidy\n```shell\ngo run cmd/server/main.go\n```\n\n## 运行客户端\n\u003e 运行之前执行 go mod tidy\n```shell\ngo run cmd/client/main.go\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkilllowkey%2Fgo-micro-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkilllowkey%2Fgo-micro-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkilllowkey%2Fgo-micro-example/lists"}