Skip to content

Commit d0c69ff

Browse files
author
Your Name
committed
3.1.3版本提交
1 parent 3364e59 commit d0c69ff

File tree

228 files changed

+6869
-2966
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

228 files changed

+6869
-2966
lines changed

README.md

+111-81
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,115 @@
1-
![](https://data.eolinker.com/WJ2lfq217421a961efc420d88a7cb6f59586824a8ea2f84.jpg)
2-
3-
[![Gitter](https://badges.gitter.im/goku-api-gateway/community.svg)](https://gitter.im/goku-api-gateway/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) [![Go Report Card](https://goreportcard.com/badge/github.com/eolinker/goku-api-gateway)](https://goreportcard.com/report/github.com/eolinker/goku-api-gateway) [![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/3214/badge)](https://bestpractices.coreinfrastructure.org/projects/3214) ![](https://img.shields.io/badge/license-GPL3.0-blue.svg)
4-
5-
Goku API Gateway is a Golang-based microservice gateway that enables high-performance dynamic routing, multi-tenancy management, API access control, etc. It's also suitable for API management under micro-service system.
6-
7-
Goku provides graphic interface and plug-in system to make configuration easier and expand more convenient.
8-
9-
# Summary / [中文介绍](https://github.com/eolinker/goku-api-gateway/blob/master/README_CN.md "中文介绍")
10-
11-
- [WhyGoku](#WhyGoku "WhyGoku")
12-
- [Features](#Features "Features")
13-
- [Benchmark](#Benchmark "Benchmark")
14-
- [ConsolePreview](#ConsolePreview "ConsolePreview")
15-
- [QuickStart](#QuickStart "QuickStart")
16-
- [EnterpriseSupport](#EnterpriseSupport "EnterpriseSupport")
17-
- [AboutUs](#AboutUs "AboutUs")
18-
- [License](#License "License")
19-
20-
# Why Goku
21-
22-
Goku API Gateway is a microservice gateway that runs on the boundaries of enterprise system services. When you build websites, apps, IOT, and even API transactions, Goku API Gateway can help you extract duplicate components from your internal system and place them on the Goku gateway, such as user authorization, access control, traffic monitoring, firewalls, data cache, data conversion and so on.
23-
24-
Goku API Gateway CE provides comprehensive usage guide and customization guide. Goku is written in pure Go language, with good performance and scalability, and the built-in plug-in system enables enterprises to customize development for their own business.
25-
26-
Goku API Gateway also can combine with EOLINK API Studio to enhance API Management,API Monitor and Automated test.
27-
28-
All in all, Goku API Gateway enables enterprise to focus on their business.
29-
30-
[![Stargazers over time](https://starchart.cc/eolinker/goku-api-gateway.svg)](#)
31-
32-
# Product Features
33-
- **Dashboard**: Built-in dashboard to configure Goku.
34-
- **Cluster Management**:Goku nodes are stateless and can be expanded horizontally. Also the configuration can be synchronized automatically.
35-
- **Hot Updates**: Continuously updates configurations without restart nodes.
36-
- **Load balancing**: Round-robin load balancing with weight.
37-
- **Service Discovery**: Service discorvery from Consul or Eureka.
38-
- **HTTP(S) Forward Proxy**: Hide real backend services, support Rest API, Webservice.
39-
- **Multi-tenant management**: According to different strategies to regnorize different users.
40-
- **Strategies**: Support different strategies to access different APIs, configure different authentication (anonymous, Apikey, Basic) and so on.
41-
- **API Alert**: Support the webhook and email to alert abnormal services.
42-
- **Flexible transmit rules**: support fuzzy matching request path, support rewriting transmit path, etc.
43-
- **IP Whitelist/Blacklist**
44-
- **Custom plugins**: Allow plugins to be mounted in common phases, such as before match, access, and proxy.
45-
- **CLI**: Start\stop\reload Goku through the command line.
46-
- **Serverless**: Invoke functions in each phase in Goku.
47-
- **Access Log**:Only record the basic content in proxy, customize the record fields and sort order, and automatically clean up the logs periodically.
48-
- **System Log**:Provide running logs of consoles and nodes,only record the error information, adjust the level to INFO, WARN or DEBUG according to the actual situation.
49-
- **Scalability**: plug-in mechanism is easy to extend.
50-
- **High performance**: Performance excels among many gateways.
51-
- **Open API**:Provide OPEN API for users to operate on the gateway for easy integration.
52-
53-
# Benchmark
54-
![](https://data.eolinker.com/p7NFG6lb4c73b26cc880e838fe45aa31bc037b7415e3770.jpg)
55-
[Benchmark Detail](https://help.eolinker.com/#/tutorial/?groupID=c-362&productID=19#tip7 "Benchmark Detail")
56-
57-
# Console Preview
58-
[Console Preview Detail](https://github.com/eolinker/goku-api-gateway/blob/master/docs/CONSOLE_PREVIEW.md "See Console Preview")
59-
60-
61-
# Quick Start
62-
* [Deployment Tutorial](https://help.eolinker.com/#/tutorial/?groupID=c-351&productID=19 "Deployment Tutorial")
63-
* [Quick Start](https://help.eolinker.com/#/tutorial/?groupID=c-307&productID=19 "Quick Start Tutorial")
64-
* [Source Code Compilation](https://help.eolinker.com/#/tutorial/?groupID=c-350&productID=19 "Source Code Compilation")
65-
66-
# Enterprise Support
67-
Goku API Gateway EE (Enterprise Version) has more powerful functions, plug-in libraries and professional technical support services. If you want to know more details, you can contact us in the following ways.
68-
- Apply for free trial and demonstration of Enterprise Version:[Appointment trial](https://wj.qq.com/s2/2150032/4b5e "Appointment trial")
69-
- Market Cooperation Mail:[email protected]
70-
- Purchase consultation Mail:[email protected]
71-
- Help Center:[help.eolinker.com](help.eolinker.com "help.eolinker.com")
72-
- QQ Group: 725853895
73-
74-
# About Us
75-
EOLINK is a leading API management service provider, providing professional API research and development management, API automated test service, API monitor service, API gateway and other services for more than 3000 enterprises worldwide. It is the first enterprise to formulate API R&D management industry norms for ITSS.
76-
77-
Official website :[https://www.eolinker.com](https://www.eolinker.com "EOLINK Official Site")
78-
Free download of PC client :[https://www.eolinker.com/pc](https://www.eolinker.com/pc/ "Free download of PC client")
79-
80-
# License
1+
![Goku API Gateway 悟空网关](https://data.eolinker.com/course/gBTEV2s29e16630bb4dc553bec35ad33914d19aa410a8bf "Goku API Gateway 悟空网关")
2+
3+
[![Gitter](https://badges.gitter.im/goku-api-gateway/community.svg)](https://gitter.im/goku-api-gateway/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) [![Go Report Card](https://goreportcard.com/badge/github.com/eolinker/goku-gateway-api-api-gateway)](https://goreportcard.com/report/github.com/eolinker/goku-gateway-api-api-gateway) [![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/3214/badge)](https://bestpractices.coreinfrastructure.org/projects/3214) ![](https://img.shields.io/badge/license-GPL3.0-blue.svg)
4+
5+
Goku API Gateway (中文名:悟空 API 网关)是一个基于 Golang 开发的微服务网关,能够实现高性能 HTTP API 转发、多租户管理、API 访问权限控制等目的,拥有强大的自定义插件系统可以自行扩展,并且提供友好的图形化配置界面,能够快速帮助企业进行 API 服务治理、提高 API 服务的稳定性和安全性。
6+
7+
# 概况
8+
9+
- [为什么要使用Goku](#为什么要使用Goku "为什么要使用Goku")
10+
- [产品特性](#产品特性 "产品特性")
11+
- [产品截图](#产品截图 "产品截图")
12+
- [安装使用](#安装使用 "安装使用")
13+
- [企业支持](#企业支持 "企业支持")
14+
- [关于我们](#关于我们 "关于我们")
15+
- [授权协议](#授权协议 "授权协议")
16+
17+
# 为什么要使用Goku
18+
Goku API Gateway (悟空 API 网关)是运行在企业系统服务边界上的微服务网关。当您构建网站、App、IOT甚至是开放API交易时,Goku API Gateway 能够帮你将内部系统中重复的组件抽取出来并放置在Goku网关上运行,如进行用户授权、访问控制、流量监控、防火墙、静态数据缓存、数据转换等。
19+
20+
Goku API Gateway 的社区版本(CE)拥有完善的使用指南和二次开发指南,代码使用纯 Go 语言编写,拥有良好的性能和扩展性,并且内置的插件系统能够让企业针对自身业务进行定制开发。
21+
22+
并且 Goku API Gateway 支持与 EOLINKER 旗下的 API Studio 接口管理平台结合,对 API 进行全面的管理、自动化测试、监控和运维。
23+
24+
总而言之,Goku API Gateway 能让业务开发团队更加专注地实现业务。
25+
26+
# 产品特性
27+
- **集群管理**:多个 Goku API Gateway 节点,配置信息自动同步,支持多集群部署。
28+
- **界面管理后台**:通过清晰的UI界面对网关的各项配置进行管理。
29+
- **负载均衡**:对后端服务器进行负载均衡。
30+
- **服务发现**:从 Consul、Eureka 等注册中心发现后端服务器。
31+
- **转发代理**:通过转发请求来隐藏真实后端服务,支持 Rest API、Webservice。
32+
- **多租户管理**:根据不同的访问终端或用户来判断。
33+
- **访问鉴权**:Basic、API Key等。
34+
- **API监控**:请求数据统计。
35+
- **API告警**:支持通过API、邮件方式对异常的服务进行告警。
36+
- **健康检查**:动态发现异常的网关节点以及后端节点,自动切断转发流量并转到其他正常后端服务。
37+
- **异常自动重启**:网关节点异常时会自动尝试重载重启。
38+
- **灵活的转发规则**:支持模糊匹配请求路径,支持改写转发路径等。
39+
- **插件系统**:基于 Go 语言的插件系统,可以快速开发高性能的插件。
40+
- **性能扩展**:网关节点拥有良好的处理性能,支持水平扩展节点数量满足不同的性能需求。
41+
- **日志**:详细的系统日志、请求日志等。
42+
- **Open API**:提供 API 对网关进行操作,便于集成。
43+
- ...
44+
45+
# 产品截图
46+
* 【首页】
47+
首页可以了解网关的基本信息,例如访问策略数、API数等,还可以了解请求和转发的情况,例如成功率等。
48+
49+
![](http://data.eolinker.com/course/p8qL49u6c8adce6b345915b3fd77bf5812a40fe7dd0a8a2)
50+
51+
* 【网关节点】
52+
网关支持集群化管理,进入不同的集群可以管理相应的节点。
53+
54+
![](http://data.eolinker.com/course/wEa9yEI2bf086f3873b55bbdaec32f3b4ce1eb23dfe44ea)
55+
56+
* 【服务注册方式】
57+
您可以通过静态或动态的方式来注册(发现)您的后端服务,创建好服务注册方式后,您可以在某个方式的基础上创建一个或多个负载(Upstream)。
58+
59+
![](http://data.eolinker.com/course/1elb5mF4d3fd6141919001293e0119557b3d5ef0cea0719)
60+
61+
* 【负载配置】
62+
配置API的转发目标服务器(负载后端),创建之后可以设置为 API 的转发地址 / 负载后端(Target / Upstream)。
63+
64+
![](http://data.eolinker.com/course/4tHYXR23abc26b914ca763aac4871ed9d60a3aeb819941f)
65+
66+
* 【接口管理】
67+
支持创建并管理API文档,并且支持导入API文档项目。
68+
69+
![](http://data.eolinker.com/course/WlTJ2kB1cd03ddf839ea1d489890a0bd5b0572efeff6043)
70+
71+
* 【访问策略】
72+
您可以给不同的调用方或应用设置访问策略,不同的访问策略可以设置不同的 API 访问权限、鉴权方式以及插件功能等。
73+
74+
![](http://data.eolinker.com/course/fUrHmVd0d2d88b7f72d985b0e93e434ed528648d2dd34db)
75+
76+
* 【告警设置】
77+
针对异常API可以设置告警提醒,支持邮件和Webhook通知。
78+
79+
![](http://data.eolinker.com/course/9eQ3Lmv64e5cedc1ad4745dfa2895f6657441d874f6c7f4)
80+
81+
* 【扩展插件】
82+
插件系统除了提供官方插件,也可以添加自定义的网关插件。
83+
84+
![](http://data.eolinker.com/course/sQhUflpcebf65dc43cb7e2e838e8d1ecf3e52e9a5a6c566)
85+
86+
* 【日志设置】
87+
提供详细的请求日志和系统运行日志,请求日志可以自定义记录字段;运行日志可以根据情况调整记录等级:ERROR、INFO、DEBUG等。
88+
89+
![](http://data.eolinker.com/course/iyifFJ2809fe63e27df709ddc1a22f94d983c5ecbf8cc29)
90+
91+
# 安装使用
92+
* [部署教程](https://help.eolinker.com/#/tutorial/?groupID=c-351&productID=19 "部署教程")
93+
* [快速入门教程](https://help.eolinker.com/#/tutorial/?groupID=c-307&productID=19 "快速入门教程")
94+
* [源码编译教程](https://help.eolinker.com/#/tutorial/?groupID=c-350&productID=19 "源码编译")
95+
96+
# 企业支持
97+
Goku API Gateway EE(企业版本)拥有更强大的功能、插件库以及专业的技术支持服务,如您需要了解可以通过以下方式联系我们。
98+
- **中国大陆服务支持电话**:400-616-0330 法定工作日(9:30-18:00)
99+
- **申请企业版免费试用及演示**[预约试用](https://wj.qq.com/s2/2150032/4b5e "预约试用")
100+
- **市场合作邮箱**[email protected]
101+
- **购买咨询邮箱**[email protected]
102+
- **帮助文档**[help.eolinker.com](help.eolinker.com "help.eolinker.com")
103+
104+
# 关于我们
105+
EOLINKER 是领先的 API 管理服务供应商,为全球超过3000家企业提供专业的 API 研发管理、API自动化测试、API监控、API网关等服务。是首家为ITSS(中国电子工业标准化技术协会)制定API研发管理行业规范的企业。
106+
107+
官方网站:[https://www.eolinker.com](https://www.eolinker.com "EOLINKER官方网站")
108+
免费下载PC桌面端:[https://www.eolinker.com/pc/](https://www.eolinker.com/pc/ "免费下载PC客户端")
109+
110+
# 授权协议
81111
```
82-
Copyright 2017-2019 Eolink Inc.
112+
Copyright 2017-2019 Eolinker Inc.
83113
84114
Licensed under the GNU General Public License v3.0 (the "License");
85115
you may not use this file except in compliance with the License.

config/config.go

+35-11
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,42 @@
11
package config
22

3-
43
//GokuConfig goku根配置
54
type GokuConfig struct {
6-
Version string `json:"version"`
7-
Cluster string `json:"cluster"`
8-
Instance string `json:"instance"`
9-
BindAddress string `json:"bind"`
5+
Version string `json:"version"`
6+
Cluster string `json:"cluster"`
7+
Instance string `json:"instance"`
8+
BindAddress string `json:"bind"`
109
AdminAddress string `json:"admin"`
1110

1211
//Port int `json:"port"`
1312
DiscoverConfig map[string]*DiscoverConfig `json:"discover,omitempty"`
1413
Balance map[string]*BalanceConfig `json:"balance,omitempty"`
15-
Plugins *GatewayPluginConfig `json:"plugins,omitempty"`
14+
Plugins GatewayPluginConfig `json:"plugins,omitempty"`
1615
APIS []*APIContent `json:"apis,omitempty"`
1716
Strategy []*StrategyConfig `json:"strategy,omitempty"`
1817
AnonymousStrategyID string `json:"anonymousStrategyID,omitempty"`
1918
AuthPlugin map[string]string `json:"authPlugin,omitempty"`
19+
GatewayBasicInfo *Gateway `json:"gatewayBasicInfo"`
20+
//RouterRule map[string]*RouterRule `json:"routerRule"`
21+
Log *LogConfig `json:"log,omitempty"`
22+
AccessLog *AccessLogConfig `json:"access_log,omitempty"`
23+
Routers []*Router `json:"routers"`
24+
MonitorModules map[string]string `json:"monitor_modules"`
25+
RedisConfig map[string]interface{} `json:"redisConfig"`
26+
ExtendsConfig map[string]interface{} `json:"extends_config"`
27+
}
2028

21-
Log *LogConfig `json:"log,omitempty"`
22-
AccessLog *AccessLogConfig `json:"access_log,omitempty"`
29+
//Router 路由
30+
type Router struct {
31+
Rules string `json:"routerRules"`
32+
Target string `json:"target"`
33+
Priority int `json:"priority"`
34+
}
2335

24-
MonitorModules map[string]string `json:"monitor_modules"`
36+
//RouterRule 路由规则
37+
type RouterRule struct {
38+
Host string `json:"host"`
39+
StrategyID string `json:"strategyID"`
2540
}
2641

2742
//AccessLogConfig access日志配置
@@ -82,12 +97,15 @@ type PluginConfig struct {
8297
IsStop bool `json:"stop"`
8398
Config string `json:"config"`
8499
UpdateTag string `json:"updateTag"`
100+
IsAuth bool `json:"isAuth"`
85101
}
86102

87103
//APIContent api详情
88104
type APIContent struct {
89-
ID int `json:"id"`
90-
Name string `json:"name"`
105+
ID int `json:"id"`
106+
Name string `json:"name"`
107+
Alias string `json:"alias"`
108+
91109
OutPutEncoder string `json:"output"`
92110
RequestURL string `json:"requestUrl"`
93111
Methods []string `json:"methods"`
@@ -177,6 +195,11 @@ type StrategyConfig struct {
177195
Plugins []*PluginConfig `json:"plugins"`
178196
}
179197

198+
//Gateway 网关配置
199+
type Gateway struct {
200+
SkipCertificate int `json:"skipCertificate"`
201+
}
202+
180203
//APIOfStrategy 策略接口配置
181204
type APIOfStrategy struct {
182205
ID int `json:"id"`
@@ -193,6 +216,7 @@ type VersionConfig struct {
193216
CreateTime string `json:"createTime"`
194217
PublishStatus int `json:"publishStatus"`
195218
PublishTime string `json:"publishTime"`
219+
Publisher string `json:"publisher"`
196220
}
197221

198222
//Project 项目

console/account/account-default.go

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package account
2+
3+
import (
4+
"errors"
5+
"net/http"
6+
"strconv"
7+
8+
"github.com/eolinker/goku-api-gateway/console/module/account"
9+
)
10+
11+
//DefaultAccount default
12+
type DefaultAccount struct {
13+
}
14+
15+
//NewDefaultAccount new defaultAccount
16+
func NewDefaultAccount() *DefaultAccount {
17+
return &DefaultAccount{}
18+
}
19+
20+
//CheckLogin 判断是否登录
21+
func (d *DefaultAccount) CheckLogin(r *http.Request) (int, error) {
22+
23+
userIDCookie, idErr := r.Cookie("userID")
24+
userCookie, userErr := r.Cookie("userToken")
25+
if idErr != nil || userErr != nil {
26+
e := errors.New("user not logged in")
27+
return 0, e
28+
}
29+
userID, err := strconv.Atoi(userIDCookie.Value)
30+
if err != nil {
31+
return 0, err
32+
}
33+
flag := account.CheckLogin(userCookie.Value, userID)
34+
if !flag {
35+
e := errors.New("illegal users")
36+
return userID, e
37+
}
38+
39+
return userID, nil
40+
}
41+
42+
//CheckPermission 检查操作权限
43+
func (d *DefaultAccount) CheckPermission(pre string, isEdit bool, userID int) (bool, error) {
44+
if isEdit {
45+
return true, nil
46+
}
47+
return true, nil
48+
}

console/controller/account/guest.go

+20-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ package account
22

33
import (
44
"errors"
5+
6+
goku_handler "github.com/eolinker/goku-api-gateway/goku-handler"
7+
58
"net/http"
69
"strconv"
710

@@ -10,6 +13,22 @@ import (
1013
"github.com/eolinker/goku-api-gateway/utils"
1114
)
1215

16+
//Account 账号类
17+
type Account struct {
18+
}
19+
20+
//Handlers 处理器
21+
func (c *Account) Handlers(factory *goku_handler.AccountHandlerFactory) map[string]http.Handler {
22+
return map[string]http.Handler{
23+
"/login": http.HandlerFunc(Login),
24+
}
25+
}
26+
27+
//NewAccountController 新建账号控制类
28+
func NewAccountController() *Account {
29+
return &Account{}
30+
}
31+
1332
//Login 用户登录
1433
func Login(httpResponse http.ResponseWriter, httpRequest *http.Request) {
1534

@@ -24,7 +43,7 @@ func Login(httpResponse http.ResponseWriter, httpRequest *http.Request) {
2443
"100000",
2544
"guest",
2645
"[ERROR]Wrong username or password!",
27-
errors.New("Wrong username or password"))
46+
errors.New("wrong username or password"))
2847
return
2948
}
3049

0 commit comments

Comments
 (0)