{"id":22332711,"url":"https://github.com/xgfone/go-apiserver","last_synced_at":"2025-07-29T19:33:25.349Z","repository":{"id":38775126,"uuid":"430335859","full_name":"xgfone/go-apiserver","owner":"xgfone","description":"An library to build the API server","archived":false,"fork":false,"pushed_at":"2024-11-22T09:21:59.000Z","size":1275,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-22T10:25:40.322Z","etag":null,"topics":["api","api-gateway","api-server","apigateway","apiserver","gateway","gateway-api","go","golang","http","router","server","service"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xgfone.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-11-21T10:32:54.000Z","updated_at":"2024-11-22T09:22:02.000Z","dependencies_parsed_at":"2023-12-20T15:05:33.010Z","dependency_job_id":"21965123-4253-4641-9346-670dc7252f3a","html_url":"https://github.com/xgfone/go-apiserver","commit_stats":{"total_commits":854,"total_committers":2,"mean_commits":427.0,"dds":0.02810304449648715,"last_synced_commit":"1ae4c075d2a7336b02d7f4f06f2a69d3c7b38d48"},"previous_names":[],"tags_count":68,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xgfone%2Fgo-apiserver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xgfone%2Fgo-apiserver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xgfone%2Fgo-apiserver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xgfone%2Fgo-apiserver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xgfone","download_url":"https://codeload.github.com/xgfone/go-apiserver/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228041975,"owners_count":17860345,"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":["api","api-gateway","api-server","apigateway","apiserver","gateway","gateway-api","go","golang","http","router","server","service"],"created_at":"2024-12-04T04:19:27.905Z","updated_at":"2025-07-29T19:33:25.330Z","avatar_url":"https://github.com/xgfone.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-apiserver\n\n[![Build Status](https://github.com/xgfone/go-apiserver/actions/workflows/go.yml/badge.svg)](https://github.com/xgfone/go-apiserver/actions/workflows/go.yml)\n[![GoDoc](https://pkg.go.dev/badge/github.com/xgfone/go-apiserver)](https://pkg.go.dev/github.com/xgfone/go-apiserver)\n[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg?style=flat-square)](https://raw.githubusercontent.com/xgfone/go-apiserver/master/LICENSE)\n![Minimum Go Version](https://img.shields.io/github/go-mod/go-version/xgfone/go-apiserver?label=Go%2B)\n![Latest SemVer](https://img.shields.io/github/v/tag/xgfone/go-apiserver?sort=semver)\n\nThe library is used to build an API server.\n\n## Install\n\n```shell\n$ go get -u github.com/xgfone/go-apiserver\n```\n\n## Example\n\n### Simple HTTP Router\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"net/http\"\n\n\t\"github.com/xgfone/go-apiserver/http/middleware\"\n\t\"github.com/xgfone/go-apiserver/http/middleware/context\"\n\t\"github.com/xgfone/go-apiserver/http/middleware/logger\"\n\t\"github.com/xgfone/go-apiserver/http/middleware/recover\"\n\t\"github.com/xgfone/go-apiserver/http/reqresp\"\n\t\"github.com/xgfone/go-apiserver/http/router\"\n\t\"github.com/xgfone/go-apiserver/http/router/ruler\"\n\t\"github.com/xgfone/go-apiserver/http/server\"\n)\n\nfunc httpHandler(route string) http.HandlerFunc {\n\treturn func(w http.ResponseWriter, r *http.Request) {\n\t\tc := reqresp.GetContext(r.Context())\n\t\tfmt.Fprintf(w, \"%s: %s\", route, c.Data[\"id\"])\n\t}\n}\n\nfunc main() {\n\t// Build the routes.\n\trouteManager := ruler.NewRouter()\n\trouteManager.Path(\"/path1/{id}\").Method(\"GET\").Handler(httpHandler(\"route1\"))\n\trouteManager.Path(\"/path2/{id}\").GET(httpHandler(\"route2\"))\n\n\trouter := router.NewRouter(routeManager)\n\trouter.Use(middleware.MiddlewareFunc(context.Context)) // Use a function as middleware\n\trouter.Use(\n\t\tmiddleware.New(\"logger\", 1, logger.Logger),    // Use the named priority middleware\n\t\tmiddleware.New(\"recover\", 2, recover.Recover), // Use the named priority middleware\n\t)\n\n\t// http.ListenAndServe(\"127.0.0.1:80\", router)\n\tserver.Start(\"127.0.0.1:80\", router)\n\n\t// Open a terminal and run the program:\n\t// $ go run main.go\n\t//\n\t// Open another terminal and run the http client:\n\t// $ curl http://127.0.0.1/path1/123\n\t// route1: 123\n\t// $ curl http://127.0.0.1/path2/123\n\t// route2: 123\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxgfone%2Fgo-apiserver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxgfone%2Fgo-apiserver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxgfone%2Fgo-apiserver/lists"}