{"id":29774482,"url":"https://github.com/go-leo/gorilla","last_synced_at":"2025-08-15T14:16:29.329Z","repository":{"id":305790892,"uuid":"1021249286","full_name":"go-leo/gorilla","owner":"go-leo","description":"Generate the Gorilla routing file based on the protobuf and Google API rules","archived":false,"fork":false,"pushed_at":"2025-08-12T02:53:04.000Z","size":4581,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-12T04:25:26.627Z","etag":null,"topics":["go","golang","googleapis","gorilla-mux","http","http-router","protocol","restful","restful-api"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/go-leo.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-07-17T05:57:43.000Z","updated_at":"2025-08-12T02:53:08.000Z","dependencies_parsed_at":"2025-07-22T03:37:23.924Z","dependency_job_id":"9cdef9ba-d0ea-4858-8248-66e5262dca6a","html_url":"https://github.com/go-leo/gorilla","commit_stats":null,"previous_names":["go-leo/gorilla"],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/go-leo/gorilla","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-leo%2Fgorilla","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-leo%2Fgorilla/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-leo%2Fgorilla/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-leo%2Fgorilla/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/go-leo","download_url":"https://codeload.github.com/go-leo/gorilla/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-leo%2Fgorilla/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270083807,"owners_count":24524024,"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","status":"online","status_checked_at":"2025-08-12T02:00:09.011Z","response_time":80,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["go","golang","googleapis","gorilla-mux","http","http-router","protocol","restful","restful-api"],"created_at":"2025-07-27T08:07:54.036Z","updated_at":"2025-08-15T14:16:29.320Z","avatar_url":"https://github.com/go-leo.png","language":"Go","readme":"# gorilla\ngorilla 参考 Google API 设计方案，通过定义 proto 文件，快速生成Go语言的Restful服务路由。\n\n# 路由规则\ngorilla 底层基于 [gorilla/mux](http://github.com/gorilla/mux) 管理http路由。详细定义规则见[gorilla/mux](https://github.com/gorilla/mux)\n\n# 优点\n1. 基于proto文件，快速生成Restful服务路由\n2. 零配置\n3. 低依赖\n4. 非反射取值，效率非常高\n5. 稳定，所有方法经过单元测试\n6. 代码简单，良好的代码设计，减少出错\n\n# 安装\n```\ngo install github.com/go-leo/gorilla/cmd/protoc-gen-gorilla@latest\n```\n\n# Example\n```protobuf\nsyntax = \"proto3\";\npackage leo.gorilla.example.user.v1;\noption go_package = \"github.com/go-leo/gorilla/example/user/v1;user\";\n\nimport \"google/api/annotations.proto\";\n\nservice User {\n\n  // CreateUser 创建用户\n  // `POST /v1/user { \"name\": \"Leo\" }` | `CreateUserRequest(name: \"Leo\")`\n  rpc CreateUser (CreateUserRequest) returns (CreateUserResponse) {\n    option (google.api.http) = {\n      post : \"/v1/user\"\n      body : \"*\"\n    };\n  }\n\n  // DeleteUser 删除用户\n    // `DELETE /v1/user/10000 | `DeleteUserRequest(id: 10000)`\n  rpc DeleteUser (DeleteUserRequest) returns (DeleteUserResponse) {\n    option (google.api.http) = {\n      delete : \"/v1/user/{id}\"\n    };\n  }\n\n  // ModifyUser 修改用户\n  // `PUT /v1/user/10000 { \"name\": \"Leo\" }` | `ModifyUserRequest(id: 10000, name: \"Leo\")`\n  rpc ModifyUser (ModifyUserRequest) returns (ModifyUserResponse) {\n    option (google.api.http) = {\n      put : \"/v1/user/{id}\"\n      body : \"*\"\n    };\n  }\n\n  // UpdateUser 更新用户\n  // `PUT /v1/user/10000 { \"id\": \"99999\" ,\"name\": \"Leo\" }` | `UpdateUserRequest(id: 10000, UserItem(id: 9999, name: \"Leo\"))`\n  rpc UpdateUser (UpdateUserRequest) returns (UpdateUserResponse) {\n    option (google.api.http) = {\n      patch : \"/v1/user/{id}\"\n      body : \"item\"\n    };\n  }\n\n  // GetUser 获取用户\n  // `GET /v1/user/10000` | `GetUserRequest(id: 10000)`\n  rpc GetUser (GetUserRequest) returns (GetUserResponse) {\n    option (google.api.http) = {\n      get : \"/v1/user/{id}\"\n    };\n  }\n\n  // ListUser 获取用户列表\n  // `GET /v1/users?page_num=1\u0026page_size=10` | `ListUserRequest(page_num: 1, page_size: 10)`\n  rpc ListUser (ListUserRequest) returns (ListUserResponse) {\n    option (google.api.http) = {\n      get : \"/v1/users\"\n    };\n  }\n}\n\nmessage UserItem {\n  int64 id = 1;\n  string name = 2;\n}\n\nmessage CreateUserRequest {\n  string name = 1;\n}\n\nmessage CreateUserResponse {\n  UserItem item = 1;\n}\n\nmessage DeleteUserRequest {\n  int64 id = 1;\n}\n\nmessage DeleteUserResponse {\n  int64 id = 1;\n}\n\nmessage ModifyUserRequest {\n  int64 id = 1;\n  string name = 2;\n}\n\nmessage ModifyUserResponse {\n    int64 id = 1;\n  string name = 2;\n}\n\nmessage UpdateUserRequest {\n  int64 id = 1;\n  UserItem item = 2;\n}\n\nmessage UpdateUserResponse {\n  int64 id = 1;\n  UserItem item = 2;\n}\n\nmessage GetUserRequest {\n  int64 id = 1;\n}\n\nmessage GetUserResponse {\n  UserItem item = 1;\n}\n\nmessage ListUserRequest {\n  int64 page_num = 1;\n  int64 page_size = 2;\n}\n\nmessage ListUserResponse {\n  int64 page_num = 1;\n  int64 page_size = 2;\n  repeated UserItem list = 3;\n}\n```\n定义了6个接口：分别是\n1. 创建用户，POST请求\n2. 删除用户，DELETE请求\n3. 修改用户，PUT请求\n4. 更新用户，PATCH请求\n5. 获取用户, GET请求\n6. 获取用户列表, GET请求\n\n# 生成路由\n执行命令\n```\nprotoc \\\n--proto_path=. \\\n--proto_path=../third_party \\\n--proto_path=../../ \\\n--go_out=. \\\n--go_opt=paths=source_relative \\\n--gorilla_out=. \\\n--gorilla_opt=paths=source_relative \\\nuser/user.proto\n```\n生成一下文件\n```\nuser\n├── user_gorilla.pb.go\n├── user_test.go\n├── user.pb.go\n└── user.proto\n```\n\n# 实现UserService代码：\n```go\n\ntype MockUserService struct{}\n\nfunc (m *MockUserService) CreateUser(ctx context.Context, req *CreateUserRequest) (*CreateUserResponse, error) {\n\treturn \u0026CreateUserResponse{Item: \u0026UserItem{Id: 1, Name: req.Name}}, nil\n}\n\nfunc (m *MockUserService) DeleteUser(ctx context.Context, req *DeleteUserRequest) (*DeleteUserResponse, error) {\n\treturn \u0026DeleteUserResponse{Id: req.GetId()}, nil\n}\n\nfunc (m *MockUserService) ModifyUser(ctx context.Context, req *ModifyUserRequest) (*ModifyUserResponse, error) {\n\treturn \u0026ModifyUserResponse{Id: req.GetId(), Name: req.GetName()}, nil\n}\n\nfunc (m *MockUserService) UpdateUser(ctx context.Context, req *UpdateUserRequest) (*UpdateUserResponse, error) {\n\treturn \u0026UpdateUserResponse{Id: req.GetId(), Item: \u0026UserItem{Id: req.GetItem().GetId(), Name: req.GetItem().GetName()}}, nil\n}\n\nfunc (m *MockUserService) GetUser(ctx context.Context, req *GetUserRequest) (*GetUserResponse, error) {\n\treturn \u0026GetUserResponse{Item: \u0026UserItem{Id: req.Id, Name: \"test\"}}, nil\n}\n\nfunc (m *MockUserService) ListUser(ctx context.Context, req *ListUserRequest) (*ListUserResponse, error) {\n\treturn \u0026ListUserResponse{\n\t\tPageNum:  req.GetPageNum(),\n\t\tPageSize: req.GetPageSize(),\n\t\tList: []*UserItem{\n\t\t\t{Id: 1, Name: \"a\"},\n\t\t\t{Id: 2, Name: \"b\"},\n\t\t},\n\t}, nil\n}\n```\n\n# 创建Server\n```go\nfunc main() {\n\trouter := mux.NewRouter()\n\trouter = AppendUserGorillaRoute(router, \u0026MockUserService{})\n\tserver := http.Server{Addr: \":8000\", Handler: router}\n\tserver.ListenAndServe()\n}\n```\n\n更多示例见 [example]https://github.com/go-leo/gorilla/tree/example/user/server\n\n# 子妹项目\n* [github.com/go-leo/gonic](https://github.com/go-leo/gonic) 使用 gin-gonic/gin 管理路由。\n* [github.com/go-leo/goose](https://github.com/go-leo/goose) 使用 Go 1.22 HTTP Router 管理路由。\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgo-leo%2Fgorilla","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgo-leo%2Fgorilla","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgo-leo%2Fgorilla/lists"}