配置文件
1.GoKu拥有一个主配置文件 goku.conf ,GoKu可以新建多个网关,每个网关一个文件夹。
2.GoKu的配置文件采用 yaml 格式:
- 大小写敏感。
- 使用缩进表示层级关系,缩进时不允许使用Tab键,只允许使用空格。
- 缩进的空格数无关,只需相同层级的元素左侧对齐即可。
3.修改配置文件后,重启网关以使其生效
4.配置文件的层级关系如下图所示:
参数字段表
一、goku.conf
参数名 |
说明 |
必填 |
类型 |
示例 |
备注 |
host |
网关地址 |
是 |
string |
192.168.21.222 |
|
port |
端口号 |
是 |
string |
8800 |
|
gateway_conf_path |
网关所在路径 |
是 |
string |
./config/gateway |
|
二、gateway.conf
参数名 |
说明 |
必填 |
类型 |
示例 |
备注 |
gateway_name |
网关名称 |
是 |
string GoKu |
|
|
gateway_alias |
网关别名 |
是 |
string |
goku |
用于拼接网关请求地址 |
gateway_status |
网关状态 |
是 |
string |
on |
on/off |
ip_limit_type |
开启ip黑白名单 |
否 |
string |
none |
可取值:none/white/black |
ip_white_list |
ip白名单 |
否 |
[]string |
|
列表 |
ip_black_list |
ip黑名单 |
否 |
[]string |
|
列表 |
strategy_conf_path |
策略组所在路径 |
是 |
string |
./config/gateway/hm/strategy.conf |
|
api_group_conf_path |
API分组所在路径 |
是 |
string |
./config/gateway/hm/api_group.conf |
|
api_conf_path |
API所在路径 |
是 |
string |
./config/gateway/hm/api.conf |
|
三、backend.conf
参数名 |
说明 |
必填 |
类型 |
示例 |
备注 |
backend_id |
后端服务id |
是 |
int |
1 |
不可重复 |
backend_name |
后端服务名称 |
是 |
string |
开放接口 |
|
backend_path |
后端服务路径 |
是 |
string |
https://api.apishop.net |
不可重复 |
四、strategy.conf
参数名 |
说明 |
必填 |
类型 |
示例 |
备注 |
strategy_name |
策略组名称 |
是 |
string |
OpenAPI |
|
strategy_id |
策略组id |
是 |
string |
sjdkjs |
随机字符串,不可重复 |
auth |
鉴权方式 |
是 |
string |
apikey |
可取值:none/basic/apikey |
api_key |
用于apikey鉴权方式 |
否 |
string |
fd9befe929399f09c393 |
|
basic_user_name basic |
用户名 |
否 |
string |
123 |
|
basic_user_password |
basic密码 |
否 |
string |
123 |
|
ip_limit_type |
开启ip黑白名单 |
否 |
string |
none |
可取值:none/white/black |
ip_white_list |
ip白名单 |
否 |
[]string |
|
列表 |
ip_black_list |
ip黑名单 |
否 |
[]string |
|
列表 |
rate_limit_list |
流量控制 |
否 |
[]string |
|
列表 |
allow |
是否允许访问 |
否 |
bool |
true |
true/false |
priority |
流控优先级 |
否 |
int |
999 |
流控执行优先级:0~999 |
start_time |
流控开始时间 |
否 |
int |
6 |
0~24 |
end_time |
流控结束时间 |
否 |
int |
22 |
0~24 |
period |
流控单位 |
否 |
string |
min |
可取值:sec/min/hour/day |
limit |
限流次数 |
否 |
int |
1000 |
|
五、api_group.conf
参数名 |
说明 |
必填 |
类型 |
示例 |
备注 |
group_id |
api分组 id |
是 |
int |
2 |
不可重复 |
group_name |
api分组名称 |
是 |
string |
通用接口 |
|
六、api.conf
参数名 |
说明 |
必填 |
类型 |
示例 |
备注 |
api_name |
参数名 |
是 |
string |
查询全国油价 |
|
group_id |
所属分组 |
是 |
int |
0 |
0代表无分组 |
backend_id |
对应后端服务 |
是 |
int |
1 |
|
request_method |
网关请求方式 |
是 |
string |
post |
数组,可取值:get/post/put/delete/options/patch/head |
request_url |
网关请求路径 |
是 |
string |
/common/oil/getOilPriceToday |
|
proxy_method |
后端请求方式 |
是 |
string |
post |
非数组,可取值:get/post/put/delete/options/patch/head |
proxy_url |
后端请求路径 |
是 |
string |
/common/oil/getOilPriceToday |
|
proxy_body_type |
body类型 |
是 |
string |
formdata |
可取值:formdata/raw/json |
porxy_body |
raw数据 |
否 |
string |
|
|
proxy_params |
请求参数映射 |
否 |
列表 |
|
|
key |
网关参数名 |
否 |
string |
province |
|
key_position |
网关参数位置 |
否 |
string |
body |
可取值:header/body/query,当为raw数据时body不可取 |
not_empty |
是否必填 |
否 |
bool |
|
|
proxy_key |
后端参数名 |
否 |
string |
province |
|
proxy_key_position |
后端参数位置 |
否 |
string |
body |
可取值:header/body/query,当为raw数据时body不可取 |
constant_params |
常量参数 |
否 |
|
|
列表 |
key |
参数名 |
否 |
string |
apiKey |
|
position |
参数位置 |
否 |
string |
body |
可取值:header/body/query,当为raw数据时body不可取 |
value |
参数值 |
否 |
string |
9399f09c393fd9befe92 |
|
想了解更多国内首款GO语言网关信息,请留意:https://agw.eolinker.com,或者关注本博客,博客将会及时更新eoLinker最新资讯。