{"id":13634757,"url":"https://github.com/bahlo/goat","last_synced_at":"2025-04-18T23:33:02.878Z","repository":{"id":19272593,"uuid":"22509039","full_name":"bahlo/goat","owner":"bahlo","description":"[DEPRECATED] :goat: A minimalistic JSON API server in Go","archived":true,"fork":false,"pushed_at":"2018-02-17T13:51:11.000Z","size":35,"stargazers_count":155,"open_issues_count":4,"forks_count":16,"subscribers_count":13,"default_branch":"master","last_synced_at":"2024-11-09T04:35:47.834Z","etag":null,"topics":["framework","go","json","middleware","rest"],"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/bahlo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-08-01T12:28:21.000Z","updated_at":"2024-06-13T21:18:47.000Z","dependencies_parsed_at":"2022-08-18T15:24:02.283Z","dependency_job_id":null,"html_url":"https://github.com/bahlo/goat","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bahlo%2Fgoat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bahlo%2Fgoat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bahlo%2Fgoat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bahlo%2Fgoat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bahlo","download_url":"https://codeload.github.com/bahlo/goat/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249565250,"owners_count":21292427,"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":["framework","go","json","middleware","rest"],"created_at":"2024-08-02T00:00:33.017Z","updated_at":"2025-04-18T23:33:02.638Z","avatar_url":"https://github.com/bahlo.png","language":"Go","readme":"## :warning: DEPRECATED :warning:\nThis project is no longer maintained, please use something like [gorilla/mux](https://github.com/gorilla/mux) or [echo](https://github.com/labstack/echo).\n\n----\n\n# Goat [![GoDoc](https://godoc.org/github.com/bahlo/goat?status.svg)](https://godoc.org/github.com/bahlo/goat) [![Build Status](https://secure.travis-ci.org/bahlo/goat.svg?branch=master)](https://travis-ci.org/bahlo/goat) [![Coverage Status](https://coveralls.io/repos/bahlo/goat/badge.svg?branch=master)](https://coveralls.io/r/bahlo/goat?branch=master)\n\nGoat is a minimalistic REST API server in Go. You can pronounce it like the\n_goat_, or _go-at_. Depends on how you like goats.\n\n## Contents\n- [Usage](#usage)\n  - [Parameters](#parameters)\n  - [Subrouters](#subrouters)\n  - [Indices](#indices)\n  - [Middleware](#middleware)\n- [Philosophy](#philosophy)\n- [Fedback](#feedback)\n- [Credits](#credits)\n- [License](#license)\n\n## Usage\n### Parameters\nYou can use named parameters and access them through `goat.Params`,\nwich you can treat as any `map[string]string`.\n```go\npackage main\n\nimport (\n    \"net/http\"\n\n    \"github.com/bahlo/goat\"\n)\n\nfunc helloHandler(w http.ResponseWriter, r *http.Request, p goat.Params) {\n    goat.WriteJSON(w, map[string]string{\n        \"hello\": p[\"name\"],\n    })\n}\n\nfunc main() {\n    r := goat.New()\n\n    r.Get(\"/hello/:name\", \"hello_url\", helloHandler)\n\n    r.Run(\":8080\")\n}\n```\n\n### Subrouters\nYou can create subrouters to simplify your code\n```go\nfunc main() {\n    r := goat.New()\n\n    r.Get(\"/hello/:name\", \"hello_url\", helloHandler)\n\n    sr := r.Subrouter(\"/user\")\n    {\n        sr.Post(\"/login\", \"user_login_url\", loginHandler)\n        sr.Get(\"/logout\", \"user_logout_url\", logoutHandler)\n    }\n\n    r.Run(\":8080\")\n}\n```\n\n### Indices\nEvery route can have a description (like `user_login_url`). These can be used\nto automagically generate an API index (like [this](https://api.github.com)).\nIf you want to hide specific methods, just provide an empty string.\n\n```go\nfunc main() {\n    r := goat.New()\n\n    r.Get(\"/\", \"\", r.IndexHandler)\n    r.Get(\"/hello/:name\", \"hello_url\", helloHandler)\n\n    sr := r.Subrouter(\"/user\")\n    {\n        sr.Post(\"/login\", \"user_login_url\", loginHandler)\n        sr.Get(\"/logout\", \"user_logout_url\", logoutHandler)\n    }\n\n    r.Run(\":8080\")\n}\n```\n\nThe above example would return the following response on `/`:\n```json\n{\n  \"hello_url\": \"/hello/:name\",\n  \"user_logout_url\": \"/user/logout\"\n}\n```\n\n**Note:** Indices are only supported for `GET` requests. Open an issue, if you\nwant them on other methods, too\n\n### Middleware\nYou can easily include any middleware you like. A great guide to middleware\nis found\n[here](https://github.com/julienschmidt/httprouter#where-can-i-find-middleware-x).\nImportant is, that it's in the following format:\n```go\nfunc(http.Handler) http.Handler\n```\n\nExample:\n```go\nfunc main() {\n    r := goat.New()\n\n    r.Get(\"/hello/:name\", \"hello_url\", helloHandler)\n    r.Use(loggerMiddleware, gzipMiddleware)\n\n    r.Run(\":8080\")\n}\n```\n\n#### Wrapping middleware\nSometimes middleware isn't in the required format, so you have to build a\nwrapper around it. This example shows a wrapper around\n`handlers.CombinedLoggingHandler` from the\n[Gorilla handlers](http://www.gorillatoolkit.org/pkg/handlers):\n\n```go\nfunc loggerMiddleware(h http.Handler) http.Handler {\n    // Create logfile (you should check for errors)\n    f, _ := os.Create(\"api.log\")\n    return handlers.CombinedLoggingHandler(f, h)\n}\n```\n\nYou can now safely use the middleware in Goat:\n\n```go\nfunc main() {\n    r := goat.New()\n\n    r.Get(\"/hello/:name\", \"hello_url\", helloHandler)\n    r.Use(loggerMiddleware)\n\n    r.Run(\":8080\")\n}\n```\n\n## Philosophy\nI wanted to create a small, fast and reliable REST API server, which supports\nquick JSON and error output, good rooting and easy-to-use middleware.\n\nI have split the files after responsibility to make it easy for everyone to\ndive in (start with `goat.go`).\n\n## Feedback\nIf you have problems, feel free to\n[create an issue](https://github.com/bahlo/goat/issues) or drop me an email\nat \u003challo@arne.me\u003e!\n\n## Credits\nThanks to Julien Schmidt for the amazing\n[httprouter](https://github.com/julienschmidt/httprouter) used in this\nproject.\n\n## License\nThis project is licensed unter MIT, for more information look into the LICENSE\nfile.\n","funding_links":[],"categories":["`API Frameworks`","Animals","Web Frameworks","Servers","API Frameworks"],"sub_categories":["Go","Advanced Console UIs","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbahlo%2Fgoat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbahlo%2Fgoat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbahlo%2Fgoat/lists"}