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

V2.0.1

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