{"id":23663778,"url":"https://github.com/daimaou92/gate","last_synced_at":"2026-05-02T01:34:56.754Z","repository":{"id":97269105,"uuid":"402033009","full_name":"daimaou92/gate","owner":"daimaou92","description":"Build REST APIs in Golang","archived":false,"fork":false,"pushed_at":"2022-03-21T20:17:17.000Z","size":123,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-05-20T19:36:54.402Z","etag":null,"topics":["go","golang","golang-library","golang-package","http","http-server","openapi","openapi3","rest","rest-api"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/daimaou92.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}},"created_at":"2021-09-01T11:17:35.000Z","updated_at":"2022-03-21T19:16:51.000Z","dependencies_parsed_at":"2024-06-20T08:21:57.856Z","dependency_job_id":null,"html_url":"https://github.com/daimaou92/gate","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/daimaou92/gate","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daimaou92%2Fgate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daimaou92%2Fgate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daimaou92%2Fgate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daimaou92%2Fgate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/daimaou92","download_url":"https://codeload.github.com/daimaou92/gate/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daimaou92%2Fgate/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32520156,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-02T01:12:54.858Z","status":"ssl_error","status_checked_at":"2026-05-02T01:12:54.261Z","response_time":64,"last_error":"SSL_read: 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":["go","golang","golang-library","golang-package","http","http-server","openapi","openapi3","rest","rest-api"],"created_at":"2024-12-29T05:33:19.676Z","updated_at":"2026-05-02T01:34:56.734Z","avatar_url":"https://github.com/daimaou92.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Gate\n\n---\n\n### This is alpha grade software\n\n---\n\nOpinionated lib based on [httprouter](https://github.com/julienschmidt/httprouter) to build REST APIs.\n\n## Usage\n\n---\n\nUsing `Gate` is a little different than most other frameworks. Using it correctly\nrequires that one decide the request, response and query payload while designing\nan API to the maximum extent feasible. When explicitly defined, as in the example\nbelow, and later fetched using the `Gate` provided attribute - one is saving\non re-allocations.\n\n`Gate` maintains a pool of all the structures explicitly provided when writing\nthe endpoints. These pools are used to reflect back a pre-allocated value,\nwhen present, in the argument of type `RequestData` later received in the handler.\nFresh allocation occurs if needed. More on golang sync pools [here](https://pkg.go.dev/sync#Pool)\n\n## Open API\n\n---\n\nUsing `Gate` as intended lets us generate an OpenAPI based doc right from your code.\nWork is underway to achieve this. This feature is inspired by [Dropshot](https://github.com/oxidecomputer/dropshot).\n\n## Example\n\n---\n\nHere's how a POST request looks in Gate\n\n```go\npackage main\n\nimport (\n\t\"encoding/json\"\n\t\"log\"\n\n\t\"github.com/daimaou92/gate\"\n\t\"github.com/getkin/kin-openapi/openapi3\"\n)\n\n/* gate provides a Payload interface that must be used\nin API definitions and their handlers to access said data.\nSince generics are still a little bit away the definitions\nneed to use a intialized instance of said payload.\nHere's how all that looks*/\n\n// Define a payload type\ntype StringJSON string\n\nfunc (sj StringJSON) Marshal() ([]byte, error) {\n\treturn json.Marshal(sj)\n}\nfunc (sj *StringJSON) Unmarshal(src []byte) error {\n\tvar v string\n\tif err := json.Unmarshal(src, \u0026v); err != nil {\n\t\treturn err\n\t}\n\t*sj = StringJSON(v)\n\treturn nil\n}\nfunc (StringJSON) ContentType() gate.ContentType {\n\treturn gate.ContentTypeJSON\n}\n// The above three functions Marshal, Unmarshal and\n// ContentType implement the gate.Payload interface\n\n// This is just a helper function to get a\n// StringJSON pointer - or a gate.Payload\nfunc NewStringJSON(s string) *StringJSON {\n\tt := StringJSON(s)\n\treturn \u0026t\n}\n\n// below is a request handler that accepts a\n// JSON string and responds back with a JSON\n// string by prepending the pattern \"YOLO\"\nfunc yoloHandler(rc *gate.RequestCtx, rd *gate.RequestData) (gate.Payload, error) {\n\tsj, ok := rd.Body.(*StringJSON)\n\tif !ok {\n\t\t// returning an error automatically responds back with\n\t\t// the corresponding code of the error\n\t\t// Here for example, the client with receive the error code\n\t\t// 400 and a text message \"Bad Request\"\n\t\treturn nil, gate.ErrBadRequest\n\t}\n\tsj = NewStringJSON(\"YOLO\" + string(*sj))\n\treturn sj, nil\n}\n\nfunc main() {\n\t// Now lets define the api server\n\tapp, err := gate.New(gate.AppOptions{\n\t\tInfo: openapi3.Info{\n\t\t\tTitle:   \"sampleAPI\",\n\t\t\tVersion: \"0.0.1\",\n\t\t},\n\t\tAddr: \":8080\",\n\t})\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tsj := NewStringJSON(\"\")\n\t// The usage of `sj` below is only so that gate knows what\n\t// type to marshal and unmarshal the payloads into\n\t// the initialized value sj above serves no other purpose\n\t// at the moment. Maybe this'll be better with generics.\n\t// But this is where we're at now.\n\tapp.Post(gate.EndpointConfig{\n\t\tPath:    \"/yolofy\",\n\t\tHandler: yoloHandler,\n\t\tPayload: gate.EndpointPayload{\n\t\t\tRequestPayload:  sj,\n\t\t\tResponsePayload: sj,\n\t\t},\n\t})\n\tlog.Println(\"Listening at :8080\")\n\tif err := app.Listen(); err != nil {\n\t\tlog.Fatal(err)\n\t}\n}\n\n```\n\nNow simply use CURL to verify:\n`curl -d '\"\"' -H 'Content-Type: application/json' -X POST http://localhost:8080/yolofy`\n\nYou should see `\"YOLO\"` as output.\n\n---\n\n### This documentation like the whole project is also a WIP. It should be updated as soon as I have more time. Thank you for your patience 🙏\n\n---\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaimaou92%2Fgate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdaimaou92%2Fgate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaimaou92%2Fgate/lists"}