diff --git a/README.md b/README.md index 6386b6c1701b240b4ef798985a818aca5fdc20f3..8477f47959eae63603f2ba745757c8e4772769e7 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/release/goku-ce-1.0.0.zip b/release/goku-ce-1.0.0.zip deleted file mode 100644 index f70c623152b535ab33237e694e73ebd2e412df31..0000000000000000000000000000000000000000 Binary files a/release/goku-ce-1.0.0.zip and /dev/null differ diff --git a/release/goku-ce-1.0.2.zip b/release/goku-ce-1.0.2.zip deleted file mode 100644 index b0afafa9855de5f632fe78e113518576b2c44dcd..0000000000000000000000000000000000000000 Binary files a/release/goku-ce-1.0.2.zip and /dev/null differ diff --git a/release/goku-ce-2.0.0.zip b/release/goku-ce-2.0.0.zip deleted file mode 100644 index 781eae7cf56aad31a07e0a75917581b0dfbf47b8..0000000000000000000000000000000000000000 Binary files a/release/goku-ce-2.0.0.zip and /dev/null differ diff --git a/release/goku-ce-1.0.1.zip b/release/goku_ce_1.0.1.zip similarity index 100% rename from release/goku-ce-1.0.1.zip rename to release/goku_ce_1.0.1.zip diff --git a/release/goku-ce-1.0.3.zip b/release/goku_ce_1.0.3.zip similarity index 100% rename from release/goku-ce-1.0.3.zip rename to release/goku_ce_1.0.3.zip diff --git a/release/goku_ce_2.0.1.zip b/release/goku_ce_2.0.1.zip new file mode 100644 index 0000000000000000000000000000000000000000..bf94fcb958d32b104415e8d697fa27b666a7009d Binary files /dev/null and b/release/goku_ce_2.0.1.zip differ diff --git a/source_code/conf/parse_config.go b/source_code/conf/parse_config.go index c18735a53ce3b7f6705de50c1eb2a3cc403e1a4e..1387751f6598b622dfbcae56e6c7cb1524b6ce87 100644 --- a/source_code/conf/parse_config.go +++ b/source_code/conf/parse_config.go @@ -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 } diff --git a/source_code/middleware/request_mapping.go b/source_code/middleware/request_mapping.go index 218fd59e0fb0af90335bf6a0662182cc14fe072d..256d52d6637f41990598ca7eabbe41864f617856 100644 --- a/source_code/middleware/request_mapping.go +++ b/source_code/middleware/request_mapping.go @@ -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 }