提交 dcc0db4f 编写于 作者: E eoLinker API Management

V2.0.1

上级 1eb95c23
......@@ -122,4 +122,14 @@ GoKu API Gateway CE,支持OpenAPI与微服务管理,支持私有云部署,
优化:
1. 架构优化,减少第三方依赖,提升网关性能;
2. 弃置mysql、redis数据库的使用,改用配置文件方式读取文件配置。
\ No newline at end of file
2. 弃置mysql、redis数据库的使用,改用配置文件方式读取文件配置。
#### V2.0.1(2018/5/4)
优化:
1. 优化网关的错误提示。
修复:
1. 修复访问网关根路径时,报越界错误。
\ No newline at end of file
......@@ -32,11 +32,12 @@ func getGatewayList(path []string) []GatewayInfo {
var gateway GatewayInfo
c,err := ioutil.ReadFile(p + PthSep + "gateway.conf")
if err != nil {
panic("Error gateway config path!")
panic("Error gateway config path! Error path: " + p)
}
err = yaml.Unmarshal(c,&gateway)
if err != nil {
panic("Error gateway config!")
panic("Error gateway config! Error path: " + p)
}
if gateway.GatewayStatus != "on" {
continue
......@@ -53,11 +54,11 @@ func getStrategyList(path string) Strategy {
var strategy Strategy
c,err := ioutil.ReadFile(path)
if err != nil {
panic("Error strategy config path!")
panic("Error strategy config path! Error path: " + path)
}
err = yaml.Unmarshal(c,&strategy)
if err != nil {
panic("Error strategy config!")
panic("Error strategy config! Error path: " + path)
}
return strategy
}
......@@ -66,11 +67,11 @@ func getApiList(path string) Api {
var api Api
c,err := ioutil.ReadFile(path)
if err != nil {
panic("Error api config path!")
panic("Error api config path! Error path: " + path)
}
err = yaml.Unmarshal(c,&api)
if err != nil {
panic("Error api config!")
panic("Error api config! Error path: " + path)
}
return api
}
......@@ -79,11 +80,11 @@ func getBackendList(path string) Backend {
var backend Backend
c,err := ioutil.ReadFile(path)
if err != nil {
panic("Error api config path!")
panic("Error backend config path! Error path: " + path)
}
err = yaml.Unmarshal(c,&backend)
if err != nil {
panic("Error api config!")
panic("Error backend config! Error path: " + path)
}
return backend
}
......@@ -15,44 +15,45 @@ func Mapping(g *goku.Goku,res http.ResponseWriter, req *http.Request) (bool,stri
if requestURI[1] == "" {
res.WriteHeader(404)
res.Write([]byte("Lack gatewayAlias"))
} else {
return false,"Lack gatewayAlias"
res.WriteHeader(404)
return false,"Lack StrategyKey"
}
} else {
res.WriteHeader(404)
res.Write([]byte("Lack StrategyID"))
return false,"Lack StrategyID"
}
gatewayAlias := requestURI[1]
strategyKey := requestURI[2]
urlLen := len(gatewayAlias) + len(strategyKey) + 2
flag := false
for _,m := range g.ServiceConfig.GatewayList{
if m.GatewayAlias == gatewayAlias{
for _,i := range m.StrategyList.Strategy{
if i.StrategyID == strategyKey{
flag = true
f,r := IPLimit(m,i,res,req)
if !f {
res.Write([]byte(r))
return false,r
}
}
gatewayAlias := requestURI[1]
StrategyID := requestURI[2]
urlLen := len(gatewayAlias) + len(StrategyID) + 2
flag := false
for _,m := range g.ServiceConfig.GatewayList{
if m.GatewayAlias == gatewayAlias{
for _,i := range m.StrategyList.Strategy{
if i.StrategyID == StrategyID{
flag = true
f,r := IPLimit(m,i,res,req)
if !f {
res.Write([]byte(r))
return false,r
}
f,r = Auth(i,res,req)
if !f {
res.Write([]byte(r))
return false,r
}
f,r = Auth(i,res,req)
if !f {
res.Write([]byte(r))
return false,r
}
f,r = RateLimit(g,i)
if !f {
res.Write([]byte(r))
return false,r
}
break
f,r = RateLimit(g,i)
if !f {
res.Write([]byte(r))
return false,r
}
break
}
}
}
if flag {
for _,i := range m.ApiList.Apis{
}
}
if flag {
for _,i := range m.ApiList.Apis{
if i.RequestURL == url[urlLen:]{
// 验证请求
if !validateRequest(i,req){
......@@ -65,8 +66,8 @@ func Mapping(g *goku.Goku,res http.ResponseWriter, req *http.Request) (bool,stri
f,r := GetBackendInfo(i.BackendID,m.BackendList)
if !f {
res.WriteHeader(404)
res.Write([]byte("Backend config are not exist!"))
return false,"Backend config are not exist!"
res.Write([]byte("Backend config is not exist!"))
return false,"Backend config is not exist!"
}
......@@ -80,7 +81,7 @@ func Mapping(g *goku.Goku,res http.ResponseWriter, req *http.Request) (bool,stri
return true,string(response)
}
}
}
}
}
res.Write([]byte("URI Not Found"))
return false,"URI Not Found"
......@@ -127,7 +128,7 @@ func CreateRequest(api conf.ApiInfo,i conf.BackendInfo,httpRequest *http.Request
}
if param == nil {
if reqParam.NotEmpty {
return 400, []byte("missing required parameters"),make(map[string][]string)
return 400, []byte("Missing required parameters"),make(map[string][]string)
} else {
continue
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册