{"id":13694326,"url":"https://github.com/dolab/gogo","last_synced_at":"2026-01-17T22:23:35.076Z","repository":{"id":57485751,"uuid":"49428252","full_name":"dolab/gogo","owner":"dolab","description":"Modern microservice web framework of golang","archived":false,"fork":false,"pushed_at":"2019-03-03T13:44:56.000Z","size":3625,"stargazers_count":42,"open_issues_count":1,"forks_count":13,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-03T01:46:58.155Z","etag":null,"topics":["framework","golang","grpc","restful-webservices"],"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/dolab.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":"2016-01-11T13:30:33.000Z","updated_at":"2024-11-24T18:01:56.000Z","dependencies_parsed_at":"2022-09-02T00:10:33.652Z","dependency_job_id":null,"html_url":"https://github.com/dolab/gogo","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/dolab/gogo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dolab%2Fgogo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dolab%2Fgogo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dolab%2Fgogo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dolab%2Fgogo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dolab","download_url":"https://codeload.github.com/dolab/gogo/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dolab%2Fgogo/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28520243,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-17T22:11:28.393Z","status":"ssl_error","status_checked_at":"2026-01-17T22:11:27.841Z","response_time":85,"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":["framework","golang","grpc","restful-webservices"],"created_at":"2024-08-02T17:01:29.425Z","updated_at":"2026-01-17T22:23:35.060Z","avatar_url":"https://github.com/dolab.png","language":"Go","funding_links":[],"categories":["开源类库","Open source library","Go"],"sub_categories":["微服务","Microservices"],"readme":"# gogo\n\n[![CircleCI](https://circleci.com/gh/dolab/gogo/tree/master.svg?style=svg)](https://circleci.com/gh/dolab/gogo/tree/master) [![Coverage](http://gocover.io/_badge/github.com/dolab/gogo?0)](http://gocover.io/github.com/dolab/gogo) [![GoDoc](https://godoc.org/github.com/dolab/gogo?status.svg)](http://godoc.org/github.com/dolab/gogo)\n\n`gogo` is an open source, high performance RESTful api framework for the [Golang](https://golang.org) programming language. It also support RPC api, which is similar to [gRPC](https://grpc.io), defined by [protobuf](https://developers.google.com/protocol-buffers/).\n\nIt's heavily inspired from [rails](http://rubyonrails.org/) for best practice.\n\n\u003e NOTE: From *VERSION 2*, gogo requires `go1.10+` support. We **Strongly** advice you to start from it for your product. If you want to support `go1.6` or older, please use released tag [v1.1.0](https://github.com/dolab/gogo/releases/tag/v1.1.0) instead.\n\n## Install\n\n```bash\n$ go get github.com/dolab/gogo/cmd/gogo\n```\n\n- Create application using scaffold tools\n\n```bash\n# show gogo helps\n$ gogo -h\n\n# create a new application\n$ gogo new myapp\n\n# resolve dependences\n$ cd myapp\n$ make\n\n# generate controller\n# NOTE: you should update application.go and add app.Resource(\"/user\", User) route by hand\n$ gogo g c user\n\n# generate filter\n$ gogo g f session\n\n# generate model\n$ gogo g m user\n\n# run test\n$ make\n\n# run development server\n$ make godev\n```\n\n\n## Getting Started\n\n- Normal\n\n```go\npackage main\n\nimport (\n\t\"net/http\"\n\n\t\"github.com/dolab/gogo\"\n)\n\nfunc main() {\n\t// load config from config/application.yml\n\t// app := gogo.New(\"development\", \"/path/to/[config/application.yml]\")\n\n\t// load config from filename\n\t// app := gogo.New(\"development\", \"/path/to/config.yml\")\n\n\t// use default config\n\tapp := gogo.NewDefaults()\n\n\t// GET /\n\tapp.GET(\"/\", func(ctx *gogo.Context) {\n\t\tctx.Text(\"Hello, gogo!\")\n\t})\n\n\t// GET /hello/:name\n\tapp.HandlerFunc(http.MethodGet, \"/hello/:name\", func(w http.ResponseWriter, r *http.Request) {\n\t\tparams := gogo.NewParams(r)\n\n\t\tname := params.Get(\"name\")\n\t\tif name == \"\" {\n\t\t\tname = \"gogo\"\n\t\t}\n\n\t\tw.WriteHeader(http.StatusOK)\n\t\tw.Write([]byte(\"Hello, \" + name + \"!\"))\n\t})\n\n\tapp.Run()\n}\n```\n\n- Using Middlewares\n\nMiddlewares is the best practice of doing common processing when handling a request.\n\n```go\npackage main\n\nimport (\n\t\"github.com/dolab/gogo\"\n)\n\nfunc main() {\n\tapp := gogo.NewDefaults()\n\n\t// avoid server quit by registering a recovery filter\n\tapp.Use(func(ctx *gogo.Context) {\n\t\tif panicErr := recover(); panicErr != nil {\n\t\t\tctx.Logger.Errorf(\"[PANICED] %v\", panicErr)\n\n\t\t\tctx.SetStatus(http.StatusInternalServerError)\n\t\t\tctx.Json(map[string]interface{}{\n\t\t\t\t\"panic\": panicErr,\n\t\t\t})\n\t\t\treturn\n\t\t}\n\n\t\tctx.Next()\n\t})\n\n\t// GET /\n\tapp.GET(\"/\", func(ctx *gogo.Context) {\n\t\tpanic(\"Oops ~ ~ ~\")\n\t})\n\n\tapp.Run()\n}\n```\n\n- Using AppGroup\n\nAppGroup is useful when defining resources with shared middlewares and the same uri prefix.\n\n```go\npackage main\n\nimport (\n\t\"encoding/base64\"\n\t\"net/http\"\n\t\"strings\"\n\n\t\"github.com/dolab/gogo\"\n)\n\nfunc main() {\n\tapp := gogo.NewDefaults()\n\n\t// avoid server quit by registering recovery func global\n\tapp.Use(func(ctx *gogo.Context) {\n\t\tif panicErr := recover(); panicErr != nil {\n\t\t\tctx.Logger.Errorf(\"[PANICED] %v\", panicErr)\n\n\t\t\tctx.SetStatus(http.StatusInternalServerError)\n\t\t\tctx.Json(map[string]interface{}{\n\t\t\t\t\"panic\": panicErr,\n\t\t\t})\n\t\t\treturn\n\t\t}\n\n\t\tctx.Next()\n\t})\n\n\t// NewGroup creates sub resources with /v1 prefix, and apply basic auth filter for all sub-resources.\n\t// NOTE: it combines recovery filter from previous.\n\tv1 := app.NewGroup(\"/v1\", func(ctx *gogo.Context) {\n\t\tauth := ctx.Header(\"Authorization\")\n\t\tif !strings.HasPrefix(auth, \"Basic \") {\n\t\t\tctx.SetStatus(http.StatusForbidden)\n\t\t\treturn\n\t\t}\n\n\t\tb, err := base64.StdEncoding.DecodeString(strings.TrimPrefix(auth, \"Basic \"))\n\t\tif err != nil {\n\t\t\tctx.Logger.Errorf(\"Base64 decode error: %v\", err)\n\n\t\t\tctx.SetStatus(http.StatusForbidden)\n\t\t\treturn\n\t\t}\n\n\t\ttmp := strings.SplitN(string(b), \":\", 2)\n\t\tif len(tmp) != 2 || tmp[0] != \"gogo\" || tmp[1] != \"ogog\" {\n\t\t\tctx.SetStatus(http.StatusForbidden)\n\t\t\treturn\n\t\t}\n\n\t\t// settings which can used by following filters and handler\n\t\tctx.Set(\"username\", tmp[0])\n\n\t\tctx.Next()\n\t})\n\n\t// GET /v1/user\n\tv1.GET(\"/user\", func(ctx *gogo.Context) {\n\t\tusername := ctx.MustGet(\"username\").(string)\n\n\t\tctx.Text(\"Hello, \" + username + \"!\")\n\t})\n\n\tapp.Run()\n}\n```\n\n- Use Resource Controller\n\nYou can implement a *controller* with optional `Index`, `Create`, `Explore`, `Show`, `Update` and `Destroy` methods, \nand use `app.Resource(\"/myresource\", \u0026MyController)` to register all RESTful routes auto.\n\nNOTE: When your resource has a inheritance relationship, there **MUST NOT** be two same id key.\nyou can overwrite default id key by implementing `ControllerID` interface.\n\n```go\npackage main\n\nimport (\n\t\"github.com/dolab/gogo\"\n)\n\ntype GroupController struct{}\n\n// GET /group\nfunc (t *GroupController) Index(ctx *gogo.Context) {\n\tctx.Text(\"GET /group\")\n}\n\n// GET /group/:group\nfunc (t *GroupController) Show(ctx *gogo.Context) {\n\tctx.Text(\"GET /group/\" + ctx.Params.Get(\"group\"))\n}\n\ntype UserController struct{}\n\n// overwrite default :user key with :id\nfunc (t *UserController) ID() string {\n\treturn \"id\"\n}\n\n// GET /group/:group/user/:id\nfunc (t *UserController) Show(ctx *gogo.Context) {\n\tctx.Text(\"GET /group/\" + ctx.Params.Get(\"group\") + \"/user/\" + ctx.Params.Get(\"id\"))\n}\n\nfunc main() {\n\tapp := gogo.NewDefaults()\n\n\t// register group controller with default :group key\n\tgroup := app.Resource(\"/group\", \u0026GroupController{})\n\n\t// nested user controller within group resource\n\t// NOTE: it overwrites default :user key by implmenting gogo.ControllerID interface.\n\tgroup.Resource(\"/user\", \u0026UserController{})\n\n\tapp.Run()\n}\n```\n\n## Configures\n\n- Server\n\n```yaml\n---\nname: gogo\nmode: test\n\ndefault_server: \u0026default_server\n  addr: localhost\n  port: 9090\n  ssl: false\n  request_timeout: 3\n  response_timeout: 10\n  request_id: X-Request-Id\n\ndefault_logger: \u0026default_logger\n  output: nil\n  level: debug\n  filter_params:\n    - password\n    - password_confirmation\n\nsections:\n  test:\n    server:\n      \u003c\u003c: *default_server\n      request_id: ''\n    logger:\n      \u003c\u003c: *default_logger\n    domain: https://example.com\n    getting_start:\n      greeting: Hello, gogo!\n    debug: false\n```\n\n## Benchmarks\n\n![benchmarks](./testdata/gogo-benchmarks.png)\n\n## TODOs\n\n- [x] server config context\n- [x] support http.Request context\n- [x] scoffold \u0026\u0026 generator\n- [x] mountable third-part app\n- [x] gRPC support\n\n## Thanks\n\n- [httprouter](https://github.com/julienschmidt/httprouter)\n\n## Author\n\n[Spring MC](https://twitter.com/mcspring)\n\n## LICENSE\n\n```\nThe MIT License (MIT)\n\nCopyright (c) 2016\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdolab%2Fgogo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdolab%2Fgogo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdolab%2Fgogo/lists"}