{"id":13523490,"url":"https://github.com/didi/gatekeeper","last_synced_at":"2025-06-15T17:11:01.403Z","repository":{"id":45152206,"uuid":"210305519","full_name":"didi/GateKeeper","owner":"didi","description":"A high-performance Golang gateway that supports rapid development and plug-inization","archived":false,"fork":false,"pushed_at":"2023-05-05T02:28:43.000Z","size":18645,"stargazers_count":440,"open_issues_count":1,"forks_count":72,"subscribers_count":21,"default_branch":"master","last_synced_at":"2025-04-11T01:39:42.155Z","etag":null,"topics":["gateway","gateway-microservice","golang"],"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/didi.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,"governance":null}},"created_at":"2019-09-23T08:41:09.000Z","updated_at":"2025-03-27T03:15:11.000Z","dependencies_parsed_at":"2022-07-13T18:19:38.189Z","dependency_job_id":"da10a62f-a17c-4c48-aa2b-850045b7461f","html_url":"https://github.com/didi/GateKeeper","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/didi/GateKeeper","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/didi%2FGateKeeper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/didi%2FGateKeeper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/didi%2FGateKeeper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/didi%2FGateKeeper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/didi","download_url":"https://codeload.github.com/didi/GateKeeper/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/didi%2FGateKeeper/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260016055,"owners_count":22946321,"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":["gateway","gateway-microservice","golang"],"created_at":"2024-08-01T06:01:00.588Z","updated_at":"2025-06-15T17:11:01.370Z","avatar_url":"https://github.com/didi.png","language":"Go","funding_links":[],"categories":["Gateway"],"sub_categories":[],"readme":"# 项目介绍\nGateKeeper是一款golang编写的支持快速开发、插件化的高性能网关。使用二进制文件安装即刻体验网关功能。\n\n功能特性：   \n1、快速开发：插件化支持功能拓展+参数配置化，双管齐下。  \n2、健康检查：支持主动+被动探活检测，还可拓展第三方配置中心。     \n3、内置插件：分布式限流(秒/时/日三种粒度)、header头转换、白名单、租户鉴权、QPS统计等\n\n系统架构：\n![avatar](http://img-hxy021.didistatic.com/static/itstool_public/do1_QEfWPEJgafZ8aPjT83eG)\n\n1、系统分为两个端：控制端(Control Plane)负责服务编辑配置和自定义参数管理；代理端(Proxy Plane)负责协议数据中间处理及转发。两端可以分开启动也同时启动。      \n2、控制端与代理端交互：控制端编辑完服务信息会写入Mysql中，代理端定时从Mysql中拉取服务配置信息，然后平滑处理代理端服务启停。     \n3、自定义化插件：支持最常见的业务需求快速定制化，主要包含业务中间件自定义、服务负载配置自定义、负载策略自定义等，如果插件需要参数配置则可以在控制端配置相应参数。\n\n# 快速开始（Quick Start）\n\n## 环境要求\n\n软件 | 版本 | 官网 | 安装教程\n---|---|---|---\nmysql | \\\u003e=5.1 | [官网](https://dev.mysql.com/downloads/mysql/) | [教程](https://www.runoob.com/mysql/mysql-install.html)\nredis | \\\u003e=3.0 | [官网](https://redis.io/download) | [教程](https://www.runoob.com/redis/redis-install.html)\n\n## 服务安装(二选一)\n\n类型 | 优点\n---|---\n二进制文件安装 | 适合无golang环境且无插件开发需求用户.\n源码安装 | 支持插件定制化用户.\n\n\n### 1. 二进制文件安装\n目前支持64位windows/linux/mac 操作系统下用户，运行以下命令可自动化进行提示安装。  \nwindows用户需要启动powershell运行以下脚本。\n```\nbash \u003c(curl -s -S -L 'https://download.fastgit.org/didi/GateKeeper/releases/download/v1.0.0/setup.sh')  \n```\n执行完毕后，会提示启动服务的命令，按照操作运行即可，执行二进制安装无需再进行源码安装。\n\n### 2. 源码安装\n\n使用源码安装，需依赖golang环境，要求如下：\n\n软件 | 版本 | 官网 | 安装教程\n---|---|---|---\ngolang | \\\u003e=1.16 | [官网](https://golang.google.cn/dl/) |  [教程](https://www.runoob.com/go/go-environment.html)\n\n#### 2.1 git clone code\n\n```\ngit clone https://github.com/didi/GateKeeper.git\n```\n\n#### 2.2 set go proxy \u0026 download golang dependency\n\n```\nexport GO111MODULE=on \u0026\u0026 export GOPROXY=https://goproxy.cn\ncd GateKeeper\ngo mod tidy\n```\n\n#### 2.3 edit mysql connect info\n\n```\nvim ./conf/dev/mysql_map.toml\n# set data_source_name = \"{dbUser}:{dbPwd}@tcp({dbIp}:{dbPort})/{dbDatabase}?charset=utf8\u0026parseTime=true\u0026loc=Asia%2FChongqin\" \n```\n\n#### 2.4 edit redis connect info\n\n\n```\nvim ./conf/dev/redis_map.toml\n# set proxy_list = \"redisIP:redsiPort\"\n# set password = \"redisPwd\"\n```\n\n#### 2.5 create database \u0026 import data\n\n```\nmysql -h 127.0.0.1 -u root -p -e \"CREATE DATABASE gatekeeper DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;\"\nmysql -h 127.0.0.1 -u root -p gatekeeper \u003c gatekeeper.sql --default-character-set=utf8\n```\n\n#### 2.6 run gatekeeper\n- 启动控制端\n\n```\nsh control.sh start_control \n```\n- 启动代理端\n```\nsh control.sh start_proxy \n```\n- 同时双启动\n```\nsh control.sh start_both \n```\n\n# 插件化\n网关中最常见的业务需求，包含业务中间件自定义、服务负载配置自定义、负载策略自定义等。  \n这些常见功能我们都支持插件化定义，除此之外还支持了插件内部的动态参数配置及获取。\n\n## 业务中间件插件\n由于中间件内部采用AOP切面编程实现，所以业务中间件我们直接套用了 gin 中间件定义：\n```\ntype HandlerFunc func(*Context)\n```\n示例demo，func直接返回定义的方法即可：\n```\nfunc HTTPFlowLimitMiddleware() gin.HandlerFunc {\n\treturn func(c *gin.Context) {\n\t\t_, err := model.GetServiceDetailFromGinContext(c)\n\t\tif err != nil {\n\t\t\tpublic.ResponseError(c, 2001, err)\n\t\t\tc.Abort()\n\t\t\treturn\n\t\t}\n\t\t//todo\n\t\tc.Next()\n\t}\n}\n```\n最后记得完成中间件在 http_proxy_router/route.go 的内部注册。\n```\nrouter.Use(\n    http_proxy_middleware.HTTPAccessModeMiddleware(),\n    ...\n    http_proxy_middleware.HTTPFlowLimitMiddleware(),\n    http_proxy_middleware.HTTPReverseProxyMiddleware())\n```\n## 负载配置插件\n系统默认支持兜底下游节点配置，但是有些服务是使用服务发现协调器实现的如 consul、zookeeper 这就需要自定义服务负载配置了。    \n与上面相同首先是接口定义：\n```\ntype LoadBalanceConf interface {\n\tAttach(o Observer)\n\tGetConf() []string\n\tWatchConf()\n\tUpdateConf(conf []string)\n\tCloseWatch()\n}\n```\n实现完上述接口的结构后，还需要注册这个步骤。\n```\nfunc init() {\n\tRegisterCheckConfigHandler(\"upstream_config\", NewLoadBalanceCheckConf)\n}\n```\n## 负载策略插件\n系统默认提供了4种负载均衡策略：轮询、权重轮询、基于客户端IP的一致性Hash、随机。如果有定义需求还可以使用插件进行功能拓展。\n同样首先是接口定义\n```\ntype LoadBalanceStrategy interface {\n\tAdd(...string) error\n\tRemoveAll() error\n\tGetAll() ([]string, error)\n\tGet(string) (string, error)\n}\n```\n实现完上述接口的结构后，还需要注册这个步骤。\n```\nfunc init() {\n\tRegisterLoadBalanceStrategyHandler(\"random\", func() LoadBalanceStrategy {\n\t\treturn \u0026RandomStrategy{}\n\t})\n}\n```\n\n## 动态参数配置及获取\n插件要做到一处开发多处使用，就离不开动态参数配置功能。\nGateKeeper要实现参数配置主要以下几个步骤：     \n首先编辑 `conf/dev/plugin_config.toml` 增加参数配置，具体参数格式介绍 待补充，现举例如下：\n```\n[[http]]\n  display_name = \"url地址重写\"\n  sort = 6\n  postion = \"normal\"\n  unique_name = \"url_rewrite\"\n\n  [[http.items]]\n    field_type = \"textarea\"\n    field_display = \"block\"\n    field_clear = \"none\"\n    field_placeholder = \"格式：^/test_service(.*) $1\\n多条请换行\"\n    field_option = \"\"\n    field_value = \"\"\n    field_default_value = \"\"\n    field_unique_name = \"rewrite_rule\"\n    field_display_name = \"URL重写\"\n    field_required = false\n    field_valid_rule = \"/^[\\\\S]+ [\\\\S]+$/is\"\n```\n\n其次，打开控制端修改响应服务信息。\n![avatar](http://img-hxy021.didistatic.com/static/itstool_public/do1_d18zzT6DBk9zXHwq3AdN)\n\n最后在响应中间件调用即可。\n```\nfunc HTTPUrlRewriteMiddleware() gin.HandlerFunc {\n\treturn func(c *gin.Context) {\n\t\tserviceDetail, err := model.GetServiceDetailFromGinContext(c)\n\t\tif err != nil {\n\t\t\tpublic.ResponseError(c, 2001, err)\n\t\t\tc.Abort()\n\t\t\treturn\n\t\t}\n\t\trewriteUrl := serviceDetail.PluginConf.GetPath(\"url_rewrite\", \"rewrite_rule\").MustString()\n\t\t...\n\t\tc.Next()\n\t}\n}\n```\n\n# 性能测试\nGateKeeper 对比业界其他知名API网关 APISIX、Nginx、HAProxy、Kong、manba  \n硬件配置：128G、40核 Intel(R) Xeon(R) Silver 4114 2.20GHz  \n测试参数：wrk -t50 -c500 -d30s --latency  \"http://xxxx/xxxx/\"  \n\n![avatar](http://img-hxy021.didistatic.com/static/itstool_public/do1_E82bzkP6K8qaiUhmgkdA)\n\n![avatar](http://img-hxy021.didistatic.com/static/itstool_public/do1_pDPElgrgBdBpMyVHafkF)\n\n![avatar](http://img-hxy021.didistatic.com/static/itstool_public/do1_y5gXsG6Kx9yhEk6FsAPE)\n\n通过以上图片分析不难得出，GateKeeper性能的表现特点为：\n- 高并发压力下并发性可达到主流网关需求。\n- 高并发压力下比同类软件内存占用较高。\n- 高并发压力下99分位比同类软件延迟最低。\n\n注：以上服务均为默认安装未做调优、不同电脑配置测试结果可能不同。    \n更多详细内容 待补充\n\n# 自动化集成测试\n[自动化集成测试](https://github.com/didi/GateKeeper/blob/master/test_suites/README.md)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdidi%2Fgatekeeper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdidi%2Fgatekeeper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdidi%2Fgatekeeper/lists"}