提交 d0c69ff4 编写于 作者: Y Your Name

3.1.3版本提交

上级 3364e59b
![](https://data.eolinker.com/WJ2lfq217421a961efc420d88a7cb6f59586824a8ea2f84.jpg)
[![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)
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.
Goku provides graphic interface and plug-in system to make configuration easier and expand more convenient.
# Summary / [中文介绍](https://github.com/eolinker/goku-api-gateway/blob/master/README_CN.md "中文介绍")
- [WhyGoku](#WhyGoku "WhyGoku")
- [Features](#Features "Features")
- [Benchmark](#Benchmark "Benchmark")
- [ConsolePreview](#ConsolePreview "ConsolePreview")
- [QuickStart](#QuickStart "QuickStart")
- [EnterpriseSupport](#EnterpriseSupport "EnterpriseSupport")
- [AboutUs](#AboutUs "AboutUs")
- [License](#License "License")
# Why Goku
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.
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.
Goku API Gateway also can combine with EOLINK API Studio to enhance API Management,API Monitor and Automated test.
All in all, Goku API Gateway enables enterprise to focus on their business.
[![Stargazers over time](https://starchart.cc/eolinker/goku-api-gateway.svg)](#)
# Product Features
- **Dashboard**: Built-in dashboard to configure Goku.
- **Cluster Management**:Goku nodes are stateless and can be expanded horizontally. Also the configuration can be synchronized automatically.
- **Hot Updates**: Continuously updates configurations without restart nodes.
- **Load balancing**: Round-robin load balancing with weight.
- **Service Discovery**: Service discorvery from Consul or Eureka.
- **HTTP(S) Forward Proxy**: Hide real backend services, support Rest API, Webservice.
- **Multi-tenant management**: According to different strategies to regnorize different users.
- **Strategies**: Support different strategies to access different APIs, configure different authentication (anonymous, Apikey, Basic) and so on.
- **API Alert**: Support the webhook and email to alert abnormal services.
- **Flexible transmit rules**: support fuzzy matching request path, support rewriting transmit path, etc.
- **IP Whitelist/Blacklist**
- **Custom plugins**: Allow plugins to be mounted in common phases, such as before match, access, and proxy.
- **CLI**: Start\stop\reload Goku through the command line.
- **Serverless**: Invoke functions in each phase in Goku.
- **Access Log**:Only record the basic content in proxy, customize the record fields and sort order, and automatically clean up the logs periodically.
- **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.
- **Scalability**: plug-in mechanism is easy to extend.
- **High performance**: Performance excels among many gateways.
- **Open API**:Provide OPEN API for users to operate on the gateway for easy integration.
# Benchmark
![](https://data.eolinker.com/p7NFG6lb4c73b26cc880e838fe45aa31bc037b7415e3770.jpg)
[Benchmark Detail](https://help.eolinker.com/#/tutorial/?groupID=c-362&productID=19#tip7 "Benchmark Detail")
# Console Preview
[Console Preview Detail](https://github.com/eolinker/goku-api-gateway/blob/master/docs/CONSOLE_PREVIEW.md "See Console Preview")
# Quick Start
* [Deployment Tutorial](https://help.eolinker.com/#/tutorial/?groupID=c-351&productID=19 "Deployment Tutorial")
* [Quick Start](https://help.eolinker.com/#/tutorial/?groupID=c-307&productID=19 "Quick Start Tutorial")
* [Source Code Compilation](https://help.eolinker.com/#/tutorial/?groupID=c-350&productID=19 "Source Code Compilation")
# Enterprise Support
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.
- Apply for free trial and demonstration of Enterprise Version:[Appointment trial](https://wj.qq.com/s2/2150032/4b5e "Appointment trial")
- Market Cooperation Mail:market@eolinker.com
- Purchase consultation Mail:sales@eolinker.com
- Help Center:[help.eolinker.com](help.eolinker.com "help.eolinker.com")
- QQ Group: 725853895
# About Us
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.
Official website :[https://www.eolinker.com](https://www.eolinker.com "EOLINK Official Site")
Free download of PC client :[https://www.eolinker.com/pc](https://www.eolinker.com/pc/ "Free download of PC client")
# License
![Goku API Gateway 悟空网关](https://data.eolinker.com/course/gBTEV2s29e16630bb4dc553bec35ad33914d19aa410a8bf "Goku API Gateway 悟空网关")
[![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)
Goku API Gateway (中文名:悟空 API 网关)是一个基于 Golang 开发的微服务网关,能够实现高性能 HTTP API 转发、多租户管理、API 访问权限控制等目的,拥有强大的自定义插件系统可以自行扩展,并且提供友好的图形化配置界面,能够快速帮助企业进行 API 服务治理、提高 API 服务的稳定性和安全性。
# 概况
- [为什么要使用Goku](#为什么要使用Goku "为什么要使用Goku")
- [产品特性](#产品特性 "产品特性")
- [产品截图](#产品截图 "产品截图")
- [安装使用](#安装使用 "安装使用")
- [企业支持](#企业支持 "企业支持")
- [关于我们](#关于我们 "关于我们")
- [授权协议](#授权协议 "授权协议")
# 为什么要使用Goku
Goku API Gateway (悟空 API 网关)是运行在企业系统服务边界上的微服务网关。当您构建网站、App、IOT甚至是开放API交易时,Goku API Gateway 能够帮你将内部系统中重复的组件抽取出来并放置在Goku网关上运行,如进行用户授权、访问控制、流量监控、防火墙、静态数据缓存、数据转换等。
Goku API Gateway 的社区版本(CE)拥有完善的使用指南和二次开发指南,代码使用纯 Go 语言编写,拥有良好的性能和扩展性,并且内置的插件系统能够让企业针对自身业务进行定制开发。
并且 Goku API Gateway 支持与 EOLINKER 旗下的 API Studio 接口管理平台结合,对 API 进行全面的管理、自动化测试、监控和运维。
总而言之,Goku API Gateway 能让业务开发团队更加专注地实现业务。
# 产品特性
- **集群管理**:多个 Goku API Gateway 节点,配置信息自动同步,支持多集群部署。
- **界面管理后台**:通过清晰的UI界面对网关的各项配置进行管理。
- **负载均衡**:对后端服务器进行负载均衡。
- **服务发现**:从 Consul、Eureka 等注册中心发现后端服务器。
- **转发代理**:通过转发请求来隐藏真实后端服务,支持 Rest API、Webservice。
- **多租户管理**:根据不同的访问终端或用户来判断。
- **访问鉴权**:Basic、API Key等。
- **API监控**:请求数据统计。
- **API告警**:支持通过API、邮件方式对异常的服务进行告警。
- **健康检查**:动态发现异常的网关节点以及后端节点,自动切断转发流量并转到其他正常后端服务。
- **异常自动重启**:网关节点异常时会自动尝试重载重启。
- **灵活的转发规则**:支持模糊匹配请求路径,支持改写转发路径等。
- **插件系统**:基于 Go 语言的插件系统,可以快速开发高性能的插件。
- **性能扩展**:网关节点拥有良好的处理性能,支持水平扩展节点数量满足不同的性能需求。
- **日志**:详细的系统日志、请求日志等。
- **Open API**:提供 API 对网关进行操作,便于集成。
- ...
# 产品截图
* 【首页】
首页可以了解网关的基本信息,例如访问策略数、API数等,还可以了解请求和转发的情况,例如成功率等。
![](http://data.eolinker.com/course/p8qL49u6c8adce6b345915b3fd77bf5812a40fe7dd0a8a2)
* 【网关节点】
网关支持集群化管理,进入不同的集群可以管理相应的节点。
![](http://data.eolinker.com/course/wEa9yEI2bf086f3873b55bbdaec32f3b4ce1eb23dfe44ea)
* 【服务注册方式】
您可以通过静态或动态的方式来注册(发现)您的后端服务,创建好服务注册方式后,您可以在某个方式的基础上创建一个或多个负载(Upstream)。
![](http://data.eolinker.com/course/1elb5mF4d3fd6141919001293e0119557b3d5ef0cea0719)
* 【负载配置】
配置API的转发目标服务器(负载后端),创建之后可以设置为 API 的转发地址 / 负载后端(Target / Upstream)。
![](http://data.eolinker.com/course/4tHYXR23abc26b914ca763aac4871ed9d60a3aeb819941f)
* 【接口管理】
支持创建并管理API文档,并且支持导入API文档项目。
![](http://data.eolinker.com/course/WlTJ2kB1cd03ddf839ea1d489890a0bd5b0572efeff6043)
* 【访问策略】
您可以给不同的调用方或应用设置访问策略,不同的访问策略可以设置不同的 API 访问权限、鉴权方式以及插件功能等。
![](http://data.eolinker.com/course/fUrHmVd0d2d88b7f72d985b0e93e434ed528648d2dd34db)
* 【告警设置】
针对异常API可以设置告警提醒,支持邮件和Webhook通知。
![](http://data.eolinker.com/course/9eQ3Lmv64e5cedc1ad4745dfa2895f6657441d874f6c7f4)
* 【扩展插件】
插件系统除了提供官方插件,也可以添加自定义的网关插件。
![](http://data.eolinker.com/course/sQhUflpcebf65dc43cb7e2e838e8d1ecf3e52e9a5a6c566)
* 【日志设置】
提供详细的请求日志和系统运行日志,请求日志可以自定义记录字段;运行日志可以根据情况调整记录等级:ERROR、INFO、DEBUG等。
![](http://data.eolinker.com/course/iyifFJ2809fe63e27df709ddc1a22f94d983c5ecbf8cc29)
# 安装使用
* [部署教程](https://help.eolinker.com/#/tutorial/?groupID=c-351&productID=19 "部署教程")
* [快速入门教程](https://help.eolinker.com/#/tutorial/?groupID=c-307&productID=19 "快速入门教程")
* [源码编译教程](https://help.eolinker.com/#/tutorial/?groupID=c-350&productID=19 "源码编译")
# 企业支持
Goku API Gateway EE(企业版本)拥有更强大的功能、插件库以及专业的技术支持服务,如您需要了解可以通过以下方式联系我们。
- **中国大陆服务支持电话**:400-616-0330 法定工作日(9:30-18:00)
- **申请企业版免费试用及演示**[预约试用](https://wj.qq.com/s2/2150032/4b5e "预约试用")
- **市场合作邮箱**:market@eolinker.com
- **购买咨询邮箱**:sales@eolinker.com
- **帮助文档**[help.eolinker.com](help.eolinker.com "help.eolinker.com")
# 关于我们
EOLINKER 是领先的 API 管理服务供应商,为全球超过3000家企业提供专业的 API 研发管理、API自动化测试、API监控、API网关等服务。是首家为ITSS(中国电子工业标准化技术协会)制定API研发管理行业规范的企业。
官方网站:[https://www.eolinker.com](https://www.eolinker.com "EOLINKER官方网站")
免费下载PC桌面端:[https://www.eolinker.com/pc/](https://www.eolinker.com/pc/ "免费下载PC客户端")
# 授权协议
```
Copyright 2017-2019 Eolink Inc.
Copyright 2017-2019 Eolinker Inc.
Licensed under the GNU General Public License v3.0 (the "License");
you may not use this file except in compliance with the License.
......
package config
//GokuConfig goku根配置
type GokuConfig struct {
Version string `json:"version"`
Cluster string `json:"cluster"`
Instance string `json:"instance"`
BindAddress string `json:"bind"`
Version string `json:"version"`
Cluster string `json:"cluster"`
Instance string `json:"instance"`
BindAddress string `json:"bind"`
AdminAddress string `json:"admin"`
//Port int `json:"port"`
DiscoverConfig map[string]*DiscoverConfig `json:"discover,omitempty"`
Balance map[string]*BalanceConfig `json:"balance,omitempty"`
Plugins *GatewayPluginConfig `json:"plugins,omitempty"`
Plugins GatewayPluginConfig `json:"plugins,omitempty"`
APIS []*APIContent `json:"apis,omitempty"`
Strategy []*StrategyConfig `json:"strategy,omitempty"`
AnonymousStrategyID string `json:"anonymousStrategyID,omitempty"`
AuthPlugin map[string]string `json:"authPlugin,omitempty"`
GatewayBasicInfo *Gateway `json:"gatewayBasicInfo"`
//RouterRule map[string]*RouterRule `json:"routerRule"`
Log *LogConfig `json:"log,omitempty"`
AccessLog *AccessLogConfig `json:"access_log,omitempty"`
Routers []*Router `json:"routers"`
MonitorModules map[string]string `json:"monitor_modules"`
RedisConfig map[string]interface{} `json:"redisConfig"`
ExtendsConfig map[string]interface{} `json:"extends_config"`
}
Log *LogConfig `json:"log,omitempty"`
AccessLog *AccessLogConfig `json:"access_log,omitempty"`
//Router 路由
type Router struct {
Rules string `json:"routerRules"`
Target string `json:"target"`
Priority int `json:"priority"`
}
MonitorModules map[string]string `json:"monitor_modules"`
//RouterRule 路由规则
type RouterRule struct {
Host string `json:"host"`
StrategyID string `json:"strategyID"`
}
//AccessLogConfig access日志配置
......@@ -82,12 +97,15 @@ type PluginConfig struct {
IsStop bool `json:"stop"`
Config string `json:"config"`
UpdateTag string `json:"updateTag"`
IsAuth bool `json:"isAuth"`
}
//APIContent api详情
type APIContent struct {
ID int `json:"id"`
Name string `json:"name"`
ID int `json:"id"`
Name string `json:"name"`
Alias string `json:"alias"`
OutPutEncoder string `json:"output"`
RequestURL string `json:"requestUrl"`
Methods []string `json:"methods"`
......@@ -177,6 +195,11 @@ type StrategyConfig struct {
Plugins []*PluginConfig `json:"plugins"`
}
//Gateway 网关配置
type Gateway struct {
SkipCertificate int `json:"skipCertificate"`
}
//APIOfStrategy 策略接口配置
type APIOfStrategy struct {
ID int `json:"id"`
......@@ -193,6 +216,7 @@ type VersionConfig struct {
CreateTime string `json:"createTime"`
PublishStatus int `json:"publishStatus"`
PublishTime string `json:"publishTime"`
Publisher string `json:"publisher"`
}
//Project 项目
......
package account
import (
"errors"
"net/http"
"strconv"
"github.com/eolinker/goku-api-gateway/console/module/account"
)
//DefaultAccount default
type DefaultAccount struct {
}
//NewDefaultAccount new defaultAccount
func NewDefaultAccount() *DefaultAccount {
return &DefaultAccount{}
}
//CheckLogin 判断是否登录
func (d *DefaultAccount) CheckLogin(r *http.Request) (int, error) {
userIDCookie, idErr := r.Cookie("userID")
userCookie, userErr := r.Cookie("userToken")
if idErr != nil || userErr != nil {
e := errors.New("user not logged in")
return 0, e
}
userID, err := strconv.Atoi(userIDCookie.Value)
if err != nil {
return 0, err
}
flag := account.CheckLogin(userCookie.Value, userID)
if !flag {
e := errors.New("illegal users")
return userID, e
}
return userID, nil
}
//CheckPermission 检查操作权限
func (d *DefaultAccount) CheckPermission(pre string, isEdit bool, userID int) (bool, error) {
if isEdit {
return true, nil
}
return true, nil
}
......@@ -2,6 +2,9 @@ package account
import (
"errors"
goku_handler "github.com/eolinker/goku-api-gateway/goku-handler"
"net/http"
"strconv"
......@@ -10,6 +13,22 @@ import (
"github.com/eolinker/goku-api-gateway/utils"
)
//Account 账号类
type Account struct {
}
//Handlers 处理器
func (c *Account) Handlers(factory *goku_handler.AccountHandlerFactory) map[string]http.Handler {
return map[string]http.Handler{
"/login": http.HandlerFunc(Login),
}
}
//NewAccountController 新建账号控制类
func NewAccountController() *Account {
return &Account{}
}
//Login 用户登录
func Login(httpResponse http.ResponseWriter, httpRequest *http.Request) {
......@@ -24,7 +43,7 @@ func Login(httpResponse http.ResponseWriter, httpRequest *http.Request) {
"100000",
"guest",
"[ERROR]Wrong username or password!",
errors.New("Wrong username or password"))
errors.New("wrong username or password"))
return
}
......
......@@ -6,11 +6,38 @@ import (
"regexp"
"strconv"
goku_handler "github.com/eolinker/goku-api-gateway/goku-handler"
"github.com/eolinker/goku-api-gateway/console/controller"
"github.com/eolinker/goku-api-gateway/console/module/account"
"github.com/eolinker/goku-api-gateway/utils"
)
//OperationUser 用户权限
const OperationUser = "user"
//UserController 用户控制器
type UserController struct {
}
//NewUserController 新建用户控制器
func NewUserController() *UserController {
return &UserController{}
}
//Handlers 处理类
func (u *UserController) Handlers(factory *goku_handler.AccountHandlerFactory) map[string]http.Handler {
return map[string]http.Handler{
"/logout": factory.NewAccountHandleFunction(OperationUser, false, Logout),
"/password/edit": factory.NewAccountHandleFunction(OperationUser, false, EditPassword),
"/getInfo": factory.NewAccountHandleFunction(OperationUser, false, GetUserInfo),
"/getUserType": factory.NewAccountHandleFunction(OperationUser, false, GetUserType),
"/checkIsAdmin": factory.NewAccountHandleFunction(OperationUser, false, CheckUserIsAdmin),
"/checkIsSuperAdmin": factory.NewAccountHandleFunction(OperationUser, false, CheckUserIsSuperAdmin),
}
}
//Logout 用户注销
func Logout(httpResponse http.ResponseWriter, httpRequest *http.Request) {
......@@ -25,10 +52,6 @@ func Logout(httpResponse http.ResponseWriter, httpRequest *http.Request) {
//EditPassword 修改账户信息
func EditPassword(httpResponse http.ResponseWriter, httpRequest *http.Request) {
userID, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationNone, controller.OperationEDIT)
if e != nil {
return
}
oldPassword := httpRequest.PostFormValue("oldPassword")
newPassword := httpRequest.PostFormValue("newPassword")
......@@ -50,6 +73,7 @@ func EditPassword(httpResponse http.ResponseWriter, httpRequest *http.Request) {
errors.New("[ERROR]Illegal newPassword"))
return
}
userID := goku_handler.UserIDFromRequest(httpRequest)
flag, result, err := account.EditPassword(oldPassword, newPassword, userID)
if !flag {
controller.WriteError(httpResponse,
......@@ -72,10 +96,7 @@ func EditPassword(httpResponse http.ResponseWriter, httpRequest *http.Request) {
//GetUserInfo 获取用户信息
func GetUserInfo(httpResponse http.ResponseWriter, httpRequest *http.Request) {
userID, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationNone, controller.OperationEDIT)
if e != nil {
return
}
userID := goku_handler.UserIDFromRequest(httpRequest)
flag, result, err := account.GetUserInfo(userID)
if !flag {
......@@ -91,11 +112,8 @@ func GetUserInfo(httpResponse http.ResponseWriter, httpRequest *http.Request) {
//GetUserType 获取用户类型
func GetUserType(httpResponse http.ResponseWriter, httpRequest *http.Request) {
userID, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationNone, controller.OperationEDIT)
if e != nil {
return
}
userID := goku_handler.UserIDFromRequest(httpRequest)
flag, result, err := account.GetUserType(userID)
if !flag {
......@@ -109,10 +127,7 @@ func GetUserType(httpResponse http.ResponseWriter, httpRequest *http.Request) {
//CheckUserIsAdmin 判断是否是管理员
func CheckUserIsAdmin(httpResponse http.ResponseWriter, httpRequest *http.Request) {
userID, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationNone, controller.OperationEDIT)
if e != nil {
return
}
userID := goku_handler.UserIDFromRequest(httpRequest)
flag, _, err := account.CheckUserIsAdmin(userID)
if !flag {
......@@ -132,10 +147,7 @@ func CheckUserIsAdmin(httpResponse http.ResponseWriter, httpRequest *http.Reques
//CheckUserIsSuperAdmin 判断是否是超级管理员
func CheckUserIsSuperAdmin(httpResponse http.ResponseWriter, httpRequest *http.Request) {
userID, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationNone, controller.OperationEDIT)
if e != nil {
return
}
userID := goku_handler.UserIDFromRequest(httpRequest)
flag, _, err := account.CheckUserIsSuperAdmin(userID)
......@@ -153,29 +165,3 @@ func CheckUserIsSuperAdmin(httpResponse http.ResponseWriter, httpRequest *http.R
controller.WriteResultInfo(httpResponse, "user", "", nil)
return
}
//CheckUserPermission 检查用户权限
func CheckUserPermission(httpResponse http.ResponseWriter, httpRequest *http.Request) {
userID, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationNone, controller.OperationEDIT)
if e != nil {
return
}
operationType := httpRequest.PostFormValue("operationType")
operation := httpRequest.PostFormValue("operation")
flag, result, err := account.CheckUserPermission(operationType, operation, userID)
if !flag {
controller.WriteError(httpResponse,
"110000",
"user",
result,
err)
return
}
controller.WriteResultInfo(httpResponse, "user", "", nil)
return
}
package api
import (
"net/http"
"strings"
"github.com/eolinker/goku-api-gateway/console/controller"
"github.com/eolinker/goku-api-gateway/console/module/api"
"net/http"
"strings"
)
//BatchSetBalanceAPI 批量设置接口负载
func BatchSetBalanceAPI(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAPI, controller.OperationEDIT)
if e != nil {
return
}
apiIDList := httpRequest.PostFormValue("apiIDList")
balanceName := httpRequest.PostFormValue("balance")
......
......@@ -6,19 +6,47 @@ import (
"strconv"
"strings"
"github.com/eolinker/goku-api-gateway/utils"
"github.com/pkg/errors"
goku_handler "github.com/eolinker/goku-api-gateway/goku-handler"
"github.com/eolinker/goku-api-gateway/console/controller"
"github.com/eolinker/goku-api-gateway/console/module/account"
"github.com/eolinker/goku-api-gateway/console/module/api"
)
const operationAPI = "apiManagement"
//Handlers handlers
type Handlers struct {
}
//Handlers handlers
func (h *Handlers) Handlers(factory *goku_handler.AccountHandlerFactory) map[string]http.Handler {
return map[string]http.Handler{
"/add": factory.NewAccountHandleFunction(operationAPI, true, AddAPI),
"/edit": factory.NewAccountHandleFunction(operationAPI, true, EditAPI),
"/copy": factory.NewAccountHandleFunction(operationAPI, true, CopyAPI),
"/getInfo": factory.NewAccountHandleFunction(operationAPI, false, GetAPIInfo),
"/getList": factory.NewAccountHandleFunction(operationAPI, false, GetAPIList),
"/id/getList": factory.NewAccountHandleFunction(operationAPI, false, GetAPIIDList),
"/batchEditGroup": factory.NewAccountHandleFunction(operationAPI, true, BatchEditAPIGroup),
"/batchDelete": factory.NewAccountHandleFunction(operationAPI, true, BatchDeleteAPI),
"/batchEditBalance": factory.NewAccountHandleFunction(operationAPI, true, BatchSetBalanceAPI),
}
}
//NewAPIHandlers API处理器
func NewAPIHandlers() *Handlers {
return &Handlers{}
}
//AddAPI 新增接口
func AddAPI(httpResponse http.ResponseWriter, httpRequest *http.Request) {
userID, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAPI, controller.OperationEDIT)
if e != nil {
return
}
apiName := httpRequest.PostFormValue("apiName")
alias := httpRequest.PostFormValue("alias")
requestURL := httpRequest.PostFormValue("requestURL")
requestMethod := httpRequest.PostFormValue("requestMethod")
protocol := httpRequest.PostFormValue("protocol")
......@@ -36,7 +64,7 @@ func AddAPI(httpResponse http.ResponseWriter, httpRequest *http.Request) {
linkApis := httpRequest.PostFormValue("linkApis")
staticResponse := httpRequest.PostFormValue("staticResponse")
responseDataType := httpRequest.PostFormValue("responseDataType")
userID := goku_handler.UserIDFromRequest(httpRequest)
if apiName == "" {
controller.WriteError(httpResponse, "190002", "api", "[ERROR]Illegal apiName!", nil)
return
......@@ -55,6 +83,15 @@ func AddAPI(httpResponse http.ResponseWriter, httpRequest *http.Request) {
controller.WriteError(httpResponse, "190012", "api", "[ERROR]Illegal apiType!", err)
return
}
if !utils.ValidateURL(requestURL) {
controller.WriteError(httpResponse, "190021", "api", "[ERROR]Illegal requestURL!", nil)
return
}
if aType == 1 && !utils.ValidateURL(targetURL) {
controller.WriteError(httpResponse, "190022", "api", "[ERROR]Illegal requestURL!", nil)
return
}
if responseDataType != "origin" && responseDataType != "json" && responseDataType != "xml" {
controller.WriteError(httpResponse, "190013", "api", "[ERROR]Illegal responseDataType!", err)
return
......@@ -102,8 +139,13 @@ func AddAPI(httpResponse http.ResponseWriter, httpRequest *http.Request) {
if managerID == "" {
mgID = userID
}
if api.CheckAliasIsExist(0, alias) {
errInfo := "[ERROR]duplicate alias!"
controller.WriteError(httpResponse, "190020", "api", errInfo, errors.New(errInfo))
return
}
flag, id, err := api.AddAPI(apiName, requestURL, targetURL, requestMethod, targetMethod, isFollow, linkApis, staticResponse, responseDataType, balanceName, protocol, pjID, gID, t, count, apiValve, mgID, userID, aType)
flag, id, err := api.AddAPI(apiName, alias, requestURL, targetURL, requestMethod, targetMethod, isFollow, linkApis, staticResponse, responseDataType, balanceName, protocol, pjID, gID, t, count, apiValve, mgID, userID, aType)
if !flag {
controller.WriteError(httpResponse,
......@@ -117,13 +159,10 @@ func AddAPI(httpResponse http.ResponseWriter, httpRequest *http.Request) {
//EditAPI 编辑接口
func EditAPI(httpResponse http.ResponseWriter, httpRequest *http.Request) {
userID, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAPI, controller.OperationEDIT)
if e != nil {
return
}
apiID := httpRequest.PostFormValue("apiID")
apiName := httpRequest.PostFormValue("apiName")
alias := httpRequest.PostFormValue("alias")
requestURL := httpRequest.PostFormValue("requestURL")
targetURL := httpRequest.PostFormValue("targetURL")
requestMethod := httpRequest.PostFormValue("requestMethod")
......@@ -140,6 +179,8 @@ func EditAPI(httpResponse http.ResponseWriter, httpRequest *http.Request) {
linkApis := httpRequest.PostFormValue("linkApis")
staticResponse := httpRequest.PostFormValue("staticResponse")
responseDataType := httpRequest.PostFormValue("responseDataType")
userID := goku_handler.UserIDFromRequest(httpRequest)
if apiName == "" {
controller.WriteError(httpResponse, "190002", "api", "[ERROR]Illegal apiName!", nil)
return
......@@ -207,8 +248,13 @@ func EditAPI(httpResponse http.ResponseWriter, httpRequest *http.Request) {
if managerID == "" {
mgID = userID
}
if api.CheckAliasIsExist(aID, alias) {
errInfo := "[ERROR]duplicate alias!"
controller.WriteError(httpResponse, "190020", "api", errInfo, errors.New(errInfo))
return
}
flag, err := api.EditAPI(apiName, requestURL, targetURL, requestMethod, targetMethod, isFollow, linkApis, staticResponse, responseDataType, balanceName, protocol, pjID, gID, t, count, apiValve, aID, mgID, userID)
flag, err := api.EditAPI(apiName, alias, requestURL, targetURL, requestMethod, targetMethod, isFollow, linkApis, staticResponse, responseDataType, balanceName, protocol, pjID, gID, t, count, apiValve, aID, mgID, userID)
if !flag {
controller.WriteError(httpResponse, "190000", "api", "[ERROR]apiID does not exist!", err)
......@@ -223,10 +269,6 @@ func EditAPI(httpResponse http.ResponseWriter, httpRequest *http.Request) {
//GetAPIInfo 获取接口信息
func GetAPIInfo(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAPI, controller.OperationREAD)
if e != nil {
return
}
apiID := httpRequest.PostFormValue("apiID")
......@@ -249,10 +291,6 @@ func GetAPIInfo(httpResponse http.ResponseWriter, httpRequest *http.Request) {
// GetAPIIDList 获取接口ID列表
func GetAPIIDList(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAPI, controller.OperationREAD)
if e != nil {
return
}
httpRequest.ParseForm()
projectID := httpRequest.Form.Get("projectID")
......@@ -284,8 +322,11 @@ func GetAPIIDList(httpResponse http.ResponseWriter, httpRequest *http.Request) {
ids := make([]int, 0)
json.Unmarshal([]byte(idsStr), &ids)
_, result, _ := api.GetAPIIDList(pjID, gID, keyword, op, ids)
_, result, err := api.GetAPIIDList(pjID, gID, keyword, op, ids)
if err != nil {
controller.WriteError(httpResponse, "190020", "api", "[ERROR]db error!", err)
return
}
// controller.WriteResultInfo(httpResponse, "api", "apiList", result)
controller.WriteResultInfoWithPage(httpResponse, "api", "apiIDList", result, &controller.PageInfo{
ItemNum: len(result),
......@@ -296,10 +337,6 @@ func GetAPIIDList(httpResponse http.ResponseWriter, httpRequest *http.Request) {
//GetAPIList 获取接口列表
func GetAPIList(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAPI, controller.OperationREAD)
if e != nil {
return
}
httpRequest.ParseForm()
projectID := httpRequest.Form.Get("projectID")
......@@ -343,8 +380,11 @@ func GetAPIList(httpResponse http.ResponseWriter, httpRequest *http.Request) {
ids := make([]int, 0)
json.Unmarshal([]byte(idsStr), &ids)
_, result, count, _ := api.GetAPIList(pjID, gID, keyword, op, p, pSize, ids)
_, result, count, err := api.GetAPIList(pjID, gID, keyword, op, p, pSize, ids)
if err != nil {
controller.WriteError(httpResponse, "190019", "api", "[Error]db error", err)
return
}
// controller.WriteResultInfo(httpResponse, "api", "apiList", result)
controller.WriteResultInfoWithPage(httpResponse, "api", "apiList", result, &controller.PageInfo{
ItemNum: len(result),
......@@ -357,10 +397,6 @@ func GetAPIList(httpResponse http.ResponseWriter, httpRequest *http.Request) {
// BatchEditAPIGroup 批量修改接口分组
func BatchEditAPIGroup(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAPI, controller.OperationEDIT)
if e != nil {
return
}
apiIDList := httpRequest.PostFormValue("apiIDList")
groupID := httpRequest.PostFormValue("groupID")
......@@ -381,10 +417,6 @@ func BatchEditAPIGroup(httpResponse http.ResponseWriter, httpRequest *http.Reque
//BatchDeleteAPI 批量删除接口
func BatchDeleteAPI(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAPI, controller.OperationEDIT)
if e != nil {
return
}
apiIDList := httpRequest.PostFormValue("apiIDList")
......@@ -400,30 +432,11 @@ func BatchDeleteAPI(httpResponse http.ResponseWriter, httpRequest *http.Request)
return
}
//GetAPIManagerList 获取接口负责人列表
func GetAPIManagerList(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAPI, controller.OperationREAD)
if e != nil {
return
}
flag, result, err := account.GetUserListWithPermission("apiManagement", "edit")
if !flag {
controller.WriteError(httpResponse, "190000", "api", err.Error(), err)
return
}
controller.WriteResultInfo(httpResponse, "api", "userList", result)
return
}
//CopyAPI 复制接口
func CopyAPI(httpResponse http.ResponseWriter, httpRequest *http.Request) {
userID, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAPI, controller.OperationEDIT)
if e != nil {
return
}
apiID := httpRequest.PostFormValue("apiID")
alisa := httpRequest.PostFormValue("alisa")
apiName := httpRequest.PostFormValue("apiName")
requestURL := httpRequest.PostFormValue("requestURL")
targetURL := httpRequest.PostFormValue("targetURL")
......@@ -434,6 +447,7 @@ func CopyAPI(httpResponse http.ResponseWriter, httpRequest *http.Request) {
isFollow := httpRequest.PostFormValue("isFollow")
groupID := httpRequest.PostFormValue("groupID")
projectID := httpRequest.PostFormValue("projectID")
userID := goku_handler.UserIDFromRequest(httpRequest)
if apiName == "" {
controller.WriteError(httpResponse, "190002", "api", "[ERROR]Illegal apiName!", nil)
return
......@@ -465,13 +479,21 @@ func CopyAPI(httpResponse http.ResponseWriter, httpRequest *http.Request) {
return
}
if !utils.ValidateURL(requestURL) {
controller.WriteError(httpResponse, "190021", "api", "[ERROR]Illegal requestURL!", nil)
return
}
flag, apiInfo, err := api.GetAPIInfo(aID)
if !flag {
controller.WriteError(httpResponse, "190000", "api", "[ERROR]apiID does not exist!", nil)
return
}
if apiInfo.APIType == 1 && !utils.ValidateURL(targetURL) {
controller.WriteError(httpResponse, "190022", "api", "[ERROR]Illegal targetURL!", nil)
return
}
linkApis, _ := json.Marshal(apiInfo.LinkAPIs)
flag, id, err := api.AddAPI(apiName, requestURL, targetURL, requestMethod, targetMethod, isFollow, string(linkApis), apiInfo.StaticResponse, apiInfo.ResponseDataType, balanceName, protocol, pjID, gID, apiInfo.Timeout, apiInfo.RetryConut, apiInfo.Valve, apiInfo.ManagerID, userID, apiInfo.APIType)
flag, id, err := api.AddAPI(apiName, alisa, requestURL, targetURL, requestMethod, targetMethod, isFollow, string(linkApis), apiInfo.StaticResponse, apiInfo.ResponseDataType, balanceName, protocol, pjID, gID, apiInfo.Timeout, apiInfo.RetryConut, apiInfo.Valve, apiInfo.ManagerID, userID, apiInfo.APIType)
if !flag {
controller.WriteError(httpResponse, "190000", "api", "[ERROR]Fail to add api!", err)
return
......
......@@ -7,14 +7,32 @@ import (
"github.com/eolinker/goku-api-gateway/console/controller"
"github.com/eolinker/goku-api-gateway/console/module/api"
"github.com/eolinker/goku-api-gateway/console/module/project"
goku_handler "github.com/eolinker/goku-api-gateway/goku-handler"
)
const operationAPIGroup = "apiManagement"
//GroupHandlers 接口分组处理器
type GroupHandlers struct {
}
//Handlers 处理器
func (g *GroupHandlers) Handlers(factory *goku_handler.AccountHandlerFactory) map[string]http.Handler {
return map[string]http.Handler{
"/add": factory.NewAccountHandleFunction(operationAPIGroup, true, AddAPIGroup),
"/edit": factory.NewAccountHandleFunction(operationAPIGroup, true, EditAPIGroup),
"/delete": factory.NewAccountHandleFunction(operationAPIGroup, true, DeleteAPIGroup),
"/getList": factory.NewAccountHandleFunction(operationAPIGroup, false, GetAPIGroupList),
}
}
//NewGroupHandlers new 接口分组处理器
func NewGroupHandlers() *GroupHandlers {
return &GroupHandlers{}
}
//AddAPIGroup 新建接口分组
func AddAPIGroup(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAPI, controller.OperationEDIT)
if e != nil {
return
}
groupName := httpRequest.PostFormValue("groupName")
projectID := httpRequest.PostFormValue("projectID")
......@@ -68,10 +86,6 @@ func AddAPIGroup(httpResponse http.ResponseWriter, httpRequest *http.Request) {
//EditAPIGroup 修改接口分组
func EditAPIGroup(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAPI, controller.OperationEDIT)
if e != nil {
return
}
groupName := httpRequest.PostFormValue("groupName")
groupID := httpRequest.PostFormValue("groupID")
......@@ -120,10 +134,6 @@ func EditAPIGroup(httpResponse http.ResponseWriter, httpRequest *http.Request) {
//DeleteAPIGroup 删除接口分组
func DeleteAPIGroup(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAPI, controller.OperationEDIT)
if e != nil {
return
}
groupID := httpRequest.PostFormValue("groupID")
projectID := httpRequest.PostFormValue("projectID")
......@@ -158,10 +168,6 @@ func DeleteAPIGroup(httpResponse http.ResponseWriter, httpRequest *http.Request)
//GetAPIGroupList 获取接口分组列表
func GetAPIGroupList(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAPI, controller.OperationREAD)
if e != nil {
return
}
projectID := httpRequest.PostFormValue("projectID")
pjID, err := strconv.Atoi(projectID)
......
......@@ -10,20 +10,44 @@ import (
"github.com/eolinker/goku-api-gateway/console/module/plugin"
plugin_config "github.com/eolinker/goku-api-gateway/console/module/plugin/plugin-config"
"github.com/eolinker/goku-api-gateway/console/module/strategy"
goku_handler "github.com/eolinker/goku-api-gateway/goku-handler"
)
const operationAPIPlugin = "strategyManagement"
//PluginHandlers 插件处理器
type PluginHandlers struct {
}
//Handlers handlers
func (p *PluginHandlers) Handlers(factory *goku_handler.AccountHandlerFactory) map[string]http.Handler {
return map[string]http.Handler{
"/addPluginToApi": factory.NewAccountHandleFunction(operationAPIPlugin, true, AddPluginToAPI),
"/edit": factory.NewAccountHandleFunction(operationAPIPlugin, true, EditAPIPluginConfig),
"/getInfo": factory.NewAccountHandleFunction(operationAPIPlugin, false, GetAPIPluginConfig),
"/getList": factory.NewAccountHandleFunction(operationAPIPlugin, false, GetAPIPluginList),
"/getListByStrategy": factory.NewAccountHandleFunction(operationAPIPlugin, false, GetAllAPIPluginInStrategy),
"/batchStart": factory.NewAccountHandleFunction(operationAPIPlugin, true, BatchStartAPIPlugin),
"/batchStop": factory.NewAccountHandleFunction(operationAPIPlugin, true, BatchStopAPIPlugin),
"/batchDelete": factory.NewAccountHandleFunction(operationAPIPlugin, true, BatchDeleteAPIPlugin),
"/notAssign/getList": factory.NewAccountHandleFunction(operationAPIPlugin, false, GetAPIPluginListWithNotAssignAPIList),
}
}
//NewPluginHandlers new插件处理器
func NewPluginHandlers() *PluginHandlers {
return &PluginHandlers{}
}
//AddPluginToAPI 新增插件到接口
func AddPluginToAPI(httpResponse http.ResponseWriter, httpRequest *http.Request) {
userID, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAPI, controller.OperationEDIT)
if e != nil {
return
}
pluginName := httpRequest.PostFormValue("pluginName")
pluginConfig := httpRequest.PostFormValue("pluginConfig")
strategyID := httpRequest.PostFormValue("strategyID")
apiID := httpRequest.PostFormValue("apiID")
userID := goku_handler.UserIDFromRequest(httpRequest)
aID, err := strconv.Atoi(apiID)
if err != nil {
controller.WriteError(httpResponse, "240002", "apiPlugin", "[ERROR]Illegal apiID!", err)
......@@ -81,15 +105,13 @@ func AddPluginToAPI(httpResponse http.ResponseWriter, httpRequest *http.Request)
//EditAPIPluginConfig 修改接口插件
func EditAPIPluginConfig(httpResponse http.ResponseWriter, httpRequest *http.Request) {
userID, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAPI, controller.OperationEDIT)
if e != nil {
return
}
pluginName := httpRequest.PostFormValue("pluginName")
pluginConfig := httpRequest.PostFormValue("pluginConfig")
strategyID := httpRequest.PostFormValue("strategyID")
apiID := httpRequest.PostFormValue("apiID")
userID := goku_handler.UserIDFromRequest(httpRequest)
flag, err := plugin_config.CheckConfig(pluginName, []byte(pluginConfig))
if !flag {
controller.WriteError(httpResponse, "500000", "apiPlugin", "[ERROR]插件配置无效:"+err.Error(), err)
......@@ -153,10 +175,6 @@ func EditAPIPluginConfig(httpResponse http.ResponseWriter, httpRequest *http.Req
//GetAPIPluginConfig 获取接口插件配置
func GetAPIPluginConfig(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAPI, controller.OperationREAD)
if e != nil {
return
}
pluginName := httpRequest.PostFormValue("pluginName")
strategyID := httpRequest.PostFormValue("strategyID")
......@@ -198,10 +216,6 @@ func GetAPIPluginConfig(httpResponse http.ResponseWriter, httpRequest *http.Requ
//GetAPIPluginList 获取接口插件配置
func GetAPIPluginList(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAPI, controller.OperationREAD)
if e != nil {
return
}
strategyID := httpRequest.PostFormValue("strategyID")
apiID := httpRequest.PostFormValue("apiID")
......@@ -230,60 +244,8 @@ func GetAPIPluginList(httpResponse http.ResponseWriter, httpRequest *http.Reques
return
}
// GetAPIPluginInStrategyByAPIID 获取策略组中所有接口插件列表
func GetAPIPluginInStrategyByAPIID(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAPI, controller.OperationREAD)
if e != nil {
return
}
httpRequest.ParseForm()
strategyID := httpRequest.Form.Get("strategyID")
apiID := httpRequest.Form.Get("apiID")
keyword := httpRequest.Form.Get("keyword")
condition := httpRequest.Form.Get("condition")
aID, err := strconv.Atoi(apiID)
if err != nil {
controller.WriteError(httpResponse, "240002", "apiPlugin", "[ERROR]Illegal condition!", err)
return
}
op, err := strconv.Atoi(condition)
if err != nil && condition != "" {
controller.WriteError(httpResponse, "270006", "apiPlugin", "[ERROR]Illegal condition!", err)
return
}
flag, pluginList, apiInfo, err := api.GetAPIPluginInStrategyByAPIID(strategyID, aID, keyword, op)
if !flag {
controller.WriteError(httpResponse,
"240000",
"apiPlugin",
"[ERROR]Empty api plugin list!",
err)
return
}
result := map[string]interface{}{
"statusCode": "000000",
"type": "apiPlugin",
"resultDesc": "",
"apiPluginList": pluginList,
"apiInfo": apiInfo,
"page": controller.PageInfo{
ItemNum: len(pluginList),
},
}
resultStr, _ := json.Marshal(result)
httpResponse.Write(resultStr)
// controller.WriteResultInfo(httpResponse, "apiPlugin", "apiPluginList", result)
}
//GetAllAPIPluginInStrategy 获取策略组中所有接口插件列表
func GetAllAPIPluginInStrategy(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAPI, controller.OperationREAD)
if e != nil {
return
}
strategyID := httpRequest.PostFormValue("strategyID")
......@@ -305,13 +267,11 @@ func GetAllAPIPluginInStrategy(httpResponse http.ResponseWriter, httpRequest *ht
//BatchStartAPIPlugin 批量修改策略组插件状态
func BatchStartAPIPlugin(httpResponse http.ResponseWriter, httpRequest *http.Request) {
userID, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAPI, controller.OperationEDIT)
if e != nil {
return
}
strategyID := httpRequest.PostFormValue("strategyID")
connIDList := httpRequest.PostFormValue("connIDList")
userID := goku_handler.UserIDFromRequest(httpRequest)
if connIDList == "" {
controller.WriteError(httpResponse,
"240001",
......@@ -338,13 +298,11 @@ func BatchStartAPIPlugin(httpResponse http.ResponseWriter, httpRequest *http.Req
//BatchStopAPIPlugin 批量修改策略组插件状态
func BatchStopAPIPlugin(httpResponse http.ResponseWriter, httpRequest *http.Request) {
userID, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAPI, controller.OperationEDIT)
if e != nil {
return
}
strategyID := httpRequest.PostFormValue("strategyID")
connIDList := httpRequest.PostFormValue("connIDList")
userID := goku_handler.UserIDFromRequest(httpRequest)
if connIDList == "" {
controller.WriteError(httpResponse,
"240001",
......@@ -371,13 +329,10 @@ func BatchStopAPIPlugin(httpResponse http.ResponseWriter, httpRequest *http.Requ
//BatchDeleteAPIPlugin 批量删除策略组插件
func BatchDeleteAPIPlugin(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAPI, controller.OperationEDIT)
if e != nil {
return
}
strategyID := httpRequest.PostFormValue("strategyID")
connIDList := httpRequest.PostFormValue("connIDList")
if connIDList == "" {
controller.WriteError(httpResponse,
"240001",
......@@ -401,10 +356,6 @@ func BatchDeleteAPIPlugin(httpResponse http.ResponseWriter, httpRequest *http.Re
//GetAPIPluginListWithNotAssignAPIList 获取没有分配接口插件的接口列表
func GetAPIPluginListWithNotAssignAPIList(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAPI, controller.OperationREAD)
if e != nil {
return
}
strategyID := httpRequest.PostFormValue("strategyID")
if strategyID == "" {
......
......@@ -2,6 +2,7 @@ package api
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"strconv"
......@@ -9,18 +10,36 @@ import (
"github.com/eolinker/goku-api-gateway/console/controller"
"github.com/eolinker/goku-api-gateway/console/module/api"
goku_handler "github.com/eolinker/goku-api-gateway/goku-handler"
entity "github.com/eolinker/goku-api-gateway/server/entity/console-entity"
)
const operationImportAMS = "apiManagement"
//ImportHandlers 导入handlers
type ImportHandlers struct {
}
//Handlers handler
func (i *ImportHandlers) Handlers(factory *goku_handler.AccountHandlerFactory) map[string]http.Handler {
return map[string]http.Handler{
"/api": factory.NewAccountHandleFunction(operationImportAMS, true, ImportAPIFromAms),
"/group": factory.NewAccountHandleFunction(operationImportAMS, true, ImportAPIGroupFromAms),
"/project": factory.NewAccountHandleFunction(operationImportAMS, true, ImportProjectFromAms),
}
}
//NewImportHandlers new导入处理器
func NewImportHandlers() *ImportHandlers {
return &ImportHandlers{}
}
//ImportAPIGroupFromAms 导入分组
func ImportAPIGroupFromAms(httpResponse http.ResponseWriter, httpRequest *http.Request) {
userID, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAPI, controller.OperationEDIT)
if e != nil {
return
}
contentType := httpRequest.Header.Get("Content-Type")
userID := goku_handler.UserIDFromRequest(httpRequest)
if !strings.Contains(contentType, "multipart/form-data") {
controller.WriteError(httpResponse,
"310001",
......@@ -98,13 +117,9 @@ func ImportAPIGroupFromAms(httpResponse http.ResponseWriter, httpRequest *http.R
//ImportProjectFromAms 导入项目
func ImportProjectFromAms(httpResponse http.ResponseWriter, httpRequest *http.Request) {
userID, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAPI, controller.OperationEDIT)
if e != nil {
return
}
contentType := httpRequest.Header.Get("Content-Type")
userID := goku_handler.UserIDFromRequest(httpRequest)
if !strings.Contains(contentType, "multipart/form-data") {
controller.WriteError(httpResponse,
"310001",
......@@ -170,12 +185,9 @@ func ImportProjectFromAms(httpResponse http.ResponseWriter, httpRequest *http.Re
//ImportAPIFromAms 导入接口
func ImportAPIFromAms(httpResponse http.ResponseWriter, httpRequest *http.Request) {
userID, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAPI, controller.OperationEDIT)
if e != nil {
return
}
contentType := httpRequest.Header.Get("Content-Type")
userID := goku_handler.UserIDFromRequest(httpRequest)
if !strings.Contains(contentType, "multipart/form-data") {
controller.WriteError(httpResponse,
"310001",
......@@ -229,6 +241,7 @@ func ImportAPIFromAms(httpResponse http.ResponseWriter, httpRequest *http.Reques
}
apiList := make([]entity.AmsAPIInfo, 0)
fmt.Println(string(body))
err = json.Unmarshal(body, &apiList)
if err != nil {
controller.WriteError(httpResponse,
......
......@@ -5,23 +5,40 @@ import (
"net/http"
"strings"
goku_handler "github.com/eolinker/goku-api-gateway/goku-handler"
"github.com/eolinker/goku-api-gateway/console/controller"
"github.com/eolinker/goku-api-gateway/console/module/auth"
log "github.com/eolinker/goku-api-gateway/goku-log"
)
const operationAuth = "strategyManagement"
//Handlers handlers
type Handlers struct {
}
//Handlers handlers
func (h *Handlers) Handlers(factory *goku_handler.AccountHandlerFactory) map[string]http.Handler {
return map[string]http.Handler{
"/getStatus": factory.NewAccountHandleFunction(operationAuth, true, GetAuthStatus),
"/getInfo": factory.NewAccountHandleFunction(operationAuth, true, GetAuthInfo),
"/editInfo": factory.NewAccountHandleFunction(operationAuth, true, EditAuthInfo),
}
}
//NewHandlers new handlers
func NewHandlers() *Handlers {
return &Handlers{}
}
//GetAuthStatus 获取认证状态
func GetAuthStatus(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationNone, controller.OperationREAD)
if e != nil {
return
}
strategyID := httpRequest.PostFormValue("strategyID")
flag, result, err := auth.GetAuthStatus(strategyID)
if !flag {
controller.WriteError(httpResponse, "250000", "auth", "[ERROR]The auth info of the strategy does not exist!", err)
return
}
......@@ -37,10 +54,6 @@ func GetAuthStatus(httpResponse http.ResponseWriter, httpRequest *http.Request)
//GetAuthInfo 获取认证信息
func GetAuthInfo(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationNone, controller.OperationREAD)
if e != nil {
return
}
strategyID := httpRequest.PostFormValue("strategyID")
......@@ -64,10 +77,6 @@ func GetAuthInfo(httpResponse http.ResponseWriter, httpRequest *http.Request) {
//EditAuthInfo 编辑认证信息
func EditAuthInfo(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationNone, controller.OperationEDIT)
if e != nil {
return
}
strategyID := httpRequest.PostFormValue("strategyID")
strategyName := httpRequest.PostFormValue("strategyName")
......
......@@ -2,10 +2,11 @@ package balance
import (
"fmt"
"github.com/eolinker/goku-api-gateway/console/controller"
"net/http"
"github.com/eolinker/goku-api-gateway/common/auto-form"
"github.com/eolinker/goku-api-gateway/console/controller"
"github.com/eolinker/goku-api-gateway/console/module/balance"
"github.com/go-sql-driver/mysql"
)
......@@ -13,10 +14,7 @@ import (
//AddBalance 新增负载配置
func AddBalance(w http.ResponseWriter, r *http.Request) {
_, e := controller.CheckLogin(w, r, controller.OperationLoadBalance, controller.OperationEDIT)
if e != nil {
return
}
if err := r.ParseForm(); err != nil {
controller.WriteError(w, "260000",
......
package balance
import (
"github.com/eolinker/goku-api-gateway/console/controller"
"net/http"
"strings"
"github.com/eolinker/goku-api-gateway/console/controller"
"github.com/eolinker/goku-api-gateway/console/module/balance"
)
//DeleteBalance 删除负载配置
func DeleteBalance(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationLoadBalance, controller.OperationEDIT)
if e != nil {
return
}
if err := httpRequest.ParseForm(); err != nil {
controller.WriteError(httpResponse, "260000", "data", "[param_check] Parse form body error | 解析form表单参数错误", err)
......@@ -37,10 +34,7 @@ func DeleteBalance(httpResponse http.ResponseWriter, httpRequest *http.Request)
//BatchDeleteBalance 批量删除负载
func BatchDeleteBalance(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationLoadBalance, controller.OperationEDIT)
if e != nil {
return
}
balanceNames := httpRequest.PostFormValue("balanceNames")
result, err := balance.BatchDeleteBalance(strings.Split(balanceNames, ","))
if err != nil {
......
package balance
import (
"net/http"
"github.com/eolinker/goku-api-gateway/console/controller"
"github.com/eolinker/goku-api-gateway/console/module/balance"
"net/http"
)
//GetBalanceInfo 获取负载信息
func GetBalanceInfo(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationLoadBalance, controller.OperationREAD)
if e != nil {
return
}
if err := httpRequest.ParseForm(); err != nil {
controller.WriteError(httpResponse, "501", "balance", "[ERROR]参数解析错误t!", err)
return
......
package balance
import (
"net/http"
goku_handler "github.com/eolinker/goku-api-gateway/goku-handler"
)
const operationBalance = "balanceManagement"
//Handlers handlers
type Handlers struct {
}
//Handlers handlers
func (h *Handlers) Handlers(factory *goku_handler.AccountHandlerFactory) map[string]http.Handler {
return map[string]http.Handler{
"/add": factory.NewAccountHandleFunction(operationBalance, true, AddBalance),
"/edit": factory.NewAccountHandleFunction(operationBalance, true, SaveBalance),
"/delete": factory.NewAccountHandleFunction(operationBalance, true, DeleteBalance),
"/getInfo": factory.NewAccountHandleFunction(operationBalance, false, GetBalanceInfo),
"/getList": factory.NewAccountHandleFunction(operationBalance, false, GetBalanceList),
"/batchDelete": factory.NewAccountHandleFunction(operationBalance, true, BatchDeleteBalance),
"/simple": factory.NewAccountHandleFunction(operationBalance, true, GetSimpleList),
}
}
//NewHandlers new handlers
func NewHandlers() *Handlers {
return &Handlers{}
}
......@@ -2,18 +2,14 @@ package balance
import (
"fmt"
"net/http"
"github.com/eolinker/goku-api-gateway/console/controller"
"github.com/eolinker/goku-api-gateway/console/module/balance"
"net/http"
)
//GetBalanceList 获取负载列表
func GetBalanceList(w http.ResponseWriter, r *http.Request) {
_, e := controller.CheckLogin(w, r, controller.OperationLoadBalance, controller.OperationREAD)
if e != nil {
return
}
_ = r.ParseForm()
keyword := r.FormValue("keyword")
......
......@@ -2,21 +2,17 @@ package balance
import (
"fmt"
"net/http"
"github.com/eolinker/goku-api-gateway/common/auto-form"
"github.com/eolinker/goku-api-gateway/console/controller"
"github.com/eolinker/goku-api-gateway/console/module/balance"
"github.com/go-sql-driver/mysql"
"net/http"
)
//SaveBalance 新增负载配置
func SaveBalance(w http.ResponseWriter, r *http.Request) {
_, e := controller.CheckLogin(w, r, controller.OperationLoadBalance, controller.OperationEDIT)
if e != nil {
return
}
if err := r.ParseForm(); err != nil {
controller.WriteError(w, "260000", "data", "[param_check] Parse form body error | 解析form表单参数错误", err)
......
package balance
import (
"net/http"
"github.com/eolinker/goku-api-gateway/console/controller"
"github.com/eolinker/goku-api-gateway/console/module/balance"
"net/http"
)
//GetSimpleList 获取简易列表
func GetSimpleList(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationLoadBalance, controller.OperationREAD)
if e != nil {
return
}
flag, result, err := balance.GetBalancNames()
......
......@@ -4,18 +4,39 @@ import (
"net/http"
"regexp"
goku_handler "github.com/eolinker/goku-api-gateway/goku-handler"
"github.com/pkg/errors"
"github.com/eolinker/goku-api-gateway/console/controller"
"github.com/eolinker/goku-api-gateway/console/module/cluster"
)
const operationCluster = "nodeManagement"
//Handlers handlers
type Handlers struct {
}
//Handlers handlers
func (h *Handlers) Handlers(factory *goku_handler.AccountHandlerFactory) map[string]http.Handler {
return map[string]http.Handler{
"/add": factory.NewAccountHandleFunction(operationCluster, true, AddCluster),
"/edit": factory.NewAccountHandleFunction(operationCluster, true, EditCluster),
"/delete": factory.NewAccountHandleFunction(operationCluster, true, DeleteCluster),
"/list": factory.NewAccountHandleFunction(operationCluster, false, GetClusterInfoList),
"/simpleList": factory.NewAccountHandleFunction(operationCluster, false, GetClusterList),
}
}
//NewHandlers new handlers
func NewHandlers() *Handlers {
return &Handlers{}
}
//GetClusterList 获取集群列表
func GetClusterList(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationNone, controller.OperationREAD)
if e != nil {
return
}
list, _ := cluster.GetClusters()
controller.WriteResultInfo(httpResponse,
......@@ -26,10 +47,7 @@ func GetClusterList(httpResponse http.ResponseWriter, httpRequest *http.Request)
//GetCluster 获取集群信息
func GetCluster(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationNone, controller.OperationREAD)
if e != nil {
return
}
httpRequest.ParseForm()
name := httpRequest.Form.Get("name")
......@@ -47,10 +65,7 @@ func GetCluster(httpResponse http.ResponseWriter, httpRequest *http.Request) {
//AddCluster 新增集群
func AddCluster(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationNone, controller.OperationREAD)
if e != nil {
return
}
httpRequest.ParseForm()
name := httpRequest.Form.Get("name")
title := httpRequest.Form.Get("title")
......@@ -78,10 +93,7 @@ func AddCluster(httpResponse http.ResponseWriter, httpRequest *http.Request) {
//EditCluster 新增集群
func EditCluster(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationNone, controller.OperationREAD)
if e != nil {
return
}
httpRequest.ParseForm()
name := httpRequest.Form.Get("name")
title := httpRequest.Form.Get("title")
......@@ -105,10 +117,7 @@ func EditCluster(httpResponse http.ResponseWriter, httpRequest *http.Request) {
//DeleteCluster 新增集群
func DeleteCluster(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationNone, controller.OperationREAD)
if e != nil {
return
}
httpRequest.ParseForm()
name := httpRequest.Form.Get("name")
match, err := regexp.MatchString(`^[a-zA-Z][a-zA-z0-9_]*$`, name)
......@@ -135,10 +144,7 @@ func DeleteCluster(httpResponse http.ResponseWriter, httpRequest *http.Request)
//GetClusterInfoList 获取集群信息列表
func GetClusterInfoList(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationNone, controller.OperationREAD)
if e != nil {
return
}
result, _ := cluster.GetClusters()
controller.WriteResultInfo(httpResponse,
......
......@@ -6,17 +6,38 @@ import (
"strconv"
"time"
goku_handler "github.com/eolinker/goku-api-gateway/goku-handler"
"github.com/eolinker/goku-api-gateway/console/module/versionConfig"
"github.com/eolinker/goku-api-gateway/console/controller"
)
const operationVersion = "versionManagement"
//VersionHandlers 版本处理器
type VersionHandlers struct {
}
//Handlers handlers
func (h *VersionHandlers) Handlers(factory *goku_handler.AccountHandlerFactory) map[string]http.Handler {
return map[string]http.Handler{
"/add": factory.NewAccountHandleFunction(operationVersion, true, AddVersionConfig),
"/basic/edit": factory.NewAccountHandleFunction(operationVersion, true, EditVersionBasicConfig),
"/delete": factory.NewAccountHandleFunction(operationVersion, true, BatchDeleteVersionConfig),
"/getList": factory.NewAccountHandleFunction(operationVersion, false, GetVersionList),
"/publish": factory.NewAccountHandleFunction(operationVersion, true, PublishVersion),
}
}
//NewVersionHandlers new versionHandlers
func NewVersionHandlers() *VersionHandlers {
return &VersionHandlers{}
}
//GetVersionList 获取版本列表
func GetVersionList(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationNone, controller.OperationREAD)
if e != nil {
return
}
httpRequest.ParseForm()
keyword := httpRequest.Form.Get("keyword")
result, _ := versionConfig.GetVersionList(keyword)
......@@ -28,10 +49,7 @@ func GetVersionList(httpResponse http.ResponseWriter, httpRequest *http.Request)
//AddVersionConfig 新增版本配置
func AddVersionConfig(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationNone, controller.OperationREAD)
if e != nil {
return
}
httpRequest.ParseForm()
name := httpRequest.Form.Get("name")
version := httpRequest.Form.Get("version")
......@@ -44,14 +62,15 @@ func AddVersionConfig(httpResponse http.ResponseWriter, httpRequest *http.Reques
}
//count := cluster.GetVersionConfigCount()
now := time.Now().Format("2006-01-02 15:04:05")
id, err := versionConfig.AddVersionConfig(name, version, remark, now)
userID := goku_handler.UserIDFromRequest(httpRequest)
id, err := versionConfig.AddVersionConfig(name, version, remark, now, userID)
if err != nil {
controller.WriteError(httpResponse, "380000", "versionConfig", err.Error(), err)
return
}
if p == 1 {
versionConfig.PublishVersion(id, now)
versionConfig.PublishVersion(id, userID, now)
}
controller.WriteResultInfo(httpResponse,
"versionConfig",
......@@ -60,12 +79,37 @@ func AddVersionConfig(httpResponse http.ResponseWriter, httpRequest *http.Reques
return
}
//BatchDeleteVersionConfig 批量删除版本配置
func BatchDeleteVersionConfig(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationNone, controller.OperationREAD)
if e != nil {
//EditVersionBasicConfig 新增版本配置
func EditVersionBasicConfig(httpResponse http.ResponseWriter, httpRequest *http.Request) {
httpRequest.ParseForm()
name := httpRequest.Form.Get("name")
version := httpRequest.Form.Get("version")
remark := httpRequest.Form.Get("remark")
versionID := httpRequest.Form.Get("versionID")
id, err := strconv.Atoi(versionID)
if err != nil {
controller.WriteError(httpResponse, "380000", "versionConfig", err.Error(), err)
return
}
userID := goku_handler.UserIDFromRequest(httpRequest)
err = versionConfig.EditVersionBasicConfig(name, version, remark, userID, id)
if err != nil {
controller.WriteError(httpResponse, "380000", "versionConfig", err.Error(), err)
return
}
controller.WriteResultInfo(httpResponse,
"versionConfig",
"",
nil)
return
}
//BatchDeleteVersionConfig 批量删除版本配置
func BatchDeleteVersionConfig(httpResponse http.ResponseWriter, httpRequest *http.Request) {
httpRequest.ParseForm()
ids := httpRequest.Form.Get("ids")
idList := make([]int, 0, 10)
......@@ -93,13 +137,14 @@ func BatchDeleteVersionConfig(httpResponse http.ResponseWriter, httpRequest *htt
func PublishVersion(httpResponse http.ResponseWriter, httpRequest *http.Request) {
httpRequest.ParseForm()
versionID := httpRequest.Form.Get("versionID")
userID := goku_handler.UserIDFromRequest(httpRequest)
id, err := strconv.Atoi(versionID)
if err != nil {
controller.WriteError(httpResponse, "380002", "versionConfig", "[ERROR]Illegal versionID", err)
return
}
now := time.Now().Format("2006-01-02 15:04:05")
err = versionConfig.PublishVersion(id, now)
err = versionConfig.PublishVersion(id, userID, now)
if err != nil {
controller.WriteError(httpResponse, "380000", "versionConfig", err.Error(), err)
return
......
......@@ -4,39 +4,38 @@ import (
"fmt"
"net/http"
goku_handler "github.com/eolinker/goku-api-gateway/goku-handler"
"github.com/eolinker/goku-api-gateway/common/auto-form"
"github.com/eolinker/goku-api-gateway/console/controller"
module "github.com/eolinker/goku-api-gateway/console/module/config-log"
)
//AccessLogHandler access日志处理器
type AccessLogHandler struct {
//LogHandler access日志处理器
type LogHandler struct {
getHandler http.Handler
setHandler http.Handler
}
func (h *AccessLogHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
_, err := controller.CheckLogin(w, r, controller.OperationGatewayConfig, controller.OperationEDIT)
if err != nil {
return
}
func (h *LogHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case http.MethodGet:
{
h.get(w, r)
h.getHandler.ServeHTTP(w, r)
}
case http.MethodPut:
{
h.set(w, r)
h.setHandler.ServeHTTP(w, r)
}
default:
w.WriteHeader(404)
}
}
func (h *AccessLogHandler) get(w http.ResponseWriter, r *http.Request) {
//AccessLogGet 获取access日志配置
func AccessLogGet(w http.ResponseWriter, r *http.Request) {
config, e := module.GetAccess()
if e = r.ParseForm(); e != nil {
controller.WriteError(w, "270000", "data", "[Get]未知错误:"+e.Error(), e)
......@@ -49,7 +48,9 @@ func (h *AccessLogHandler) get(w http.ResponseWriter, r *http.Request) {
config)
}
func (h *AccessLogHandler) set(w http.ResponseWriter, r *http.Request) {
//AccessLogSet 设置access日志内容
func AccessLogSet(w http.ResponseWriter, r *http.Request) {
err := r.ParseForm()
if err = r.ParseForm(); err != nil {
controller.WriteError(w, "260000", "data", "[param_check] Parse form body error | 解析form表单参数错误", err)
......@@ -82,7 +83,7 @@ func (h *AccessLogHandler) set(w http.ResponseWriter, r *http.Request) {
err = module.Set(module.AccessLog, paramBase)
if err != nil {
controller.WriteError(w, "260000", "data", fmt.Sprintf("[mysql_error] %s", err.Error()), err)
controller.WriteError(w, "260000", "data", fmt.Sprintf("[db_error] %s", err.Error()), err)
return
}
controller.WriteResultInfo(w,
......@@ -90,3 +91,11 @@ func (h *AccessLogHandler) set(w http.ResponseWriter, r *http.Request) {
"",
nil)
}
//NewAccessHandler accessHandler
func NewAccessHandler(factory *goku_handler.AccountHandlerFactory) http.Handler {
return &LogHandler{
getHandler: factory.NewAccountHandleFunction(operationLog, false, AccessLogGet),
setHandler: factory.NewAccountHandleFunction(operationLog, true, AccessLogSet),
}
}
package config_log
import (
"fmt"
"net/http"
"strings"
module "github.com/eolinker/goku-api-gateway/console/module/config-log"
goku_handler "github.com/eolinker/goku-api-gateway/goku-handler"
)
//Handle handle
func Handle(prefix string) http.Handler {
const operationLog = "logManagement"
pre := strings.TrimSuffix(prefix, "/")
serveMux := http.NewServeMux()
consoleLogHandler := &LogHandler{
name: module.ConsoleLog,
}
//Handlers handlers
type Handlers struct {
}
serveMux.Handle(fmt.Sprintf("%s/%s", pre, "console"), consoleLogHandler)
nodeLogHandler := &LogHandler{
name: module.NodeLog,
//Handlers handlers
func (h *Handlers) Handlers(factory *goku_handler.AccountHandlerFactory) map[string]http.Handler {
return map[string]http.Handler{
"/console": NewLogHandler("console", factory),
"/node": NewLogHandler("node", factory),
"/access": NewAccessHandler(factory),
}
serveMux.Handle(fmt.Sprintf("%s/%s", pre, "node"), nodeLogHandler)
accessLogHandler := &AccessLogHandler{}
serveMux.Handle(fmt.Sprintf("%s/%s", pre, "access"), accessLogHandler)
return serveMux
}
//NewHandlers new handlers
func NewHandlers() *Handlers {
return &Handlers{}
}
......@@ -4,39 +4,20 @@ import (
"fmt"
"net/http"
goku_handler "github.com/eolinker/goku-api-gateway/goku-handler"
"github.com/eolinker/goku-api-gateway/common/auto-form"
"github.com/eolinker/goku-api-gateway/console/controller"
module "github.com/eolinker/goku-api-gateway/console/module/config-log"
)
//LogHandler 日志处理器
type LogHandler struct {
//LogHandlerGet 日志配置获取处理器
type LogHandlerGet struct {
name string
}
func (h *LogHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
_, err := controller.CheckLogin(w, r, controller.OperationGatewayConfig, controller.OperationEDIT)
if err != nil {
return
}
switch r.Method {
case http.MethodGet:
{
h.get(w, r)
}
func (h *LogHandlerGet) ServeHTTP(w http.ResponseWriter, r *http.Request) {
case http.MethodPut:
{
h.set(w, r)
}
default:
w.WriteHeader(404)
}
}
func (h *LogHandler) get(w http.ResponseWriter, r *http.Request) {
config, e := module.Get(h.name)
if e = r.ParseForm(); e != nil {
controller.WriteError(w, "270000", "data", "[Get]未知错误:"+e.Error(), e)
......@@ -50,7 +31,12 @@ func (h *LogHandler) get(w http.ResponseWriter, r *http.Request) {
}
func (h *LogHandler) set(w http.ResponseWriter, r *http.Request) {
//LogHandlerSet 设置日志处理器
type LogHandlerSet struct {
name string
}
func (h *LogHandlerSet) ServeHTTP(w http.ResponseWriter, r *http.Request) {
err := r.ParseForm()
if err = r.ParseForm(); err != nil {
......@@ -83,7 +69,7 @@ func (h *LogHandler) set(w http.ResponseWriter, r *http.Request) {
}
err = module.Set(h.name, paramBase)
if err != nil {
controller.WriteError(w, "260000", "data", fmt.Sprintf("[mysql_error] %s", err.Error()), err)
controller.WriteError(w, "260000", "data", fmt.Sprintf("[db_error] %s", err.Error()), err)
return
}
controller.WriteResultInfo(w,
......@@ -91,3 +77,11 @@ func (h *LogHandler) set(w http.ResponseWriter, r *http.Request) {
"",
nil)
}
//NewLogHandler 日志handler
func NewLogHandler(name string, factory *goku_handler.AccountHandlerFactory) http.Handler {
return &LogHandler{
getHandler: factory.NewAccountHandler(operationLog, false, &LogHandlerGet{name: name}),
setHandler: factory.NewAccountHandler(operationLog, true, &LogHandlerSet{name: name}),
}
}
......@@ -2,27 +2,24 @@ package discovery
import (
"fmt"
"github.com/eolinker/goku-api-gateway/console/controller"
"net/http"
"github.com/eolinker/goku-api-gateway/common/auto-form"
"github.com/eolinker/goku-api-gateway/console/controller"
"github.com/eolinker/goku-api-gateway/console/module/service"
driver2 "github.com/eolinker/goku-api-gateway/server/driver"
)
func add(w http.ResponseWriter, r *http.Request) {
_, err := controller.CheckLogin(w, r, controller.OperationLoadBalance, controller.OperationEDIT)
if err != nil {
return
}
if err = r.ParseForm(); err != nil {
if err := r.ParseForm(); err != nil {
controller.WriteError(w, "260000", "data", "[param_check] Parse form body error | 解析form表单参数错误", err)
return
}
param := new(service.AddParam)
err = auto.SetValues(r.PostForm, param)
err := auto.SetValues(r.PostForm, param)
if err != nil {
controller.WriteError(w, "260000", "data", fmt.Sprintf("[param_check] %s", err.Error()), err)
return
......
......@@ -2,19 +2,16 @@ package discovery
import (
"fmt"
"github.com/eolinker/goku-api-gateway/console/controller"
"net/http"
"github.com/eolinker/goku-api-gateway/console/controller"
"github.com/eolinker/goku-api-gateway/console/module/service"
)
func setDefault(w http.ResponseWriter, r *http.Request) {
_, err := controller.CheckLogin(w, r, controller.OperationLoadBalance, controller.OperationEDIT)
if err != nil {
return
}
if err != r.ParseForm() {
if err := r.ParseForm() ; err!= nil{
controller.WriteError(w, "260000", "data", "[param_check] Parse form body error | 解析form表单参数错误", err)
return
}
......@@ -24,7 +21,7 @@ func setDefault(w http.ResponseWriter, r *http.Request) {
return
}
err = service.SetDefaut(name)
err := service.SetDefaut(name)
if err != nil {
controller.WriteError(w, "260000", "data", fmt.Sprintf("[error] %s", err.Error()), err)
return
......
......@@ -2,21 +2,16 @@ package discovery
import (
"fmt"
"net/http"
"strings"
dao_service2 "github.com/eolinker/goku-api-gateway/server/dao/console-sqlite3/dao-service"
"github.com/eolinker/goku-api-gateway/console/controller"
"github.com/eolinker/goku-api-gateway/console/module/service"
dao_service2 "github.com/eolinker/goku-api-gateway/server/dao/console-sqlite3/dao-service"
"net/http"
"strings"
)
func delete(w http.ResponseWriter, r *http.Request) {
_, err := controller.CheckLogin(w, r, controller.OperationLoadBalance, controller.OperationEDIT)
if err != nil {
return
}
if err != r.ParseForm() {
if err := r.ParseForm() ; err!= nil{
controller.WriteError(w, "260000", "serviceDiscovery", "[param_check] Parse form body error | 解析form表单参数错误", err)
return
}
......@@ -24,7 +19,7 @@ func delete(w http.ResponseWriter, r *http.Request) {
names := strings.Split(nameStr, ",")
err = service.Delete(names)
err := service.Delete(names)
if err != nil {
if en, ok := err.(dao_service2.DeleteError); ok {
......
package discovery
import (
"net/http"
"github.com/eolinker/goku-api-gateway/console/controller"
driver2 "github.com/eolinker/goku-api-gateway/server/driver"
"net/http"
)
func getDrivices(w http.ResponseWriter, r *http.Request) {
ds := driver2.GetByType(driver2.Discovery)
_, err := controller.CheckLogin(w, r, controller.OperationLoadBalance, controller.OperationREAD)
if err != nil {
return
}
controller.WriteResultInfo(w, "serviceDiscovery", "data", ds)
}
......@@ -2,26 +2,22 @@ package discovery
import (
"fmt"
"net/http"
"github.com/eolinker/goku-api-gateway/common/auto-form"
"github.com/eolinker/goku-api-gateway/console/controller"
"github.com/eolinker/goku-api-gateway/console/module/service"
driver2 "github.com/eolinker/goku-api-gateway/server/driver"
"net/http"
)
func edit(w http.ResponseWriter, r *http.Request) {
_, err := controller.CheckLogin(w, r, controller.OperationLoadBalance, controller.OperationEDIT)
if err != nil {
return
}
if err != r.ParseForm() {
if err := r.ParseForm() ; err!= nil{
controller.WriteError(w, "260000", "serviceDiscovery", "[param_check] Parse form body error | 解析form表单参数错误", err)
return
}
param := new(service.AddParam)
err = auto.SetValues(r.PostForm, param)
err := auto.SetValues(r.PostForm, param)
if err != nil {
controller.WriteError(w, "260000", "data", fmt.Sprintf("[param_check] %s", err.Error()), err)
return
......
......@@ -2,17 +2,13 @@ package discovery
import (
"fmt"
"net/http"
"github.com/eolinker/goku-api-gateway/console/controller"
"github.com/eolinker/goku-api-gateway/console/module/service"
"net/http"
)
func getInfo(w http.ResponseWriter, r *http.Request) {
_, err := controller.CheckLogin(w, r, controller.OperationLoadBalance, controller.OperationREAD)
if err != nil {
return
}
name := r.URL.Query().Get("name")
if !service.ValidateName(name) {
......
......@@ -2,24 +2,31 @@ package discovery
import (
"net/http"
)
//Handle 服务发现处理器
func Handle(prefix string) http.Handler {
serveMux := http.NewServeMux()
serveMux.HandleFunc("/drivers", getDrivices)
serveMux.HandleFunc("/add", add)
serveMux.HandleFunc("/delete", delete)
serveMux.HandleFunc("/save", edit)
serveMux.HandleFunc("/info", getInfo)
serveMux.HandleFunc("/simple", simple)
serveMux.HandleFunc("/list", list)
goku_handler "github.com/eolinker/goku-api-gateway/goku-handler"
)
serveMux.HandleFunc("/default", setDefault)
//Handlers handlers
type Handlers struct {
}
return http.StripPrefix(prefix, serveMux)
//Handlers handlers
func (h *Handlers) Handlers(factory *goku_handler.AccountHandlerFactory) map[string]http.Handler {
return map[string]http.Handler{
"/add": factory.NewAccountHandleFunction(operationDiscovery, true, add),
"/save": factory.NewAccountHandleFunction(operationDiscovery, true, edit),
"/delete": factory.NewAccountHandleFunction(operationDiscovery, true, delete),
"/info": factory.NewAccountHandleFunction(operationDiscovery, false, getInfo),
"/list": factory.NewAccountHandleFunction(operationDiscovery, false, list),
"/default": factory.NewAccountHandleFunction(operationDiscovery, true, setDefault),
"/drivers": factory.NewAccountHandleFunction(operationDiscovery, false, getDrivices),
"/simple": factory.NewAccountHandleFunction(operationDiscovery, false, simple),
}
}
//NewHandlers new handlers
func NewHandlers() *Handlers {
return &Handlers{}
}
const operationDiscovery = "balanceManagement"
package discovery
import (
"net/http"
"github.com/eolinker/goku-api-gateway/console/controller"
"github.com/eolinker/goku-api-gateway/console/module/service"
"net/http"
)
func list(w http.ResponseWriter, r *http.Request) {
_, err := controller.CheckLogin(w, r, controller.OperationLoadBalance, controller.OperationREAD)
if err != nil {
return
}
_ = r.ParseForm()
......
package discovery
import (
"github.com/eolinker/goku-api-gateway/console/controller"
"net/http"
"github.com/eolinker/goku-api-gateway/console/controller"
"github.com/eolinker/goku-api-gateway/console/module/service"
)
func simple(w http.ResponseWriter, r *http.Request) {
_, err := controller.CheckLogin(w, r, controller.OperationLoadBalance, controller.OperationREAD)
if err != nil {
return
}
vs, def, err := service.SimpleList()
if err != nil {
......
......@@ -4,16 +4,32 @@ import (
"encoding/json"
"net/http"
goku_handler "github.com/eolinker/goku-api-gateway/goku-handler"
"github.com/eolinker/goku-api-gateway/console/controller"
"github.com/eolinker/goku-api-gateway/console/module/gateway"
)
const operationGateway = "gateway"
//Handlers hendlers
type Handlers struct {
}
//Handlers handlers
func (h *Handlers) Handlers(factory *goku_handler.AccountHandlerFactory) map[string]http.Handler {
return map[string]http.Handler{
"/getSummaryInfo": factory.NewAccountHandleFunction(operationGateway, false, GetGatewayBasicInfo),
}
}
//NewHandlers new handlers
func NewHandlers() *Handlers {
return &Handlers{}
}
//GetGatewayBasicInfo 获取网关基本信息
func GetGatewayBasicInfo(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationNone, controller.OperationREAD)
if e != nil {
return
}
flag, result, err := gateway.GetGatewayMonitorSummaryByPeriod()
if !flag {
......
......@@ -4,19 +4,36 @@ import (
"net/http"
"strconv"
goku_handler "github.com/eolinker/goku-api-gateway/goku-handler"
"github.com/eolinker/goku-api-gateway/ksitigarbha"
"github.com/pkg/errors"
"github.com/eolinker/goku-api-gateway/console/controller"
"github.com/eolinker/goku-api-gateway/console/module/monitor"
)
//GetMonitorModules 获取监控模块列表
func GetMonitorModules(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationNone, controller.OperationREAD)
if e != nil {
return
const operationMonitorModule = "monitorModuleManagement"
//Handlers handlers
type Handlers struct {
}
//Handlers handlers
func (h *Handlers) Handlers(factory *goku_handler.AccountHandlerFactory) map[string]http.Handler {
return map[string]http.Handler{
"/get": factory.NewAccountHandleFunction(operationMonitorModule, false, GetMonitorModules),
"/set": factory.NewAccountHandleFunction(operationMonitorModule, true, SetMonitorModule),
}
}
//NewHandlers new handlers
func NewHandlers() *Handlers {
return &Handlers{}
}
//GetMonitorModules 获取监控模块列表
func GetMonitorModules(httpResponse http.ResponseWriter, httpRequest *http.Request) {
result, err := monitor.GetMonitorModules()
if err != nil {
controller.WriteError(httpResponse,
......@@ -25,18 +42,14 @@ func GetMonitorModules(httpResponse http.ResponseWriter, httpRequest *http.Reque
err.Error(),
err)
return
}
controller.WriteResultInfo(httpResponse, "monitorModule", "moduleList", result)
return
}
//SetMonitorModule 设置监控模块
func SetMonitorModule(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationNone, controller.OperationREAD)
if e != nil {
return
}
httpRequest.ParseForm()
moduleName := httpRequest.Form.Get("moduleName")
moduleStatus := httpRequest.Form.Get("moduleStatus")
......@@ -62,7 +75,11 @@ func SetMonitorModule(httpResponse http.ResponseWriter, httpRequest *http.Reques
err)
return
}
if status == 1 {
ksitigarbha.Open(moduleName, config)
} else {
ksitigarbha.Close(moduleName)
}
controller.WriteResultInfo(httpResponse, "monitorModule", "", nil)
return
}
......@@ -3,8 +3,10 @@ package node
import (
"encoding/json"
"errors"
"github.com/eolinker/goku-api-gateway/common/auto-form"
goku_handler "github.com/eolinker/goku-api-gateway/goku-handler"
"github.com/eolinker/goku-api-gateway/common/auto-form"
"github.com/eolinker/goku-api-gateway/console/module/cluster"
log "github.com/eolinker/goku-api-gateway/goku-log"
......@@ -17,13 +19,32 @@ import (
"github.com/eolinker/goku-api-gateway/utils"
)
//AddNode 新增节点信息
func AddNode(httpResponse http.ResponseWriter, httpRequest *http.Request) {
const operationNode = "nodeManagement"
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationNode, controller.OperationEDIT)
if e != nil {
return
//Handlers Handlers
type Handlers struct {
}
//Handlers handlers
func (h *Handlers) Handlers(factory *goku_handler.AccountHandlerFactory) map[string]http.Handler {
return map[string]http.Handler{
"/add": factory.NewAccountHandleFunction(operationNode, true, AddNode),
"/edit": factory.NewAccountHandleFunction(operationNode, true, EditNode),
"/delete": factory.NewAccountHandleFunction(operationNode, true, DeleteNode),
"/getInfo": factory.NewAccountHandleFunction(operationNode, false, GetNodeInfo),
"/getList": factory.NewAccountHandleFunction(operationNode, false, GetNodeList),
"/batchEditGroup": factory.NewAccountHandleFunction(operationNode, true, BatchEditNodeGroup),
"/batchDelete": factory.NewAccountHandleFunction(operationNode, true, BatchDeleteNode),
}
}
//NewNodeHandlers new nodeHandlers
func NewNodeHandlers() *Handlers {
return &Handlers{}
}
//AddNode 新增节点信息
func AddNode(httpResponse http.ResponseWriter, httpRequest *http.Request) {
cluserName := httpRequest.PostFormValue("cluster")
......@@ -35,27 +56,16 @@ func AddNode(httpResponse http.ResponseWriter, httpRequest *http.Request) {
//nodeNumber := rsa.CertConf["nodeNumber"].(int)
type NodeParam struct {
NodeName string `opt:"nodeName,require"`
NodeName string `opt:"nodeName,require"`
ListenAddress string `opt:"listenAddress,require"`
AdminAddress string `opt:"adminAddress,require"`
GroupID int `opt:"groupID,require"`
Path string `opt:"gatewayPath"`
AdminAddress string `opt:"adminAddress,require"`
GroupID int `opt:"groupID,require"`
Path string `opt:"gatewayPath"`
}
//
//nodeName := httpRequest.PostFormValue("nodeName")
//listenAddress := httpRequest.PostFormValue("listenAddress")
//adminAddress := httpRequest.PostFormValue("adminAddress")
//groupID := httpRequest.PostFormValue("groupID")
//gatewayPath := httpRequest.PostFormValue("gatewayPath")
//
//gID, err := strconv.Atoi(groupID)
//if err != nil && groupID != "" {
// controller.WriteError(httpResponse, "230015", "", "[ERROR]Illegal groupID!", err)
// return
//}
param:=new(NodeParam)
err:=auto.SetValues(httpRequest.Form,param)
if err!= nil{
param := new(NodeParam)
err := auto.SetValues(httpRequest.Form, param)
if err != nil {
controller.WriteError(httpResponse, "230015", "", "[ERROR]", err)
return
}
......@@ -88,37 +98,32 @@ func AddNode(httpResponse http.ResponseWriter, httpRequest *http.Request) {
}
}
flag, result, err := node.AddNode(clusterID, param.NodeName, param.ListenAddress, param.AdminAddress, param.Path, param.GroupID)
id, v, result, err := node.AddNode(clusterID, param.NodeName, param.ListenAddress, param.AdminAddress, param.Path, param.GroupID)
if !flag {
if err != nil {
controller.WriteError(httpResponse,
"330000",
"node",
result["error"].(string),
result,
err)
return
}
res := map[string]interface{}{
"nodeID": result["nodeID"],
"version": result["version"],
"nodeID": id,
"version": v,
"statusCode": "000000",
"type": "node",
"resultDesc": "",
}
data, _ := json.Marshal(res)
_,_=httpResponse.Write(data)
_, _ = httpResponse.Write(data)
}
//EditNode 修改节点信息
func EditNode(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationNode, controller.OperationEDIT)
if e != nil {
return
}
nodeName := httpRequest.PostFormValue("nodeName")
listenAddress := httpRequest.PostFormValue("listenAddress")
adminAddress := httpRequest.PostFormValue("adminAddress")
......@@ -170,17 +175,9 @@ func EditNode(httpResponse http.ResponseWriter, httpRequest *http.Request) {
}
}
//exits := node.CheckIsExistRemoteAddr(id, listenAddress, adminAddress)
//if exits {
//
// controller.WriteError(httpResponse, "230005", "node", "[ERROR]The remote address is existed!", nil)
// return
//
//}
result, err := node.EditNode(nodeName, listenAddress, adminAddress, gatewayPath, id, gID)
flag, result, _ := node.EditNode(nodeName, listenAddress, adminAddress, gatewayPath, id, gID)
if !flag {
if err != nil {
controller.WriteError(httpResponse, "330000", "node", result, nil)
return
}
......@@ -192,12 +189,6 @@ func EditNode(httpResponse http.ResponseWriter, httpRequest *http.Request) {
//DeleteNode 删除节点信息
func DeleteNode(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationNode, controller.OperationEDIT)
if e != nil {
return
}
nodeID := httpRequest.PostFormValue("nodeID")
id, err := strconv.Atoi(nodeID)
......@@ -210,8 +201,8 @@ func DeleteNode(httpResponse http.ResponseWriter, httpRequest *http.Request) {
return
}
flag, result, err := node.DeleteNode(id)
if !flag {
result, err := node.DeleteNode(id)
if err != nil {
controller.WriteError(httpResponse,
"330000",
......@@ -227,12 +218,8 @@ func DeleteNode(httpResponse http.ResponseWriter, httpRequest *http.Request) {
// GetNodeList 获取节点列表
func GetNodeList(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationNode, controller.OperationREAD)
if e != nil {
return
}
httpRequest.ParseForm()
cluserName := httpRequest.Form.Get("cluster")
clusterName := httpRequest.Form.Get("cluster")
groupID := httpRequest.Form.Get("groupID")
keyword := httpRequest.Form.Get("keyword")
......@@ -245,21 +232,20 @@ func GetNodeList(httpResponse http.ResponseWriter, httpRequest *http.Request) {
gID = -1
}
clusterID := cluster.GetClusterIDByName(cluserName)
clusterID := cluster.GetClusterIDByName(clusterName)
if clusterID == 0 {
controller.WriteError(httpResponse, "330003", "node", "[ERROR]The cluster dosen't exist!", nil)
return
}
flag, result, err := node.GetNodeList(clusterID, gID, keyword)
if !flag {
result, err := node.GetNodeList(clusterID, gID, keyword)
if err != nil {
controller.WriteError(httpResponse,
"330000",
"node",
"[ERROR]Empty node list!",
err)
return
}
controller.WriteResultInfo(httpResponse, "node", "nodeList", result)
// controller.WriteResultInfo(httpResponse, "nodeList", result)
......@@ -268,10 +254,6 @@ func GetNodeList(httpResponse http.ResponseWriter, httpRequest *http.Request) {
//GetNodeInfo 获取节点信息
func GetNodeInfo(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationNode, controller.OperationREAD)
if e != nil {
return
}
nodeID := httpRequest.PostFormValue("nodeID")
......@@ -286,8 +268,8 @@ func GetNodeInfo(httpResponse http.ResponseWriter, httpRequest *http.Request) {
err)
return
}
result, err := node.GetNodeInfo(id)
if err!= nil {
result, err := node.GetNodeInfo(id)
if err != nil {
controller.WriteError(httpResponse,
"330000",
......@@ -302,16 +284,8 @@ func GetNodeInfo(httpResponse http.ResponseWriter, httpRequest *http.Request) {
return
}
//BatchEditNodeGroup 批量修改节点分组
func BatchEditNodeGroup(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationNode, controller.OperationEDIT)
if e != nil {
return
}
nodeIDList := httpRequest.PostFormValue("nodeIDList")
groupID := httpRequest.PostFormValue("groupID")
......@@ -325,8 +299,8 @@ func BatchEditNodeGroup(httpResponse http.ResponseWriter, httpRequest *http.Requ
return
}
flag, result, err := node.BatchEditNodeGroup(nodeIDList, gID)
if !flag {
result, err := node.BatchEditNodeGroup(nodeIDList, gID)
if err != nil {
controller.WriteError(httpResponse,
"330000",
......@@ -345,16 +319,10 @@ func BatchEditNodeGroup(httpResponse http.ResponseWriter, httpRequest *http.Requ
//BatchDeleteNode 批量删除节点
func BatchDeleteNode(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationNode, controller.OperationEDIT)
if e != nil {
return
}
nodeIDList := httpRequest.PostFormValue("nodeIDList")
flag, result, err := node.BatchDeleteNode(nodeIDList)
if !flag {
result, err := node.BatchDeleteNode(nodeIDList)
if err != nil {
if result == "230013" {
controller.WriteError(httpResponse,
......
......@@ -4,18 +4,35 @@ import (
"net/http"
"strconv"
goku_handler "github.com/eolinker/goku-api-gateway/goku-handler"
"github.com/eolinker/goku-api-gateway/console/controller"
"github.com/eolinker/goku-api-gateway/console/module/cluster"
"github.com/eolinker/goku-api-gateway/console/module/node"
)
//AddNodeGroup 新增节点分组
func AddNodeGroup(httpResponse http.ResponseWriter, httpRequest *http.Request) {
//GroupHandlers groupHandlers
type GroupHandlers struct {
}
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationNode, controller.OperationEDIT)
if e != nil {
return
//Handlers handlers
func (h *GroupHandlers) Handlers(factory *goku_handler.AccountHandlerFactory) map[string]http.Handler {
return map[string]http.Handler{
"/add": factory.NewAccountHandleFunction(operationNode, true, AddNodeGroup),
"/edit": factory.NewAccountHandleFunction(operationNode, true, EditNodeGroup),
"/delete": factory.NewAccountHandleFunction(operationNode, true, DeleteNodeGroup),
"/getInfo": factory.NewAccountHandleFunction(operationNode, false, GetNodeGroupInfo),
"/getList": factory.NewAccountHandleFunction(operationNode, false, GetNodeGroupList),
}
}
//NewGroupHandlers new groupHandlers
func NewGroupHandlers() *GroupHandlers {
return &GroupHandlers{}
}
//AddNodeGroup 新增节点分组
func AddNodeGroup(httpResponse http.ResponseWriter, httpRequest *http.Request) {
cluserName := httpRequest.PostFormValue("cluster")
......@@ -53,11 +70,6 @@ func AddNodeGroup(httpResponse http.ResponseWriter, httpRequest *http.Request) {
//EditNodeGroup 修改节点分组信息
func EditNodeGroup(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationNode, controller.OperationEDIT)
if e != nil {
return
}
groupName := httpRequest.PostFormValue("groupName")
groupID := httpRequest.PostFormValue("groupID")
if groupName == "" {
......@@ -97,10 +109,6 @@ func EditNodeGroup(httpResponse http.ResponseWriter, httpRequest *http.Request)
//DeleteNodeGroup 删除节点分组
func DeleteNodeGroup(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationNode, controller.OperationEDIT)
if e != nil {
return
}
groupID := httpRequest.PostFormValue("groupID")
......@@ -149,10 +157,6 @@ func DeleteNodeGroup(httpResponse http.ResponseWriter, httpRequest *http.Request
//GetNodeGroupInfo 获取节点分组信息
func GetNodeGroupInfo(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationNode, controller.OperationREAD)
if e != nil {
return
}
groupID := httpRequest.PostFormValue("groupID")
......@@ -182,10 +186,6 @@ func GetNodeGroupInfo(httpResponse http.ResponseWriter, httpRequest *http.Reques
//GetNodeGroupList 获取节点分组列表
func GetNodeGroupList(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationNode, controller.OperationREAD)
if e != nil {
return
}
cluserName := httpRequest.FormValue("cluster")
clusterID := cluster.GetClusterIDByName(cluserName)
......
......@@ -4,17 +4,47 @@ import (
"net/http"
"strconv"
goku_handler "github.com/eolinker/goku-api-gateway/goku-handler"
"github.com/eolinker/goku-api-gateway/console/controller"
"github.com/eolinker/goku-api-gateway/console/module/plugin"
plugin_config "github.com/eolinker/goku-api-gateway/console/module/plugin/plugin-config"
)
const operationPlugin = "pluginManagement"
//Handlers handlers
type Handlers struct {
}
//Handlers handlers
func (h *Handlers) Handlers(factory *goku_handler.AccountHandlerFactory) map[string]http.Handler {
return map[string]http.Handler{
"/add": factory.NewAccountHandleFunction(operationPlugin, true, AddPlugin),
"/edit": factory.NewAccountHandleFunction(operationPlugin, true, EditPlugin),
"/delete": factory.NewAccountHandleFunction(operationPlugin, true, DeletePlugin),
"/checkNameIsExist": factory.NewAccountHandleFunction(operationPlugin, false, CheckNameIsExist),
"/checkIndexIsExist": factory.NewAccountHandleFunction(operationPlugin, false, CheckIndexIsExist),
"/getList": factory.NewAccountHandleFunction(operationPlugin, false, GetPluginList),
"/getInfo": factory.NewAccountHandleFunction(operationPlugin, false, GetPluginInfo),
"/getConfig": factory.NewAccountHandleFunction(operationPlugin, false, GetPluginConfig),
"/start": factory.NewAccountHandleFunction(operationPlugin, true, StartPlugin),
"/stop": factory.NewAccountHandleFunction(operationPlugin, true, StopPlugin),
"/getListByType": factory.NewAccountHandleFunction(operationPlugin, false, GetPluginListByPluginType),
"/batchStop": factory.NewAccountHandleFunction(operationPlugin, true, BatchStopPlugin),
"/batchStart": factory.NewAccountHandleFunction(operationPlugin, true, BatchStartPlugin),
"/availiable/check": factory.NewAccountHandleFunction(operationPlugin, false, CheckPluginIsAvailable),
}
}
//NewHandlers new handlers
func NewHandlers() *Handlers {
return &Handlers{}
}
// GetPluginList 获取插件列表
func GetPluginList(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationPlugin, controller.OperationREAD)
if e != nil {
return
}
httpRequest.ParseForm()
keyword := httpRequest.Form.Get("keyword")
condition := httpRequest.Form.Get("condition")
......@@ -40,10 +70,6 @@ func GetPluginList(httpResponse http.ResponseWriter, httpRequest *http.Request)
//AddPlugin 新增插件信息
func AddPlugin(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationPlugin, controller.OperationEDIT)
if e != nil {
return
}
pluginPriority := httpRequest.PostFormValue("pluginPriority")
pluginName := httpRequest.PostFormValue("pluginName")
......@@ -106,10 +132,6 @@ func AddPlugin(httpResponse http.ResponseWriter, httpRequest *http.Request) {
//EditPlugin 修改插件信息
func EditPlugin(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationPlugin, controller.OperationEDIT)
if e != nil {
return
}
pluginPriority := httpRequest.PostFormValue("pluginPriority")
pluginName := httpRequest.PostFormValue("pluginName")
......@@ -162,10 +184,6 @@ func EditPlugin(httpResponse http.ResponseWriter, httpRequest *http.Request) {
//DeletePlugin 删除插件信息
func DeletePlugin(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationPlugin, controller.OperationEDIT)
if e != nil {
return
}
pluginName := httpRequest.PostFormValue("pluginName")
flag, err := plugin.CheckNameIsExist(pluginName)
......@@ -195,10 +213,6 @@ func DeletePlugin(httpResponse http.ResponseWriter, httpRequest *http.Request) {
//GetPluginInfo 获取插件信息
func GetPluginInfo(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationPlugin, controller.OperationREAD)
if e != nil {
return
}
pluginName := httpRequest.PostFormValue("pluginName")
......@@ -228,10 +242,6 @@ func GetPluginInfo(httpResponse http.ResponseWriter, httpRequest *http.Request)
//GetPluginConfig 获取插件配置
func GetPluginConfig(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationPlugin, controller.OperationREAD)
if e != nil {
return
}
pluginName := httpRequest.PostFormValue("pluginName")
flag, result, err := plugin.GetPluginConfig(pluginName)
......@@ -252,10 +262,6 @@ func GetPluginConfig(httpResponse http.ResponseWriter, httpRequest *http.Request
//CheckIndexIsExist 判断插件优先级是否存在
func CheckIndexIsExist(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationPlugin, controller.OperationEDIT)
if e != nil {
return
}
pluginPriority := httpRequest.PostFormValue("pluginPriority")
......@@ -286,10 +292,6 @@ func CheckIndexIsExist(httpResponse http.ResponseWriter, httpRequest *http.Reque
//CheckNameIsExist 检查插件名称是否存在
func CheckNameIsExist(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationPlugin, controller.OperationEDIT)
if e != nil {
return
}
pluginName := httpRequest.PostFormValue("pluginName")
......@@ -309,10 +311,6 @@ func CheckNameIsExist(httpResponse http.ResponseWriter, httpRequest *http.Reques
//StartPlugin 开启插件
func StartPlugin(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationPlugin, controller.OperationEDIT)
if e != nil {
return
}
pluginName := httpRequest.PostFormValue("pluginName")
......@@ -332,10 +330,6 @@ func StartPlugin(httpResponse http.ResponseWriter, httpRequest *http.Request) {
//StopPlugin 关闭插件
func StopPlugin(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationPlugin, controller.OperationEDIT)
if e != nil {
return
}
pluginName := httpRequest.PostFormValue("pluginName")
......@@ -354,10 +348,6 @@ func StopPlugin(httpResponse http.ResponseWriter, httpRequest *http.Request) {
//GetPluginListByPluginType 获取不同类型的插件列表
func GetPluginListByPluginType(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationPlugin, controller.OperationREAD)
if e != nil {
return
}
pluginType := httpRequest.PostFormValue("pluginType")
......@@ -387,10 +377,6 @@ func GetPluginListByPluginType(httpResponse http.ResponseWriter, httpRequest *ht
//BatchStopPlugin 批量关闭插件
func BatchStopPlugin(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationPlugin, controller.OperationEDIT)
if e != nil {
return
}
pluginNameList := httpRequest.PostFormValue("pluginNameList")
......@@ -411,10 +397,6 @@ func BatchStopPlugin(httpResponse http.ResponseWriter, httpRequest *http.Request
//BatchStartPlugin 批量关闭插件
func BatchStartPlugin(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationPlugin, controller.OperationEDIT)
if e != nil {
return
}
pluginNameList := httpRequest.PostFormValue("pluginNameList")
......@@ -435,10 +417,6 @@ func BatchStartPlugin(httpResponse http.ResponseWriter, httpRequest *http.Reques
//CheckPluginIsAvailable 检测插件
func CheckPluginIsAvailable(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationPlugin, controller.OperationEDIT)
if e != nil {
return
}
pluginName := httpRequest.PostFormValue("pluginName")
if len(pluginName) < 2 {
......@@ -449,37 +427,5 @@ func CheckPluginIsAvailable(httpResponse http.ResponseWriter, httpRequest *http.
nil)
return
}
//flag, nodeList, err := node.GetNodeIPList()
//if !flag {
// controller.WriteError(httpResponse,
// "210000",
// "plugin",
// "[ERROR]The Open node list is empty",
// err)
// return
//}
//flag, errPluginList := utils.CheckPluginIsAvailiable(pluginName, nodeList)
//if !flag {
//
// controller.WriteResultInfoWithCode(httpResponse,
// "210000",
// "plugin",
// "errNodeList",
// errPluginList)
// return
//}
//flag, res, _ := plugin.EditPluginCheckStatus(pluginName, 1)
//if !flag {
//
// controller.WriteError(httpResponse,
// "210000",
// "plugin",
// res,
// err)
// return
//}
//
//controller.WriteResultInfo(httpResponse, "plugin", "", nil)
return
}
......@@ -4,16 +4,38 @@ import (
"net/http"
"strconv"
goku_handler "github.com/eolinker/goku-api-gateway/goku-handler"
"github.com/eolinker/goku-api-gateway/console/controller"
"github.com/eolinker/goku-api-gateway/console/module/project"
)
const operationProject = "apiManagement"
//Handlers handlers
type Handlers struct {
}
//Handlers handlers
func (h *Handlers) Handlers(factory *goku_handler.AccountHandlerFactory) map[string]http.Handler {
return map[string]http.Handler{
"/add": factory.NewAccountHandleFunction(operationProject, true, AddProject),
"/edit": factory.NewAccountHandleFunction(operationProject, true, EditProject),
"/delete": factory.NewAccountHandleFunction(operationProject, true, DeleteProject),
"/getInfo": factory.NewAccountHandleFunction(operationProject, false, GetProjectInfo),
"/getList": factory.NewAccountHandleFunction(operationProject, false, GetProjectList),
"/strategy/getList": factory.NewAccountHandleFunction(operationProject, false, GetAPIListFromProjectNotInStrategy),
"/batchDelete": factory.NewAccountHandleFunction(operationProject, true, BatchDeleteProject),
}
}
//NewHandlers new handlers
func NewHandlers() *Handlers {
return &Handlers{}
}
//AddProject 新建项目
func AddProject(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAPI, controller.OperationEDIT)
if e != nil {
return
}
projectName := httpRequest.PostFormValue("projectName")
if projectName == "" {
......@@ -43,10 +65,6 @@ func AddProject(httpResponse http.ResponseWriter, httpRequest *http.Request) {
//EditProject 修改项目信息
func EditProject(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAPI, controller.OperationEDIT)
if e != nil {
return
}
projectName := httpRequest.PostFormValue("projectName")
projectID := httpRequest.PostFormValue("projectID")
......@@ -87,10 +105,6 @@ func EditProject(httpResponse http.ResponseWriter, httpRequest *http.Request) {
//DeleteProject 删除项目信息
func DeleteProject(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAPI, controller.OperationEDIT)
if e != nil {
return
}
projectID := httpRequest.PostFormValue("projectID")
......@@ -122,10 +136,6 @@ func DeleteProject(httpResponse http.ResponseWriter, httpRequest *http.Request)
//BatchDeleteProject 删除项目信息
func BatchDeleteProject(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAPI, controller.OperationEDIT)
if e != nil {
return
}
projectIDList := httpRequest.PostFormValue("projectIDList")
......@@ -147,10 +157,6 @@ func BatchDeleteProject(httpResponse http.ResponseWriter, httpRequest *http.Requ
//GetProjectInfo 获取项目信息
func GetProjectInfo(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAPI, controller.OperationREAD)
if e != nil {
return
}
projectID := httpRequest.PostFormValue("projectID")
......@@ -181,10 +187,7 @@ func GetProjectInfo(httpResponse http.ResponseWriter, httpRequest *http.Request)
//GetProjectList 获取项目列表
func GetProjectList(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAPI, controller.OperationREAD)
if e != nil {
return
}
httpRequest.ParseForm()
keyword := httpRequest.FormValue("keyword")
......@@ -207,10 +210,6 @@ func GetProjectList(httpResponse http.ResponseWriter, httpRequest *http.Request)
//GetAPIListFromProjectNotInStrategy 获取项目列表中没有被策略组绑定的接口
func GetAPIListFromProjectNotInStrategy(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAPI, controller.OperationREAD)
if e != nil {
return
}
flag, result, err := project.GetAPIListFromProjectNotInStrategy()
if !flag {
......
// 控制台模块注册文件
package controller
......@@ -6,17 +6,41 @@ import (
"strconv"
"strings"
goku_handler "github.com/eolinker/goku-api-gateway/goku-handler"
"github.com/eolinker/goku-api-gateway/console/controller"
"github.com/eolinker/goku-api-gateway/console/module/api"
"github.com/eolinker/goku-api-gateway/console/module/strategy"
)
const operationAPIStrategy = "strategyManagement"
//APIStrategyHandlers 接口策略handlers
type APIStrategyHandlers struct {
}
//Handlers handlers
func (h *APIStrategyHandlers) Handlers(factory *goku_handler.AccountHandlerFactory) map[string]http.Handler {
return map[string]http.Handler{
"/add": factory.NewAccountHandleFunction(operationAPIStrategy, true, AddAPIToStrategy),
"/target": factory.NewAccountHandleFunction(operationAPIStrategy, true, ResetAPITargetOfStrategy),
"/batchEditTarget": factory.NewAccountHandleFunction(operationAPIStrategy, true, BatchResetAPITargetOfStrategy),
"/getList": factory.NewAccountHandleFunction(operationAPIStrategy, false, GetAPIListFromStrategy),
"/id/getList": factory.NewAccountHandleFunction(operationAPIStrategy, false, GetAPIIDListFromStrategy),
"/getNotInList": factory.NewAccountHandleFunction(operationAPIStrategy, false, GetAPIListNotInStrategy),
"/id/getNotInList": factory.NewAccountHandleFunction(operationAPIStrategy, false, GetAPIIDListNotInStrategyByProject),
"/batchDelete": factory.NewAccountHandleFunction(operationAPIStrategy, true, BatchDeleteAPIInStrategy),
"/plugin/getList": factory.NewAccountHandleFunction(operationAPIStrategy, false, GetAPIPluginInStrategyByAPIID),
}
}
//NewAPIStrategyHandlers new接口策略处理器
func NewAPIStrategyHandlers() *APIStrategyHandlers {
return &APIStrategyHandlers{}
}
//AddAPIToStrategy 将接口加入策略组
func AddAPIToStrategy(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationStrategy, controller.OperationEDIT)
if e != nil {
return
}
strategyID := httpRequest.PostFormValue("strategyID")
apiID := httpRequest.PostFormValue("apiID")
......@@ -49,11 +73,6 @@ func AddAPIToStrategy(httpResponse http.ResponseWriter, httpRequest *http.Reques
// ResetAPITargetOfStrategy 将接口加入策略组
func ResetAPITargetOfStrategy(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationStrategy, controller.OperationEDIT)
if e != nil {
return
}
strategyID := httpRequest.PostFormValue("strategyID")
target := httpRequest.PostFormValue("target")
apiID := httpRequest.PostFormValue("apiID")
......@@ -93,10 +112,6 @@ func ResetAPITargetOfStrategy(httpResponse http.ResponseWriter, httpRequest *htt
// BatchResetAPITargetOfStrategy 将接口加入策略组
func BatchResetAPITargetOfStrategy(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationStrategy, controller.OperationEDIT)
if e != nil {
return
}
strategyID := httpRequest.PostFormValue("strategyID")
target := httpRequest.PostFormValue("target")
......@@ -137,10 +152,6 @@ func BatchResetAPITargetOfStrategy(httpResponse http.ResponseWriter, httpRequest
// GetAPIIDListFromStrategy 获取策略组接口ID列表
func GetAPIIDListFromStrategy(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationStrategy, controller.OperationREAD)
if e != nil {
return
}
httpRequest.ParseForm()
strategyID := httpRequest.Form.Get("strategyID")
......@@ -194,10 +205,6 @@ func GetAPIIDListFromStrategy(httpResponse http.ResponseWriter, httpRequest *htt
// GetAPIListFromStrategy 获取策略组接口列表
func GetAPIListFromStrategy(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationStrategy, controller.OperationREAD)
if e != nil {
return
}
httpRequest.ParseForm()
strategyID := httpRequest.Form.Get("strategyID")
......@@ -266,10 +273,6 @@ func GetAPIListFromStrategy(httpResponse http.ResponseWriter, httpRequest *http.
//CheckIsExistAPIInStrategy 检查插件是否添加进策略组
func CheckIsExistAPIInStrategy(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationStrategy, controller.OperationEDIT)
if e != nil {
return
}
strategyID := httpRequest.PostFormValue("strategyID")
apiID := httpRequest.PostFormValue("apiID")
......@@ -301,10 +304,7 @@ func CheckIsExistAPIInStrategy(httpResponse http.ResponseWriter, httpRequest *ht
// GetAPIIDListNotInStrategyByProject 获取未被该策略组绑定的接口ID列表(通过项目)
func GetAPIIDListNotInStrategyByProject(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationStrategy, controller.OperationREAD)
if e != nil {
return
}
httpRequest.ParseForm()
strategyID := httpRequest.Form.Get("strategyID")
projectID := httpRequest.Form.Get("projectID")
......@@ -342,10 +342,7 @@ func GetAPIIDListNotInStrategyByProject(httpResponse http.ResponseWriter, httpRe
//GetAPIListNotInStrategy 获取未被该策略组绑定的接口列表
func GetAPIListNotInStrategy(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationStrategy, controller.OperationREAD)
if e != nil {
return
}
httpRequest.ParseForm()
strategyID := httpRequest.Form.Get("strategyID")
projectID := httpRequest.Form.Get("projectID")
......@@ -397,10 +394,6 @@ func GetAPIListNotInStrategy(httpResponse http.ResponseWriter, httpRequest *http
//BatchDeleteAPIInStrategy 批量删除策略组接口
func BatchDeleteAPIInStrategy(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationStrategy, controller.OperationEDIT)
if e != nil {
return
}
apiIDList := httpRequest.PostFormValue("apiIDList")
strategyID := httpRequest.PostFormValue("strategyID")
......@@ -418,3 +411,48 @@ func BatchDeleteAPIInStrategy(httpResponse http.ResponseWriter, httpRequest *htt
}
controller.WriteResultInfo(httpResponse, "apiStrategy", "", nil)
}
// GetAPIPluginInStrategyByAPIID 获取策略组中所有接口插件列表
func GetAPIPluginInStrategyByAPIID(httpResponse http.ResponseWriter, httpRequest *http.Request) {
httpRequest.ParseForm()
strategyID := httpRequest.Form.Get("strategyID")
apiID := httpRequest.Form.Get("apiID")
keyword := httpRequest.Form.Get("keyword")
condition := httpRequest.Form.Get("condition")
aID, err := strconv.Atoi(apiID)
if err != nil {
controller.WriteError(httpResponse, "240002", "apiPlugin", "[ERROR]Illegal condition!", err)
return
}
op, err := strconv.Atoi(condition)
if err != nil && condition != "" {
controller.WriteError(httpResponse, "270006", "apiPlugin", "[ERROR]Illegal condition!", err)
return
}
flag, pluginList, apiInfo, err := api.GetAPIPluginInStrategyByAPIID(strategyID, aID, keyword, op)
if !flag {
controller.WriteError(httpResponse,
"240000",
"apiPlugin",
"[ERROR]Empty api plugin list!",
err)
return
}
result := map[string]interface{}{
"statusCode": "000000",
"type": "apiPlugin",
"resultDesc": "",
"apiPluginList": pluginList,
"apiInfo": apiInfo,
"page": controller.PageInfo{
ItemNum: len(pluginList),
},
}
resultStr, _ := json.Marshal(result)
httpResponse.Write(resultStr)
// controller.WriteResultInfo(httpResponse, "apiPlugin", "apiPluginList", result)
}
......@@ -4,20 +4,47 @@ import (
"net/http"
"strconv"
goku_handler "github.com/eolinker/goku-api-gateway/goku-handler"
"github.com/eolinker/goku-api-gateway/console/controller"
"github.com/eolinker/goku-api-gateway/console/module/strategy"
entity "github.com/eolinker/goku-api-gateway/server/entity/console-entity"
)
const operationStrategy = "strategyManagement"
//Handlers 策略处理器
type Handlers struct {
}
//Handlers handlers
func (h *Handlers) Handlers(factory *goku_handler.AccountHandlerFactory) map[string]http.Handler {
return map[string]http.Handler{
"/add": factory.NewAccountHandleFunction(operationStrategy, true, AddStrategy),
"/edit": factory.NewAccountHandleFunction(operationStrategy, true, EditStrategy),
"/copy": factory.NewAccountHandleFunction(operationStrategy, true, CopyStrategy),
"/delete": factory.NewAccountHandleFunction(operationStrategy, true, DeleteStrategy),
"/getInfo": factory.NewAccountHandleFunction(operationStrategy, false, GetStrategyInfo),
"/getList": factory.NewAccountHandleFunction(operationStrategy, false, GetStrategyList),
"/batchEditGroup": factory.NewAccountHandleFunction(operationStrategy, true, BatchEditStrategyGroup),
"/batchDelete": factory.NewAccountHandleFunction(operationStrategy, true, BatchDeleteStrategy),
"/batchStart": factory.NewAccountHandleFunction(operationStrategy, true, BatchStartStrategy),
"/batchStop": factory.NewAccountHandleFunction(operationStrategy, true, BatchStopStrategy),
"/id/getList": factory.NewAccountHandleFunction(operationStrategy, false, GetStrategyIDList),
}
}
//NewStrategyHandlers new策略处理器
func NewStrategyHandlers() *Handlers {
return &Handlers{}
}
//AddStrategy 新增策略组
func AddStrategy(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationStrategy, controller.OperationEDIT)
if e != nil {
return
}
strategyName := httpRequest.PostFormValue("strategyName")
groupID := httpRequest.PostFormValue("groupID")
userID := goku_handler.UserIDFromRequest(httpRequest)
if strategyName == "" {
controller.WriteError(httpResponse,
"220006",
......@@ -37,7 +64,7 @@ func AddStrategy(httpResponse http.ResponseWriter, httpRequest *http.Request) {
return
}
flag, result, err := strategy.AddStrategy(strategyName, gID)
flag, result, err := strategy.AddStrategy(strategyName, gID, userID)
if !flag {
controller.WriteError(httpResponse,
......@@ -54,14 +81,11 @@ func AddStrategy(httpResponse http.ResponseWriter, httpRequest *http.Request) {
//EditStrategy 修改策略组信息
func EditStrategy(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationStrategy, controller.OperationEDIT)
if e != nil {
return
}
strategyName := httpRequest.PostFormValue("strategyName")
strategyID := httpRequest.PostFormValue("strategyID")
groupID := httpRequest.PostFormValue("groupID")
userID := goku_handler.UserIDFromRequest(httpRequest)
if strategyName == "" {
controller.WriteError(httpResponse,
"220006",
......@@ -80,7 +104,7 @@ func EditStrategy(httpResponse http.ResponseWriter, httpRequest *http.Request) {
return
}
flag, result, err := strategy.EditStrategy(strategyID, strategyName, gID)
flag, result, err := strategy.EditStrategy(strategyID, strategyName, gID, userID)
if !flag {
controller.WriteError(httpResponse,
"220000",
......@@ -95,10 +119,6 @@ func EditStrategy(httpResponse http.ResponseWriter, httpRequest *http.Request) {
//DeleteStrategy 删除策略组
func DeleteStrategy(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationStrategy, controller.OperationEDIT)
if e != nil {
return
}
strategyID := httpRequest.PostFormValue("strategyID")
......@@ -116,10 +136,6 @@ func DeleteStrategy(httpResponse http.ResponseWriter, httpRequest *http.Request)
// GetOpenStrategy 获取策略组列表
func GetOpenStrategy(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationStrategy, controller.OperationREAD)
if e != nil {
return
}
var flag bool
var err error
......@@ -139,14 +155,22 @@ func GetOpenStrategy(httpResponse http.ResponseWriter, httpRequest *http.Request
//GetStrategyList 获取策略组列表
func GetStrategyList(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationStrategy, controller.OperationREAD)
if e != nil {
return
}
httpRequest.ParseForm()
groupID := httpRequest.Form.Get("groupID")
keyword := httpRequest.Form.Get("keyword")
condition := httpRequest.Form.Get("condition")
page := httpRequest.Form.Get("page")
pageSize := httpRequest.Form.Get("pageSize")
p, e := strconv.Atoi(page)
if e != nil {
p = 1
}
pSize, e := strconv.Atoi(pageSize)
if e != nil {
pSize = 15
}
gID, err := strconv.Atoi(groupID)
if err != nil {
......@@ -176,7 +200,7 @@ func GetStrategyList(httpResponse http.ResponseWriter, httpRequest *http.Request
var flag bool
err = nil
result := make([]*entity.Strategy, 0)
flag, result, err = strategy.GetStrategyList(gID, keyword, op)
flag, result, count, err := strategy.GetStrategyList(gID, keyword, op, p, pSize)
if !flag {
controller.WriteError(httpResponse,
"220000",
......@@ -185,15 +209,18 @@ func GetStrategyList(httpResponse http.ResponseWriter, httpRequest *http.Request
err)
return
}
controller.WriteResultInfo(httpResponse, "strategy", "strategyList", result)
controller.WriteResultInfoWithPage(httpResponse, "strategy", "strategyList", result, &controller.PageInfo{
ItemNum: len(result),
TotalNum: count,
Page: p,
PageSize: pSize,
})
return
}
//GetStrategyIDList 获取策略组列表
func GetStrategyIDList(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationStrategy, controller.OperationREAD)
if e != nil {
return
}
httpRequest.ParseForm()
groupID := httpRequest.Form.Get("groupID")
keyword := httpRequest.Form.Get("keyword")
......@@ -238,10 +265,7 @@ func GetStrategyIDList(httpResponse http.ResponseWriter, httpRequest *http.Reque
// GetStrategyInfo 获取策略组信息
func GetStrategyInfo(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationStrategy, controller.OperationREAD)
if e != nil {
return
}
httpRequest.ParseForm()
strategyID := httpRequest.Form.Get("strategyID")
......@@ -280,10 +304,6 @@ func GetStrategyInfo(httpResponse http.ResponseWriter, httpRequest *http.Request
//BatchEditStrategyGroup 批量修改策略组分组
func BatchEditStrategyGroup(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationStrategy, controller.OperationEDIT)
if e != nil {
return
}
strategyIDList := httpRequest.PostFormValue("strategyIDList")
groupID := httpRequest.PostFormValue("groupID")
......@@ -322,10 +342,6 @@ func BatchEditStrategyGroup(httpResponse http.ResponseWriter, httpRequest *http.
//BatchDeleteStrategy 批量修改策略组
func BatchDeleteStrategy(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationStrategy, controller.OperationEDIT)
if e != nil {
return
}
strategyIDList := httpRequest.PostFormValue("strategyIDList")
if strategyIDList == "" {
......@@ -351,10 +367,6 @@ func BatchDeleteStrategy(httpResponse http.ResponseWriter, httpRequest *http.Req
//BatchStartStrategy 批量开启策略
func BatchStartStrategy(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationStrategy, controller.OperationEDIT)
if e != nil {
return
}
strategyIDList := httpRequest.PostFormValue("strategyIDList")
if strategyIDList == "" {
......@@ -380,10 +392,6 @@ func BatchStartStrategy(httpResponse http.ResponseWriter, httpRequest *http.Requ
//BatchStopStrategy 批量关闭策略
func BatchStopStrategy(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationStrategy, controller.OperationEDIT)
if e != nil {
return
}
strategyIDList := httpRequest.PostFormValue("strategyIDList")
if strategyIDList == "" {
......@@ -410,10 +418,7 @@ func BatchStopStrategy(httpResponse http.ResponseWriter, httpRequest *http.Reque
// GetBalanceListInStrategy 获取在策略中的负载列表
func GetBalanceListInStrategy(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationStrategy, controller.OperationEDIT)
if e != nil {
return
}
httpRequest.ParseForm()
strategyID := httpRequest.Form.Get("strategyID")
balanceType := httpRequest.Form.Get("balanceType")
......@@ -435,14 +440,11 @@ func GetBalanceListInStrategy(httpResponse http.ResponseWriter, httpRequest *htt
// CopyStrategy 复制策略
func CopyStrategy(httpResponse http.ResponseWriter, httpRequest *http.Request) {
userID, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationStrategy, controller.OperationEDIT)
if e != nil {
return
}
strategyName := httpRequest.PostFormValue("strategyName")
strategyID := httpRequest.PostFormValue("strategyID")
groupID := httpRequest.PostFormValue("groupID")
userID := goku_handler.UserIDFromRequest(httpRequest)
if strategyID == "" {
controller.WriteError(httpResponse,
"220003",
......@@ -469,7 +471,7 @@ func CopyStrategy(httpResponse http.ResponseWriter, httpRequest *http.Request) {
return
}
flag, result, err := strategy.AddStrategy(strategyName, gID)
flag, result, err := strategy.AddStrategy(strategyName, gID, userID)
if !flag {
controller.WriteError(httpResponse,
"220000",
......
......@@ -4,16 +4,35 @@ import (
"net/http"
"strconv"
goku_handler "github.com/eolinker/goku-api-gateway/goku-handler"
"github.com/eolinker/goku-api-gateway/console/controller"
"github.com/eolinker/goku-api-gateway/console/module/strategy"
)
const operationStrategyGroup = "strategyManagement"
//GroupHandlers 策略分组处理器
type GroupHandlers struct {
}
//Handlers handlers
func (h *GroupHandlers) Handlers(factory *goku_handler.AccountHandlerFactory) map[string]http.Handler {
return map[string]http.Handler{
"/add": factory.NewAccountHandleFunction(operationStrategyGroup, true, AddStrategyGroup),
"/edit": factory.NewAccountHandleFunction(operationStrategyGroup, true, EditStrategyGroup),
"/delete": factory.NewAccountHandleFunction(operationStrategyGroup, true, DeleteStrategyGroup),
"/getList": factory.NewAccountHandleFunction(operationStrategyGroup, false, GetStrategyGroupList),
}
}
//NewGroupHandlers new groupHandlers
func NewGroupHandlers() *GroupHandlers {
return &GroupHandlers{}
}
// AddStrategyGroup 新建接口分组
func AddStrategyGroup(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationStrategy, controller.OperationREAD)
if e != nil {
return
}
groupName := httpRequest.PostFormValue("groupName")
if groupName == "" {
......@@ -39,10 +58,6 @@ func AddStrategyGroup(httpResponse http.ResponseWriter, httpRequest *http.Reques
// EditStrategyGroup 修改接口分组
func EditStrategyGroup(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationStrategy, controller.OperationREAD)
if e != nil {
return
}
groupName := httpRequest.PostFormValue("groupName")
groupID := httpRequest.PostFormValue("groupID")
......@@ -81,10 +96,6 @@ func EditStrategyGroup(httpResponse http.ResponseWriter, httpRequest *http.Reque
// DeleteStrategyGroup 删除接口分组
func DeleteStrategyGroup(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationStrategy, controller.OperationREAD)
if e != nil {
return
}
groupID := httpRequest.PostFormValue("groupID")
......@@ -113,10 +124,6 @@ func DeleteStrategyGroup(httpResponse http.ResponseWriter, httpRequest *http.Req
// GetStrategyGroupList 获取接口分组列表
func GetStrategyGroupList(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationStrategy, controller.OperationREAD)
if e != nil {
return
}
flag, result, err := strategy.GetStrategyGroupList()
if !flag {
......
......@@ -4,18 +4,43 @@ import (
"net/http"
"strconv"
goku_handler "github.com/eolinker/goku-api-gateway/goku-handler"
"github.com/eolinker/goku-api-gateway/console/controller"
"github.com/eolinker/goku-api-gateway/console/module/plugin"
plugin_config "github.com/eolinker/goku-api-gateway/console/module/plugin/plugin-config"
"github.com/eolinker/goku-api-gateway/console/module/strategy"
)
const operationStrategyPlugin = "strategyManagement"
//PluginHandlers 策略插件处理器
type PluginHandlers struct {
}
//Handlers handlers
func (h *PluginHandlers) Handlers(factory *goku_handler.AccountHandlerFactory) map[string]http.Handler {
return map[string]http.Handler{
"/addPluginToStrategy": factory.NewAccountHandleFunction(operationAPIStrategy, true, AddPluginToStrategy),
"/edit": factory.NewAccountHandleFunction(operationAPIStrategy, true, EditStrategyPluginConfig),
"/getInfo": factory.NewAccountHandleFunction(operationAPIStrategy, false, GetStrategyPluginConfig),
"/getList": factory.NewAccountHandleFunction(operationAPIStrategy, false, GetStrategyPluginList),
"/checkPluginIsExist": factory.NewAccountHandleFunction(operationAPIStrategy, false, CheckPluginIsExistInStrategy),
"/getStatus": factory.NewAccountHandleFunction(operationAPIStrategy, false, GetStrategyPluginStatus),
"/batchStart": factory.NewAccountHandleFunction(operationAPIStrategy, false, BatchStartStrategyPlugin),
"/batchStop": factory.NewAccountHandleFunction(operationAPIStrategy, true, BatchStopStrategyPlugin),
"/batchDelete": factory.NewAccountHandleFunction(operationAPIStrategy, true, BatchDeleteStrategyPlugin),
}
}
//NewPluginHandlers new pluginHandlers
func NewPluginHandlers() *PluginHandlers {
return &PluginHandlers{}
}
//AddPluginToStrategy 新增插件到接口
func AddPluginToStrategy(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationStrategy, controller.OperationEDIT)
if e != nil {
return
}
pluginName := httpRequest.PostFormValue("pluginName")
pluginConfig := httpRequest.PostFormValue("pluginConfig")
......@@ -69,10 +94,6 @@ func AddPluginToStrategy(httpResponse http.ResponseWriter, httpRequest *http.Req
//EditStrategyPluginConfig 修改插件信息
func EditStrategyPluginConfig(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationStrategy, controller.OperationEDIT)
if e != nil {
return
}
pluginName := httpRequest.PostFormValue("pluginName")
pluginConfig := httpRequest.PostFormValue("pluginConfig")
......@@ -111,10 +132,7 @@ func EditStrategyPluginConfig(httpResponse http.ResponseWriter, httpRequest *htt
//GetStrategyPluginList 获取策略组插件列表
func GetStrategyPluginList(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationStrategy, controller.OperationREAD)
if e != nil {
return
}
httpRequest.ParseForm()
strategyID := httpRequest.Form.Get("strategyID")
keyword := httpRequest.Form.Get("keyword")
......@@ -141,10 +159,6 @@ func GetStrategyPluginList(httpResponse http.ResponseWriter, httpRequest *http.R
//GetStrategyPluginConfig 获取策略组插件信息
func GetStrategyPluginConfig(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationStrategy, controller.OperationREAD)
if e != nil {
return
}
strategyID := httpRequest.PostFormValue("strategyID")
pluginName := httpRequest.PostFormValue("pluginName")
......@@ -156,10 +170,6 @@ func GetStrategyPluginConfig(httpResponse http.ResponseWriter, httpRequest *http
//CheckPluginIsExistInStrategy 检查策略组是否绑定插件
func CheckPluginIsExistInStrategy(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationStrategy, controller.OperationREAD)
if e != nil {
return
}
strategyID := httpRequest.PostFormValue("strategyID")
pluginName := httpRequest.PostFormValue("pluginName")
......@@ -190,10 +200,6 @@ func CheckPluginIsExistInStrategy(httpResponse http.ResponseWriter, httpRequest
//GetStrategyPluginStatus 检查策略组插件是否开启
func GetStrategyPluginStatus(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationStrategy, controller.OperationREAD)
if e != nil {
return
}
strategyID := httpRequest.PostFormValue("strategyID")
pluginName := httpRequest.PostFormValue("pluginName")
......@@ -226,10 +232,6 @@ func GetStrategyPluginStatus(httpResponse http.ResponseWriter, httpRequest *http
//BatchStartStrategyPlugin 批量开启策略组插件
func BatchStartStrategyPlugin(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationStrategy, controller.OperationEDIT)
if e != nil {
return
}
strategyID := httpRequest.PostFormValue("strategyID")
connIDList := httpRequest.PostFormValue("connIDList")
......@@ -256,10 +258,6 @@ func BatchStartStrategyPlugin(httpResponse http.ResponseWriter, httpRequest *htt
//BatchStopStrategyPlugin 批量修改策略组插件状态
func BatchStopStrategyPlugin(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationStrategy, controller.OperationEDIT)
if e != nil {
return
}
strategyID := httpRequest.PostFormValue("strategyID")
connIDList := httpRequest.PostFormValue("connIDList")
......@@ -285,10 +283,6 @@ func BatchStopStrategyPlugin(httpResponse http.ResponseWriter, httpRequest *http
//BatchDeleteStrategyPlugin 批量删除策略组插件
func BatchDeleteStrategyPlugin(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationStrategy, controller.OperationEDIT)
if e != nil {
return
}
strategyID := httpRequest.PostFormValue("strategyID")
connIDList := httpRequest.PostFormValue("connIDList")
......
......@@ -2,39 +2,9 @@ package controller
import (
"encoding/json"
"errors"
log "github.com/eolinker/goku-api-gateway/goku-log"
"net/http"
"reflect"
"strconv"
log "github.com/eolinker/goku-api-gateway/goku-log"
"github.com/eolinker/goku-api-gateway/console/module/account"
)
const (
//OperationEDIT 编辑
OperationEDIT = "edit"
//OperationREAD 读取
OperationREAD = "read"
)
const (
//OperationNone 无操作
OperationNone = ""
//OperationAPI 接口操作
OperationAPI = "apiManagement"
//OperationADMIN 管理员
OperationADMIN = "adminManagement"
//OperationLoadBalance 负载操作
OperationLoadBalance = "loadBalance"
//OperationStrategy 策略操作
OperationStrategy = "strategyManagement"
//OperationNode 节点操作
OperationNode = "nodeManagement"
//OperationPlugin 插件操作
OperationPlugin = "pluginManagement"
//OperationGatewayConfig 网关配置操作
OperationGatewayConfig = "gatewayConfig"
)
//PageInfo 页码信息
......@@ -137,28 +107,3 @@ func WriteError(w http.ResponseWriter, statusCode, resultType, resultDesc string
log.WithFields(ret).Debug("write error:", err)
}
//CheckLogin 判断是否登录
func CheckLogin(w http.ResponseWriter, r *http.Request, operationType, operation string) (int, error) {
userIDCookie, idErr := r.Cookie("userID")
userCookie, userErr := r.Cookie("userToken")
if idErr != nil || userErr != nil {
e := errors.New("user not logged in")
WriteError(w, "100001", "user", e.Error(), e)
return 0, e
}
userID, err := strconv.Atoi(userIDCookie.Value)
if err != nil {
WriteError(w, "100001", "user", "Illegal user id!", err)
return 0, err
}
flag := account.CheckLogin(userCookie.Value, userID)
if !flag {
e := errors.New("illegal users")
WriteError(w, "100001", "user", "Illegal users!", e)
return userID, e
}
return userID, nil
}
package account
import (
console_sqlite3 "github.com/eolinker/goku-api-gateway/server/dao/console-sqlite3"
"github.com/eolinker/goku-api-gateway/common/pdao"
"github.com/eolinker/goku-api-gateway/server/dao"
)
var(
guestDao dao.GuestDao
userDao dao.UserDao
)
func init() {
pdao.Need(&guestDao,&userDao)
}
//Login 登录
func Login(loginCall, loginPassword string) (bool, int) {
return console_sqlite3.Login(loginCall, loginPassword)
func Login(loginCall, loginPassword string) (bool, int) {
return guestDao.Login(loginCall, loginPassword)
}
//CheckLogin 检查用户是否登录
func CheckLogin(userToken string, userID int) bool {
return console_sqlite3.CheckLogin(userToken, userID)
func CheckLogin(userToken string, userID int) bool {
return guestDao.CheckLogin(userToken, userID)
}
//Register 用户注册
func Register(loginCall, loginPassword string) bool {
return console_sqlite3.Register(loginCall, loginPassword)
func Register(loginCall, loginPassword string) bool {
return guestDao.Register(loginCall, loginPassword)
}
//CheckSuperAdminCount 获取超级管理员数量
func CheckSuperAdminCount() (int, error) {
b, err := console_sqlite3.CheckSuperAdminCount()
func CheckSuperAdminCount() (int, error) {
b, err := userDao.CheckSuperAdminCount()
return b, err
}
package account
import (
console_sqlite3 "github.com/eolinker/goku-api-gateway/server/dao/console-sqlite3"
)
//GetUserListWithPermission 获取具有编辑权限的用户列表
func GetUserListWithPermission(operationType, operation string) (bool, []map[string]interface{}, error) {
return console_sqlite3.GetUserListWithPermission(operationType, operation)
}
//EditPassword 修改账户信息
func EditPassword(oldPassword, newPassword string, userID int) (bool, string, error) {
return console_sqlite3.EditPassword(oldPassword, newPassword, userID)
return userDao.EditPassword(oldPassword, newPassword, userID)
}
//GetUserInfo 获取账户信息
func GetUserInfo(userID int) (bool, interface{}, error) {
return console_sqlite3.GetUserInfo(userID)
return userDao.GetUserInfo(userID)
}
//GetUserType 获取用户类型
func GetUserType(userID int) (bool, interface{}, error) {
return console_sqlite3.GetUserType(userID)
return userDao.GetUserType(userID)
}
//CheckUserIsAdmin 判断是否是管理员
func CheckUserIsAdmin(userID int) (bool, string, error) {
return console_sqlite3.CheckUserIsAdmin(userID)
return userDao.CheckUserIsAdmin(userID)
}
//CheckUserIsSuperAdmin 判断是否是超级管理员
func CheckUserIsSuperAdmin(userID int) (bool, string, error) {
return console_sqlite3.CheckUserIsSuperAdmin(userID)
}
//CheckUserPermission 检查用户权限
func CheckUserPermission(operationType, operation string, userID int) (bool, string, error) {
return console_sqlite3.CheckUserPermission(operationType, operation, userID)
return userDao.CheckUserIsSuperAdmin(userID)
}
package api
import (
console_sqlite3 "github.com/eolinker/goku-api-gateway/server/dao/console-sqlite3"
entity "github.com/eolinker/goku-api-gateway/server/entity/console-entity"
)
//AddAPI 新增接口
func AddAPI(apiName, requestURL, targetURL, requestMethod, targetMethod, isFollow, linkApis, staticResponse, responseDataType, balanceName, protocol string, projectID, groupID, timeout, retryCount, alertValve, managerID, userID, apiType int) (bool, int, error) {
func AddAPI(apiName, alias, requestURL, targetURL, requestMethod, targetMethod, isFollow, linkApis, staticResponse, responseDataType, balanceName, protocol string, projectID, groupID, timeout, retryCount, alertValve, managerID, userID, apiType int) (bool, int, error) {
flag, result, err := console_sqlite3.AddAPI(apiName, requestURL, targetURL, requestMethod, targetMethod, isFollow, linkApis, staticResponse, responseDataType, balanceName, protocol, projectID, groupID, timeout, retryCount, alertValve, managerID, userID, apiType)
flag, result, err := apiDao.AddAPI(apiName, alias, requestURL, targetURL, requestMethod, targetMethod, isFollow, linkApis, staticResponse, responseDataType, balanceName, protocol, projectID, groupID, timeout, retryCount, alertValve, managerID, userID, apiType)
return flag, result, err
}
//EditAPI 新增接口
func EditAPI(apiName, requestURL, targetURL, requestMethod, targetMethod, isFollow, linkApis, staticResponse, responseDataType, balanceName, protocol string, projectID, groupID, timeout, retryCount, alertValve, apiID, managerID, userID int) (bool, error) {
flag, err := console_sqlite3.EditAPI(apiName, requestURL, targetURL, requestMethod, targetMethod, isFollow, linkApis, staticResponse, responseDataType, balanceName, protocol, projectID, groupID, timeout, retryCount, alertValve, apiID, managerID, userID)
func EditAPI(apiName, alias, requestURL, targetURL, requestMethod, targetMethod, isFollow, linkApis, staticResponse, responseDataType, balanceName, protocol string, projectID, groupID, timeout, retryCount, alertValve, apiID, managerID, userID int) (bool, error) {
flag, err := apiDao.EditAPI(apiName, alias, requestURL, targetURL, requestMethod, targetMethod, isFollow, linkApis, staticResponse, responseDataType, balanceName, protocol, projectID, groupID, timeout, retryCount, alertValve, apiID, managerID, userID)
return flag, err
}
//GetAPIInfo 获取接口信息
func GetAPIInfo(apiID int) (bool, *entity.API, error) {
return console_sqlite3.GetAPIInfo(apiID)
return apiDao.GetAPIInfo(apiID)
}
// GetAPIIDList 获取接口ID列表
func GetAPIIDList(projectID int, groupID int, keyword string, condition int, ids []int) (bool, []int, error) {
return console_sqlite3.GetAPIIDList(projectID, groupID, keyword, condition, ids)
return apiDao.GetAPIIDList(projectID, groupID, keyword, condition, ids)
}
// GetAPIList 获取接口列表
func GetAPIList(projectID int, groupID int, keyword string, condition, page, pageSize int, ids []int) (bool, []map[string]interface{}, int, error) {
return console_sqlite3.GetAPIList(projectID, groupID, keyword, condition, page, pageSize, ids)
return apiDao.GetAPIList(projectID, groupID, keyword, condition, page, pageSize, ids)
}
//CheckURLIsExist 接口路径是否存在
func CheckURLIsExist(requestURL, requestMethod string, projectID, apiID int) bool {
return console_sqlite3.CheckURLIsExist(requestURL, requestMethod, projectID, apiID)
return apiDao.CheckURLIsExist(requestURL, requestMethod, projectID, apiID)
}
//CheckAPIIsExist 检查接口是否存在
func CheckAPIIsExist(apiID int) (bool, error) {
return console_sqlite3.CheckAPIIsExist(apiID)
return apiDao.CheckAPIIsExist(apiID)
}
//CheckAliasIsExist 检查接口是否存在
func CheckAliasIsExist(apiID int, alias string) bool {
return apiDao.CheckAliasIsExist(apiID, alias)
}
//BatchEditAPIGroup 批量修改接口分组
func BatchEditAPIGroup(apiIDList []string, groupID int) (bool, string, error) {
r, e := console_sqlite3.BatchEditAPIGroup(apiIDList, groupID)
r, e := apiDao.BatchEditAPIGroup(apiIDList, groupID)
return e == nil, r, e
}
......@@ -55,7 +59,7 @@ func BatchEditAPIGroup(apiIDList []string, groupID int) (bool, string, error) {
//BatchEditAPIBalance 批量修改接口负载
func BatchEditAPIBalance(apiIDList []string, balance string) (string, error) {
r, err := console_sqlite3.BatchEditAPIBalance(apiIDList, balance)
r, err := apiDao.BatchEditAPIBalance(apiIDList, balance)
return r, err
}
......@@ -63,7 +67,7 @@ func BatchEditAPIBalance(apiIDList []string, balance string) (string, error) {
//BatchDeleteAPI 批量删除接口
func BatchDeleteAPI(apiIDList string) (bool, string, error) {
flag, result, err := console_sqlite3.BatchDeleteAPI(apiIDList)
flag, result, err := apiDao.BatchDeleteAPI(apiIDList)
return flag, result, err
}
package api
import (
console_sqlite3 "github.com/eolinker/goku-api-gateway/server/dao/console-sqlite3"
)
//AddAPIGroup 新建接口分组
func AddAPIGroup(groupName string, projectID, parentGroupID int) (bool, interface{}, error) {
return console_sqlite3.AddAPIGroup(groupName, projectID, parentGroupID)
return apiGroupDao.AddAPIGroup(groupName, projectID, parentGroupID)
}
//EditAPIGroup 修改接口分组
func EditAPIGroup(groupName string, groupID, projectID int) (bool, string, error) {
return console_sqlite3.EditAPIGroup(groupName, groupID, projectID)
return apiGroupDao.EditAPIGroup(groupName, groupID, projectID)
}
//DeleteAPIGroup 删除接口分组
func DeleteAPIGroup(projectID, groupID int) (bool, string, error) {
flag, result, err := console_sqlite3.DeleteAPIGroup(projectID, groupID)
flag, result, err := apiGroupDao.DeleteAPIGroup(projectID, groupID)
return flag, result, err
}
//GetAPIGroupList 获取接口分组列表
func GetAPIGroupList(projectID int) (bool, []map[string]interface{}, error) {
return console_sqlite3.GetAPIGroupList(projectID)
return apiGroupDao.GetAPIGroupList(projectID)
}
package api
import (
console_sqlite3 "github.com/eolinker/goku-api-gateway/server/dao/console-sqlite3"
)
//BatchEditAPIPluginStatus BatchEditAPIPluginStatus批量修改接口插件状态
func BatchEditAPIPluginStatus(connIDList, strategyID string, pluginStatus, userID int) (bool, string, error) {
flag, result, err := console_sqlite3.BatchEditAPIPluginStatus(connIDList, strategyID, pluginStatus, userID)
flag, result, err := apiPluginDao.BatchEditAPIPluginStatus(connIDList, strategyID, pluginStatus, userID)
return flag, result, err
}
//BatchDeleteAPIPlugin 批量删除接口插件
func BatchDeleteAPIPlugin(connIDList, strategyID string) (bool, string, error) {
flag, result, err := console_sqlite3.BatchDeleteAPIPlugin(connIDList, strategyID)
flag, result, err := apiPluginDao.BatchDeleteAPIPlugin(connIDList, strategyID)
return flag, result, err
}
//AddPluginToAPI 新增插件到接口
func AddPluginToAPI(pluginName, config, strategyID string, apiID, userID int) (bool, interface{}, error) {
flag, result, err := console_sqlite3.AddPluginToAPI(pluginName, config, strategyID, apiID, userID)
flag, result, err := apiPluginDao.AddPluginToAPI(pluginName, config, strategyID, apiID, userID)
return flag, result, err
}
//EditAPIPluginConfig 修改接口插件配置
func EditAPIPluginConfig(pluginName, config, strategyID string, apiID, userID int) (bool, interface{}, error) {
flag, result, err := console_sqlite3.EditAPIPluginConfig(pluginName, config, strategyID, apiID, userID)
flag, result, err := apiPluginDao.EditAPIPluginConfig(pluginName, config, strategyID, apiID, userID)
return flag, result, err
}
//GetAPIPluginList 获取接口插件列表
func GetAPIPluginList(apiID int, strategyID string) (bool, []map[string]interface{}, error) {
return console_sqlite3.GetAPIPluginList(apiID, strategyID)
return apiPluginDao.GetAPIPluginList(apiID, strategyID)
}
//GetPluginIndex 获取插件优先级
func GetPluginIndex(pluginName string) (bool, int, error) {
return console_sqlite3.GetPluginIndex(pluginName)
return apiPluginDao.GetPluginIndex(pluginName)
}
//GetAPIPluginConfig 通过ApiID获取配置信息
func GetAPIPluginConfig(apiID int, strategyID, pluginName string) (bool, map[string]string, error) {
return console_sqlite3.GetAPIPluginConfig(apiID, strategyID, pluginName)
return apiPluginDao.GetAPIPluginConfig(apiID, strategyID, pluginName)
}
//CheckPluginIsExistInAPI 检查策略组是否绑定插件
func CheckPluginIsExistInAPI(strategyID, pluginName string, apiID int) (bool, error) {
return console_sqlite3.CheckPluginIsExistInAPI(strategyID, pluginName, apiID)
return apiPluginDao.CheckPluginIsExistInAPI(strategyID, pluginName, apiID)
}
//GetAllAPIPluginInStrategy 获取策略组中所有接口插件列表
func GetAllAPIPluginInStrategy(strategyID string) (bool, []map[string]interface{}, error) {
return console_sqlite3.GetAllAPIPluginInStrategy(strategyID)
return apiPluginDao.GetAllAPIPluginInStrategy(strategyID)
}
// GetAPIPluginInStrategyByAPIID 获取策略组中所有接口插件列表
func GetAPIPluginInStrategyByAPIID(strategyID string, apiID int, keyword string, condition int) (bool, []map[string]interface{}, map[string]interface{}, error) {
return console_sqlite3.GetAPIPluginInStrategyByAPIID(strategyID, apiID, keyword, condition)
return apiPluginDao.GetAPIPluginInStrategyByAPIID(strategyID, apiID, keyword, condition)
}
//GetAPIPluginListWithNotAssignAPIList 获取没有绑定插件得接口列表
func GetAPIPluginListWithNotAssignAPIList(strategyID string) (bool, []map[string]interface{}, error) {
return console_sqlite3.GetAPIPluginListWithNotAssignAPIList(strategyID)
return apiPluginDao.GetAPIPluginListWithNotAssignAPIList(strategyID)
}
package api
import (
console_sqlite3 "github.com/eolinker/goku-api-gateway/server/dao/console-sqlite3"
)
//AddAPIToStrategy 将接口加入策略组
func AddAPIToStrategy(apiList []string, strategyID string) (bool, string, error) {
flag, result, err := console_sqlite3.AddAPIToStrategy(apiList, strategyID)
flag, result, err := apiStrategyDao.AddAPIToStrategy(apiList, strategyID)
return flag, result, err
}
//SetTarget 重置目标地址
func SetTarget(apiID int, strategyID string, target string) (bool, string, error) {
flag, result, err := console_sqlite3.SetAPITargetOfStrategy(apiID, strategyID, target)
flag, result, err := apiStrategyDao.SetAPITargetOfStrategy(apiID, strategyID, target)
return flag, result, err
}
// BatchSetTarget 批量重置目标地址
func BatchSetTarget(apiIds []int, strategyID string, target string) (bool, string, error) {
flag, result, err := console_sqlite3.BatchSetAPITargetOfStrategy(apiIds, strategyID, target)
flag, result, err := apiStrategyDao.BatchSetAPITargetOfStrategy(apiIds, strategyID, target)
return flag, result, err
}
// GetAPIIDListFromStrategy 获取策略组接口ID列表
func GetAPIIDListFromStrategy(strategyID, keyword string, condition int, ids []int, balanceNames []string) (bool, []int, error) {
return console_sqlite3.GetAPIIDListFromStrategy(strategyID, keyword, condition, ids, balanceNames)
return apiStrategyDao.GetAPIIDListFromStrategy(strategyID, keyword, condition, ids, balanceNames)
}
// GetAPIListFromStrategy 获取策略组接口列表
func GetAPIListFromStrategy(strategyID, keyword string, condition, page, pageSize int, ids []int, balanceNames []string) (bool, []map[string]interface{}, int, error) {
return console_sqlite3.GetAPIListFromStrategy(strategyID, keyword, condition, page, pageSize, ids, balanceNames)
return apiStrategyDao.GetAPIListFromStrategy(strategyID, keyword, condition, page, pageSize, ids, balanceNames)
}
//CheckIsExistAPIInStrategy 检查插件是否添加进策略组
func CheckIsExistAPIInStrategy(apiID int, strategyID string) (bool, string, error) {
return console_sqlite3.CheckIsExistAPIInStrategy(apiID, strategyID)
return apiStrategyDao.CheckIsExistAPIInStrategy(apiID, strategyID)
}
// GetAPIIDListNotInStrategy 获取未被该策略组绑定的接口ID列表(通过项目)
func GetAPIIDListNotInStrategy(strategyID string, projectID, groupID int, keyword string) (bool, []int, error) {
return console_sqlite3.GetAPIIDListNotInStrategy(strategyID, projectID, groupID, keyword)
return apiStrategyDao.GetAPIIDListNotInStrategy(strategyID, projectID, groupID, keyword)
}
// GetAPIListNotInStrategy 获取未被该策略组绑定的接口列表(通过项目)
func GetAPIListNotInStrategy(strategyID string, projectID, groupID, page, pageSize int, keyword string) (bool, []map[string]interface{}, int, error) {
return console_sqlite3.GetAPIListNotInStrategy(strategyID, projectID, groupID, page, pageSize, keyword)
return apiStrategyDao.GetAPIListNotInStrategy(strategyID, projectID, groupID, page, pageSize, keyword)
}
//BatchDeleteAPIInStrategy 批量删除策略组接口
func BatchDeleteAPIInStrategy(apiIDList, strategyID string) (bool, string, error) {
flag, result, err := console_sqlite3.BatchDeleteAPIInStrategy(apiIDList, strategyID)
flag, result, err := apiStrategyDao.BatchDeleteAPIInStrategy(apiIDList, strategyID)
return flag, result, err
}
package api
import (
"github.com/eolinker/goku-api-gateway/common/pdao"
"github.com/eolinker/goku-api-gateway/server/dao"
)
var(
apiDao dao.APIDao
apiGroupDao dao.APIGroupDao
apiPluginDao dao.APIPluginDao
apiStrategyDao dao.APIStrategyDao
importDao dao.ImportDao
)
func init() {
pdao.Need(&apiDao,&apiGroupDao,&apiPluginDao,&apiStrategyDao,&importDao)
}
\ No newline at end of file
package api
import (
console_sqlite3 "github.com/eolinker/goku-api-gateway/server/dao/console-sqlite3"
entity "github.com/eolinker/goku-api-gateway/server/entity/console-entity"
)
//ImportAPIGroupFromAms 导入接口分组
func ImportAPIGroupFromAms(projectID, userID int, groupInfo entity.AmsGroupInfo) (bool, string, error) {
flag, result, err := console_sqlite3.ImportAPIGroupFromAms(projectID, userID, groupInfo)
flag, result, err := importDao.ImportAPIGroupFromAms(projectID, userID, groupInfo)
return flag, result, err
}
//ImportProjectFromAms 导入项目
func ImportProjectFromAms(userID int, projectInfo entity.AmsProject) (bool, string, error) {
flag, result, err := console_sqlite3.ImportProjectFromAms(userID, projectInfo)
flag, result, err := importDao.ImportProjectFromAms(userID, projectInfo)
return flag, result, err
}
//ImportAPIFromAms 导入接口
func ImportAPIFromAms(projectID, groupID, userID int, apiList []entity.AmsAPIInfo) (bool, string, error) {
flag, result, err := console_sqlite3.ImportAPIFromAms(projectID, groupID, userID, apiList)
flag, result, err := importDao.ImportAPIFromAms(projectID, groupID, userID, apiList)
return flag, result, err
}
package auth
import (
console_sqlite3 "github.com/eolinker/goku-api-gateway/server/dao/console-sqlite3"
"github.com/eolinker/goku-api-gateway/common/pdao"
"github.com/eolinker/goku-api-gateway/server/dao"
)
var (
authDao dao.AuthDao
)
func init() {
pdao.Need(&authDao)
}
//GetAuthStatus 获取认证状态
func GetAuthStatus(strategyID string) (bool, map[string]interface{}, error) {
return console_sqlite3.GetAuthStatus(strategyID)
return authDao.GetAuthStatus(strategyID)
}
//GetAuthInfo 获取认证信息
func GetAuthInfo(strategyID string) (bool, map[string]interface{}, error) {
return console_sqlite3.GetAuthInfo(strategyID)
return authDao.GetAuthInfo(strategyID)
}
//EditAuthInfo 编辑认证信息
func EditAuthInfo(strategyID, strategyName, basicAuthList, apikeyList, jwtCredentialList, oauth2CredentialList string, delClientIDList []string) (bool, error) {
flag, err := console_sqlite3.EditAuthInfo(strategyID, strategyName, basicAuthList, apikeyList,
flag, err := authDao.EditAuthInfo(strategyID, strategyName, basicAuthList, apikeyList,
jwtCredentialList, oauth2CredentialList, delClientIDList)
return flag, err
......
......@@ -5,14 +5,12 @@ import (
"fmt"
"time"
dao_balance "github.com/eolinker/goku-api-gateway/server/dao/console-sqlite3/dao-balance"
"github.com/eolinker/goku-api-gateway/console/module/service"
driver2 "github.com/eolinker/goku-api-gateway/server/driver"
entity "github.com/eolinker/goku-api-gateway/server/entity/balance-entity-service"
)
//Add 新增负载
//RegisterDao 新增负载
func Add(info *Param) (string, error) {
serviceInfo, err := service.Get(info.ServiceName)
if err != nil {
......@@ -25,7 +23,7 @@ func Add(info *Param) (string, error) {
return "param:static 和 staticCluster 不能同时为空", errors.New("param:static 和 staticCluster 不能同时为空")
}
now := time.Now().Format("2006-01-02 15:04:05")
result, err := dao_balance.AddStatic(info.Name, info.ServiceName, info.Static, info.StaticCluster, info.Desc, now)
result, err := balanceDao.AddStatic(info.Name, info.ServiceName, info.Static, info.StaticCluster, info.Desc, now)
return result, err
}
......@@ -35,7 +33,7 @@ func Add(info *Param) (string, error) {
return "param:appName 不能为空", errors.New("param:appName 不能为空")
}
now := time.Now().Format("2006-01-02 15:04:05")
result, err := dao_balance.AddDiscovery(info.Name, info.ServiceName, info.AppName, info.Desc, now)
result, err := balanceDao.AddDiscovery(info.Name, info.ServiceName, info.AppName, info.Desc, now)
return result, err
}
......@@ -58,7 +56,7 @@ func Save(info *Param) (string, error) {
return "param:static 和 staticCluster 不能同时为空", errors.New("param:static 和 staticCluster 不能同时为空")
}
now := time.Now().Format("2006-01-02 15:04:05")
result, err := dao_balance.SaveStatic(info.Name, info.ServiceName, info.Static, info.StaticCluster, info.Desc, now)
result, err := balanceDao.SaveStatic(info.Name, info.ServiceName, info.Static, info.StaticCluster, info.Desc, now)
return result, err
}
......@@ -68,7 +66,7 @@ func Save(info *Param) (string, error) {
return "param:appName 不能为空", errors.New("param:appName 不能为空")
}
now := time.Now().Format("2006-01-02 15:04:05")
result, err := dao_balance.SaveDiscover(info.Name, info.ServiceName, info.AppName, info.Desc, now)
result, err := balanceDao.SaveDiscover(info.Name, info.ServiceName, info.AppName, info.Desc, now)
return result, err
}
......@@ -80,7 +78,7 @@ func Save(info *Param) (string, error) {
//Get 通过负载名称获取负载信息
func Get(name string) (*Info, error) {
b, e := dao_balance.Get(name)
b, e := balanceDao.Get(name)
if e != nil {
return nil, e
}
......@@ -92,13 +90,13 @@ func Get(name string) (*Info, error) {
func Search(keyworkd string) ([]*Info, error) {
var entities []*entity.Balance
if keyworkd == "" {
es, e := dao_balance.GetAll()
es, e := balanceDao.GetAll()
if e != nil {
return nil, e
}
entities = es
} else {
es, e := dao_balance.Search(keyworkd)
es, e := balanceDao.Search(keyworkd)
if e != nil {
return nil, e
}
......@@ -107,7 +105,13 @@ func Search(keyworkd string) ([]*Info, error) {
infos := make([]*Info, 0, len(entities))
useBalances, _ := balanceDao.GetUseBalanceNames()
for _, ent := range entities {
if useBalances != nil {
if _, ok := useBalances[ent.Name]; ok {
ent.CanDelete = 0
}
}
infos = append(infos, ReadInfo(ent))
}
return infos, nil
......@@ -116,13 +120,18 @@ func Search(keyworkd string) ([]*Info, error) {
//GetAll 获取所有负载列表
func GetAll() ([]*Info, error) {
entities, e := dao_balance.GetAll()
entities, e := balanceDao.GetAll()
if e != nil {
return nil, e
}
infos := make([]*Info, 0, len(entities))
useBalances, _ := balanceDao.GetUseBalanceNames()
for _, ent := range entities {
if useBalances != nil {
if _, ok := useBalances[ent.Name]; ok {
ent.CanDelete = 0
}
}
infos = append(infos, ReadInfo(ent))
}
return infos, nil
......@@ -130,19 +139,19 @@ func GetAll() ([]*Info, error) {
//Delete 删除负载
func Delete(name string) (string, error) {
result, err := dao_balance.Delete(name)
result, err := balanceDao.Delete(name)
return result, err
}
//GetBalancNames 获取负载名称列表
func GetBalancNames() (bool, []string, error) {
return dao_balance.GetBalanceNames()
return balanceDao.GetBalanceNames()
}
//BatchDeleteBalance 批量删除负载
func BatchDeleteBalance(balanceNames []string) (string, error) {
result, err := dao_balance.BatchDelete(balanceNames)
result, err := balanceDao.BatchDelete(balanceNames)
return result, err
}
......@@ -28,6 +28,7 @@ type Info struct {
Desc string `json:"balanceDesc"`
CreateTime string `json:"createTime"`
UpdateTime string `json:"updateTime"`
CanDelete int `json:"canDelete"`
}
//ReadInfo 读取负载信息
......@@ -43,6 +44,7 @@ func ReadInfo(balance *entity.Balance) *Info {
Desc: balance.Desc,
CreateTime: balance.CreateTime,
UpdateTime: balance.UpdateTime,
CanDelete: balance.CanDelete,
}
json.Unmarshal([]byte(balance.StaticCluster), &info.StaticCluster)
return info
......
......@@ -2,25 +2,30 @@ package balance
import (
"encoding/json"
"github.com/eolinker/goku-api-gateway/common/pdao"
"github.com/eolinker/goku-api-gateway/server/dao"
"github.com/eolinker/goku-api-gateway/common/general"
dao_balance_update2 "github.com/eolinker/goku-api-gateway/server/dao/console-sqlite3/dao-balance-update"
entity "github.com/eolinker/goku-api-gateway/server/entity/balance-entity"
)
var (
balanceDao dao.BalanceDao
balanceUpdateDao dao.BalanceUpdateDao
)
func init() {
pdao.Need(&balanceDao,&balanceUpdateDao)
general.RegeditLater(Update)
}
//Update 将旧负载配置更新为新负载配置
func Update() error {
l, e := dao_balance_update2.GetAllOldVerSion()
l, e := balanceUpdateDao.GetAllOldVerSion()
if e != nil {
return e
}
defStaticServiceName := dao_balance_update2.GetDefaultServiceStatic()
defStaticServiceName := balanceUpdateDao.GetDefaultServiceStatic()
for _, e := range l {
update(e, defStaticServiceName)
}
......
package cluster
import (
console_sqlite3 "github.com/eolinker/goku-api-gateway/server/dao/console-sqlite3"
"github.com/eolinker/goku-api-gateway/common/pdao"
"github.com/eolinker/goku-api-gateway/server/dao"
entity "github.com/eolinker/goku-api-gateway/server/entity/console-entity"
)
var (
clusterDao dao.ClusterDao
)
func init() {
pdao.Need(&clusterDao)
}
//AddCluster 新增集群
func AddCluster(name, title, note string) error {
return console_sqlite3.AddCluster(name, title, note)
return clusterDao.AddCluster(name, title, note)
}
//EditCluster 修改集群信息
func EditCluster(name, title, note string) error {
return console_sqlite3.EditCluster(name, title, note)
return clusterDao.EditCluster(name, title, note)
}
//DeleteCluster 删除集群
func DeleteCluster(name string) error {
return console_sqlite3.DeleteCluster(name)
return clusterDao.DeleteCluster(name)
}
//GetClusters 获取集群列表
func GetClusters() ([]*entity.Cluster, error) {
return console_sqlite3.GetClusters()
return clusterDao.GetClusters()
}
//GetCluster 获取集群信息
func GetCluster(name string) (*entity.Cluster, error) {
return console_sqlite3.GetCluster(name)
return clusterDao.GetCluster(name)
}
//GetClusterNodeCount 获取集群节点数量
func GetClusterNodeCount(name string) int {
return console_sqlite3.GetClusterNodeCount(name)
return clusterDao.GetClusterNodeCount(name)
}
//CheckClusterNameIsExist 判断集群名称是否存在
func CheckClusterNameIsExist(name string) bool {
return console_sqlite3.CheckClusterNameIsExist(name)
return clusterDao.CheckClusterNameIsExist(name)
}
//GetClusterIDByName 获取集群节点数量
func GetClusterIDByName(name string) int {
return console_sqlite3.GetClusterIDByName(name)
return clusterDao.GetClusterIDByName(name)
}
package config_log
import (
"github.com/eolinker/goku-api-gateway/common/pdao"
"github.com/eolinker/goku-api-gateway/server/dao"
)
var (
configLogDao dao.ConfigLogDao
)
func init() {
pdao.Need(&configLogDao)
}
\ No newline at end of file
......@@ -5,7 +5,6 @@ import (
"github.com/eolinker/goku-api-gateway/common/auto-form"
log "github.com/eolinker/goku-api-gateway/goku-log"
config_log "github.com/eolinker/goku-api-gateway/server/dao/console-sqlite3/config-log"
)
//Get 获取普通日志配置
......@@ -18,7 +17,7 @@ func Get(name string) (*LogConfig, error) {
c.Levels = Levels
c.Periods = Periods
c.Expires = Expires
config, e := config_log.Get(name)
config, e := configLogDao.Get(name)
if e != nil || config == nil {
auto.SetDefaults(c)
......@@ -36,7 +35,7 @@ func Get(name string) (*LogConfig, error) {
//GetAccess 获取access配置
func GetAccess() (*AccessConfig, error) {
config, e := config_log.Get(AccessLog)
config, e := configLogDao.Get(AccessLog)
c := new(AccessConfig)
c.Periods = Periods
c.Expires = Expires
......
......@@ -4,7 +4,6 @@ import (
"fmt"
log "github.com/eolinker/goku-api-gateway/goku-log"
config_log "github.com/eolinker/goku-api-gateway/server/dao/console-sqlite3/config-log"
entity "github.com/eolinker/goku-api-gateway/server/entity/config-log"
)
......@@ -27,7 +26,7 @@ func Set(name string, param *Param) error {
}
c.Fields = param.Fields
c.Expire = param.Expire
err := config_log.Set(c)
err := configLogDao.Set(c)
if err != nil {
return err
}
......
package gateway
import (
"github.com/eolinker/goku-api-gateway/common/pdao"
v "github.com/eolinker/goku-api-gateway/common/version"
console_sqlite3 "github.com/eolinker/goku-api-gateway/server/dao/console-sqlite3"
"github.com/eolinker/goku-api-gateway/server/dao"
entity "github.com/eolinker/goku-api-gateway/server/entity/console-entity"
)
var (
gatewayDao dao.GatewayDao
pluginDao dao.PluginDao
clusterDao dao.ClusterDao
)
func init() {
pdao.Need(&gatewayDao, &pluginDao, &clusterDao)
}
//BaseGatewayInfo 网关基本配置
type BaseGatewayInfo struct {
NodeCount int `json:"nodeCount"`
......@@ -25,37 +37,36 @@ type SystemInfo struct {
//GetGatewayConfig 获取网关配置
func GetGatewayConfig() (map[string]interface{}, error) {
return console_sqlite3.GetGatewayConfig()
return gatewayDao.GetGatewayConfig()
}
//EditGatewayBaseConfig 编辑网关基本配置
func EditGatewayBaseConfig(successCode string, nodeUpdatePeriod, monitorUpdatePeriod, timeout int) (bool, string, error) {
flag, result, err := console_sqlite3.EditGatewayBaseConfig(successCode, nodeUpdatePeriod, monitorUpdatePeriod, timeout)
return flag, result, err
}
//EditGatewayAlarmConfig 编辑网关告警配置
func EditGatewayAlarmConfig(apiAlertInfo, sender, senderPassword, smtpAddress string, alertStatus, smtpPort, smtpProtocol int) (bool, string, error) {
flag, result, err := console_sqlite3.EditGatewayAlarmConfig(apiAlertInfo, sender, senderPassword, smtpAddress, alertStatus, smtpPort, smtpProtocol)
config := entity.GatewayBasicConfig{
SuccessCode: successCode,
NodeUpdatePeriod: nodeUpdatePeriod,
MonitorUpdatePeriod: monitorUpdatePeriod,
MonitorTimeout: timeout,
}
flag, result, err := gatewayDao.EditGatewayBaseConfig(config)
return flag, result, err
}
//GetGatewayMonitorSummaryByPeriod 获取监控summary
func GetGatewayMonitorSummaryByPeriod() (bool, *SystemInfo, error) {
nodeStartCount, nodeStopCount, projectCount, apiCount, strategyCount, e := console_sqlite3.GetGatewayInfo()
nodeStartCount, nodeStopCount, projectCount, apiCount, strategyCount, e := gatewayDao.GetGatewayInfo()
if e != nil {
return false, nil, e
}
info := new(SystemInfo)
info.BaseInfo.PluginCount = console_sqlite3.GetPluginCount()
info.BaseInfo.PluginCount = pluginDao.GetPluginCount()
info.BaseInfo.NodeCount = nodeStartCount + nodeStopCount
info.BaseInfo.ProjectCount = projectCount
info.BaseInfo.APICount = apiCount
info.BaseInfo.StrategyCount = strategyCount
info.BaseInfo.Version = v.Version
info.BaseInfo.ClusterCount = console_sqlite3.GetClusterCount()
info.BaseInfo.ClusterCount = clusterDao.GetClusterCount()
return true, info, nil
......
package monitor
import (
"github.com/eolinker/goku-api-gateway/common/general"
"github.com/eolinker/goku-api-gateway/common/pdao"
"github.com/eolinker/goku-api-gateway/ksitigarbha"
console_sqlite3 "github.com/eolinker/goku-api-gateway/server/dao/console-sqlite3"
"github.com/eolinker/goku-api-gateway/server/dao"
"github.com/pkg/errors"
)
var(
monitorModuleDao dao.MonitorModulesDao
)
func init() {
pdao.Need(&monitorModuleDao)
general.RegeditLater(InitModuleStatus)
}
type MonitorModule struct {
Name string `json:"moduleName"`
......@@ -14,31 +23,54 @@ type MonitorModule struct {
Desc string `json:"moduleDesc"`
Models interface{} `json:"layer"`
}
// 初始化监控模块的配置状态
func InitModuleStatus() error {
modules, err := monitorModuleDao.GetMonitorModules()
if err != nil {
return err
}
names := ksitigarbha.GetMonitorModuleNames()
for _, name := range names {
if m,has:= modules[name];has{
if m.ModuleStatus == 1{
ksitigarbha.Open(name,m.Config)
}else{
ksitigarbha.Close(name)
}
}else{
ksitigarbha.Close(name)
}
}
return nil
}
//GetMonitorModules 获取监控模块列表
func GetMonitorModules() ([]*MonitorModule, error) {
m, err := console_sqlite3.GetMonitorModules()
m, err := monitorModuleDao.GetMonitorModules()
if err != nil {
return make([]*MonitorModule, 0), nil
return nil, err
}
names := ksitigarbha.GetMonitorModuleNames()
modules := make([]*MonitorModule, 0, len(names))
for _, name := range names {
model,_ := ksitigarbha.GetMonitorModuleModel(name)
mod :=&MonitorModule{
Name: name,
Config: model.GetDefaultConfig(),
ModuleStatus: 0,
Desc: model.GetDesc(),
Models: model.GetModel(),
}
model, _ := ksitigarbha.GetMonitorModuleModel(name)
mod := &MonitorModule{
Name: name,
Config: model.GetDefaultConfig(),
ModuleStatus: 0,
Desc: model.GetDesc(),
Models: model.GetModel(),
}
v, ok := m[name]
if ok {
mod.ModuleStatus = v.ModuleStatus
c ,err := model.Decode(v.Config)
c, err := model.Decode(v.Config)
if err == nil {
mod.Config = c
}
......@@ -51,22 +83,21 @@ func GetMonitorModules() ([]*MonitorModule, error) {
func SetMonitorModule(moduleName string, config string, moduleStatus int) error {
model,has := ksitigarbha.GetMonitorModuleModel(moduleName)
model, has := ksitigarbha.GetMonitorModuleModel(moduleName)
if !has {
return errors.New("[error]the module does not exist")
}
if moduleStatus == 1 {
if moduleStatus == 1 {
_ ,err:= model.Decode(config)
if err != nil{
_, err := model.Decode(config)
if err != nil {
//errInfo := "[error]invalid config"
return err
}
}
err := console_sqlite3.SetMonitorModule(moduleName, config, moduleStatus)
err := monitorModuleDao.SetMonitorModule(moduleName, config, moduleStatus)
if err != nil {
return err
}
......
......@@ -4,27 +4,27 @@ import "testing"
func Test_InstanceLocker_Lock(t *testing.T) {
l:=newInstanceLocker()
instance:="test"
if !l.Lock(instance){
l := newInstanceLocker()
instance := "test"
if !l.Lock(instance) {
t.Error("should lock true")
return
}
if l.Lock(instance){
if l.Lock(instance) {
t.Error("should lock false")
return
}
l.UnLock(instance)
if !l.Lock(instance){
if !l.Lock(instance) {
t.Error("should lock true")
return
}
if l.Lock(instance){
if l.Lock(instance) {
t.Error("should lock false")
return
}
}
\ No newline at end of file
}
package node
import (
"github.com/eolinker/goku-api-gateway/common/pdao"
"github.com/eolinker/goku-api-gateway/server/dao"
)
var (
nodeDao dao.NodeDao
nodeGroupDao dao.NodeGroupDao
)
func init() {
pdao.Need(&nodeDao,&nodeGroupDao)
}
\ No newline at end of file
......@@ -3,66 +3,80 @@ package node
import (
"time"
console_sqlite3 "github.com/eolinker/goku-api-gateway/server/dao/console-sqlite3"
entity "github.com/eolinker/goku-api-gateway/server/entity/console-entity"
"github.com/eolinker/goku-api-gateway/utils"
)
//AddNode 新增节点信息
func AddNode(clusterID int, nodeName, listenAddress, adminAddress, gatewayPath string, groupID int) (bool, map[string]interface{}, error) {
func AddNode(clusterID int, nodeName, listenAddress, adminAddress, gatewayPath string, groupID int) (int64, string, string, error) {
now := time.Now().Format("20060102150405")
nodeKey := utils.Md5(utils.GetRandomString(16) + now)
return console_sqlite3.AddNode(clusterID, nodeName, nodeKey, listenAddress, adminAddress, gatewayPath, groupID)
return nodeDao.AddNode(clusterID, nodeName, nodeKey, listenAddress, adminAddress, gatewayPath, groupID)
}
//EditNode 修改节点
func EditNode(nodeName, listenAddress, adminAddress, gatewayPath string, nodeID, groupID int) (bool, string, error) {
return console_sqlite3.EditNode(nodeName, listenAddress, adminAddress, gatewayPath, nodeID, groupID)
func EditNode(nodeName, listenAddress, adminAddress, gatewayPath string, nodeID, groupID int) (string, error) {
return nodeDao.EditNode(nodeName, listenAddress, adminAddress, gatewayPath, nodeID, groupID)
}
//DeleteNode 删除节点
func DeleteNode(nodeID int) (bool, string, error) {
return console_sqlite3.DeleteNode(nodeID)
func DeleteNode(nodeID int) (string, error) {
return nodeDao.DeleteNode(nodeID)
}
//GetNodeInfo 获取节点信息
func GetNodeInfo(nodeID int) ( *entity.Node, error) {
node, e := console_sqlite3.GetNodeInfo(nodeID)
func GetNodeInfo(nodeID int) (*entity.Node, error) {
node, e := nodeDao.GetNodeInfo(nodeID)
if e != nil {
return nil, e
}
ResetNodeStatus(node)
return node, e
return node, e
}
//GetNodeInfoByKey 获取节点信息
func GetNodeInfoByKey(nodeKey string) ( *entity.Node, error) {
node, e := console_sqlite3.GetNodeByKey(nodeKey)
func GetNodeInfoByKey(nodeKey string) (*entity.Node, error) {
node, e := nodeDao.GetNodeByKey(nodeKey)
if e != nil {
return nil, e
}
ResetNodeStatus(node)
return node, e
return node, e
}
// GetNodeList 获取节点列表
func GetNodeList(clusterID, groupID int, keyword string) (bool, []*entity.Node, error) {
b, nodes, e := console_sqlite3.GetNodeList(clusterID, groupID, keyword)
func GetNodeList(clusterID, groupID int, keyword string) ([]*entity.Node, error) {
nodes, e := nodeDao.GetNodeList(clusterID, groupID, keyword)
if e != nil {
return nil, e
}
ResetNodeStatus(nodes...)
return b, nodes, e
return nodes, e
}
//GetAllNode 获取所有节点
func GetAllNode() ([]*entity.Node, error) {
nodes, e := nodeDao.GetNodeInfoAll()
if e != nil {
return nil, e
}
return nodes, e
}
//BatchDeleteNode 批量删除节点
func BatchDeleteNode(nodeIDList string) (bool, string, error) {
flag, nodeIDList, err := console_sqlite3.GetAvaliableNodeListFromNodeList(nodeIDList, 0)
if !flag {
return false, err.Error(), err
} else if nodeIDList == "" {
return false, "230013", err
func BatchDeleteNode(nodeIDList string) (string, error) {
nodeIDList, err := nodeDao.GetAvaliableNodeListFromNodeList(nodeIDList, 0)
if err != nil {
return err.Error(), err
}
if nodeIDList == "" {
return "230013", err
}
return console_sqlite3.BatchDeleteNode(nodeIDList)
return nodeDao.BatchDeleteNode(nodeIDList)
}
//BatchEditNodeGroup 批量修改节点分组
func BatchEditNodeGroup(nodeIDList string, groupID int) (bool, string, error) {
return console_sqlite3.BatchEditNodeGroup(nodeIDList, groupID)
func BatchEditNodeGroup(nodeIDList string, groupID int) (string, error) {
return nodeDao.BatchEditNodeGroup(nodeIDList, groupID)
}
//
////GetNodeIPList 获取节点IP列表
//func GetNodeIPList() (bool, []map[string]interface{}, error) {
// return console_sqlite3.GetNodeIPList()
//}
package node
import (
console_sqlite3 "github.com/eolinker/goku-api-gateway/server/dao/console-sqlite3"
)
//AddNodeGroup 新建节点分组
func AddNodeGroup(groupName string, clusterID int) (bool, interface{}, error) {
return console_sqlite3.AddNodeGroup(groupName, clusterID)
return nodeGroupDao.AddNodeGroup(groupName, clusterID)
}
//EditNodeGroup 修改节点分组信息
func EditNodeGroup(groupName string, groupID int) (bool, string, error) {
return console_sqlite3.EditNodeGroup(groupName, groupID)
return nodeGroupDao.EditNodeGroup(groupName, groupID)
}
//DeleteNodeGroup 删除节点分组
func DeleteNodeGroup(groupID int) (bool, string, error) {
return console_sqlite3.DeleteNodeGroup(groupID)
return nodeGroupDao.DeleteNodeGroup(groupID)
}
//GetNodeGroupInfo 获取节点分组信息
func GetNodeGroupInfo(groupID int) (bool, map[string]interface{}, error) {
return console_sqlite3.GetNodeGroupInfo(groupID)
return nodeGroupDao.GetNodeGroupInfo(groupID)
}
//GetNodeGroupList 获取节点分组列表
func GetNodeGroupList(clusterID int) (bool, []map[string]interface{}, error) {
return console_sqlite3.GetNodeGroupList(clusterID)
return nodeGroupDao.GetNodeGroupList(clusterID)
}
//CheckNodeGroupIsExist 检查节点分组是否存在
func CheckNodeGroupIsExist(groupID int) (bool, error) {
return console_sqlite3.CheckNodeGroupIsExist(groupID)
return nodeGroupDao.CheckNodeGroupIsExist(groupID)
}
//GetRunningNodeCount 获取分组内启动节点数量
func GetRunningNodeCount(groupID int) (bool, interface{}, error) {
return console_sqlite3.GetRunningNodeCount(groupID)
return nodeGroupDao.GetRunningNodeCount(groupID)
}
......@@ -8,7 +8,7 @@ import (
)
//EXPIRE 心跳检测过期时间
const EXPIRE = time.Second * 5
const EXPIRE = time.Second * 10
var (
manager = _StatusManager{
......@@ -25,11 +25,16 @@ type _StatusManager struct {
func (m *_StatusManager) refresh(id string) {
t := time.Now()
//heartBeat, err := nodeDao.GetHeartBeatTime(id)
//if err == nil {
// t = heartBeat
//}
m.locker.Lock()
m.lastHeartBeat[id] = t
m.locker.Unlock()
nodeDao.SetHeartBeatTime(id, time.Now())
}
func (m *_StatusManager) stop(id string) {
......@@ -48,7 +53,7 @@ func (m *_StatusManager) get(id string) (time.Time, bool) {
}
type _InstanceLocker struct {
locker sync.RWMutex
locker sync.RWMutex
instances map[string]bool
}
......@@ -58,22 +63,22 @@ func newInstanceLocker() *_InstanceLocker {
instances: make(map[string]bool),
}
}
func (l * _InstanceLocker)IsLock(key string)bool {
func (l *_InstanceLocker) IsLock(key string) bool {
l.locker.RLock()
locked :=l.instances[key]
locked := l.instances[key]
l.locker.RUnlock()
return locked
}
func (l * _InstanceLocker)Lock(key string)bool{
func (l *_InstanceLocker) Lock(key string) bool {
locked :=l.IsLock(key)
if locked{
locked := l.IsLock(key)
if locked {
return false
}
l.locker.Lock()
locked =l.instances[key]
if locked{
locked = l.instances[key]
if locked {
l.locker.Unlock()
return false
}
......@@ -81,7 +86,7 @@ func (l * _InstanceLocker)Lock(key string)bool{
l.locker.Unlock()
return true
}
func (l * _InstanceLocker)UnLock(key string){
func (l *_InstanceLocker) UnLock(key string) {
l.locker.Lock()
l.instances[key] = false
......@@ -90,21 +95,29 @@ func (l * _InstanceLocker)UnLock(key string){
//Refresh refresh
func Refresh( instance string) {
func Refresh(instance string) {
manager.refresh(instance)
}
func GetLastHeartTime(instance string) (time.Time, bool) {
return manager.get(instance)
}
//IsLive 通过ip和端口获取当前节点在线状态
func IsLive( instance string) bool {
func IsLive(instance string) bool {
if instanceLocker.IsLock(instance) {
return true
}
t, has := manager.get(instance)
if !has {
return false
}
if time.Now().Sub(t) > EXPIRE {
now := time.Now()
if now.Sub(t) > EXPIRE {
return false
}
return true
......@@ -113,23 +126,23 @@ func IsLive( instance string) bool {
//ResetNodeStatus 重置节点状态
func ResetNodeStatus(nodes ...*entity.Node) {
for _, node := range nodes {
if instanceLocker.IsLock(node.NodeKey) || IsLive(node.NodeKey) {
if instanceLocker.IsLock(node.NodeKey) || IsLive(node.NodeKey) {
node.NodeStatus = 1
} else {
node.NodeStatus = 0
if node.NodeStatus == 1 {
node.NodeStatus = 2
} else {
node.NodeStatus = 0
}
}
}
}
func Lock(key string)bool{
func Lock(key string) bool {
return instanceLocker.Lock(key)
}
func UnLock(key string) {
func UnLock(key string) {
instanceLocker.UnLock(key)
Refresh(key)
}
func IsLock(key string)bool{
return instanceLocker.Lock(key)
}
\ No newline at end of file
}
package plugin
import (
console_sqlite3 "github.com/eolinker/goku-api-gateway/server/dao/console-sqlite3"
"github.com/eolinker/goku-api-gateway/common/pdao"
"github.com/eolinker/goku-api-gateway/server/dao"
entity "github.com/eolinker/goku-api-gateway/server/entity/console-entity"
)
var (
pluginDao dao.PluginDao
)
func init() {
pdao.Need(&pluginDao)
}
//GetPluginInfo 获取插件配置信息
func GetPluginInfo(pluginName string) (bool, *entity.Plugin, error) {
return console_sqlite3.GetPluginInfo(pluginName)
return pluginDao.GetPluginInfo(pluginName)
}
//GetPluginList 获取插件列表
func GetPluginList(keyword string, condition int) (bool, []*entity.Plugin, error) {
return console_sqlite3.GetPluginList(keyword, condition)
return pluginDao.GetPluginList(keyword, condition)
}
//AddPlugin 新增插件信息
func AddPlugin(pluginName, pluginConfig, pluginDesc, version string, pluginPriority, isStop, pluginType int) (bool, string, error) {
return console_sqlite3.AddPlugin(pluginName, pluginConfig, pluginDesc, version, pluginPriority, isStop, pluginType)
return pluginDao.AddPlugin(pluginName, pluginConfig, pluginDesc, version, pluginPriority, isStop, pluginType)
}
//EditPlugin 修改插件信息
func EditPlugin(pluginName, pluginConfig, pluginDesc, version string, pluginPriority, isStop, pluginType int) (bool, string, error) {
return console_sqlite3.EditPlugin(pluginName, pluginConfig, pluginDesc, version, pluginPriority, isStop, pluginType)
return pluginDao.EditPlugin(pluginName, pluginConfig, pluginDesc, version, pluginPriority, isStop, pluginType)
}
//DeletePlugin 删除插件信息
func DeletePlugin(pluginName string) (bool, string, error) {
return console_sqlite3.DeletePlugin(pluginName)
return pluginDao.DeletePlugin(pluginName)
}
//CheckIndexIsExist 判断插件ID是否存在
func CheckIndexIsExist(pluginName string, pluginPriority int) (bool, error) {
return console_sqlite3.CheckIndexIsExist(pluginName, pluginPriority)
return pluginDao.CheckIndexIsExist(pluginName, pluginPriority)
}
//GetPluginConfig 获取插件配置及插件信息
func GetPluginConfig(pluginName string) (bool, string, error) {
return console_sqlite3.GetPluginConfig(pluginName)
return pluginDao.GetPluginConfig(pluginName)
}
//CheckNameIsExist 检查插件名称是否存在
func CheckNameIsExist(pluginName string) (bool, error) {
return console_sqlite3.CheckNameIsExist(pluginName)
return pluginDao.CheckNameIsExist(pluginName)
}
//EditPluginStatus 修改插件开启状态
func EditPluginStatus(pluginName string, pluginStatus int) (bool, error) {
flag, err := console_sqlite3.EditPluginStatus(pluginName, pluginStatus)
flag, err := pluginDao.EditPluginStatus(pluginName, pluginStatus)
return flag, err
}
//GetPluginListByPluginType 获取不同类型的插件列表
func GetPluginListByPluginType(pluginType int) (bool, []map[string]interface{}, error) {
return console_sqlite3.GetPluginListByPluginType(pluginType)
return pluginDao.GetPluginListByPluginType(pluginType)
}
//BatchStopPlugin 批量关闭插件
func BatchStopPlugin(pluginNameList string) (bool, string, error) {
flag, result, err := console_sqlite3.BatchStopPlugin(pluginNameList)
flag, result, err := pluginDao.BatchStopPlugin(pluginNameList)
return flag, result, err
}
//BatchStartPlugin 批量关闭插件
func BatchStartPlugin(pluginNameList string) (bool, string, error) {
flag, result, err := console_sqlite3.BatchStartPlugin(pluginNameList)
flag, result, err := pluginDao.BatchStartPlugin(pluginNameList)
return flag, result, err
}
//EditPluginCheckStatus 更新插件检测状态
func EditPluginCheckStatus(pluginName string, isCheck int) (bool, string, error) {
return console_sqlite3.EditPluginCheckStatus(pluginName, isCheck)
return pluginDao.EditPluginCheckStatus(pluginName, isCheck)
}
package project
import (
console_sqlite3 "github.com/eolinker/goku-api-gateway/server/dao/console-sqlite3"
"github.com/eolinker/goku-api-gateway/common/pdao"
"github.com/eolinker/goku-api-gateway/server/dao"
entity "github.com/eolinker/goku-api-gateway/server/entity/console-entity"
)
var (
projectDao dao.ProjectDao
)
func init() {
pdao.Need(&projectDao)
}
//AddProject 新建项目
func AddProject(projectName string) (bool, interface{}, error) {
return console_sqlite3.AddProject(projectName)
return projectDao.AddProject(projectName)
}
//EditProject 修改项目信息
func EditProject(projectName string, projectID int) (bool, string, error) {
return console_sqlite3.EditProject(projectName, projectID)
return projectDao.EditProject(projectName, projectID)
}
//DeleteProject 修改项目信息
func DeleteProject(projectID int) (bool, string, error) {
flag, result, err := console_sqlite3.DeleteProject(projectID)
flag, result, err := projectDao.DeleteProject(projectID)
return flag, result, err
}
//BatchDeleteProject 批量删除项目
func BatchDeleteProject(projectIDList string) (bool, string, error) {
flag, result, err := console_sqlite3.BatchDeleteProject(projectIDList)
flag, result, err := projectDao.BatchDeleteProject(projectIDList)
return flag, result, err
}
//GetProjectInfo 获取项目信息
func GetProjectInfo(projectID int) (bool, entity.Project, error) {
return console_sqlite3.GetProjectInfo(projectID)
return projectDao.GetProjectInfo(projectID)
}
//GetProjectList 获取项目列表
func GetProjectList(keyword string) (bool, []*entity.Project, error) {
return console_sqlite3.GetProjectList(keyword)
return projectDao.GetProjectList(keyword)
}
//CheckProjectIsExist 检查项目是否存在
func CheckProjectIsExist(projectID int) (bool, error) {
return console_sqlite3.CheckProjectIsExist(projectID)
return projectDao.CheckProjectIsExist(projectID)
}
//GetAPIListFromProjectNotInStrategy 获取项目列表中没有被策略组绑定的接口
func GetAPIListFromProjectNotInStrategy() (bool, []map[string]interface{}, error) {
return console_sqlite3.GetAPIListFromProjectNotInStrategy()
return projectDao.GetAPIListFromProjectNotInStrategy()
}
此差异已折叠。
......@@ -33,7 +33,7 @@ type Info struct {
HealthCheckTimeOut int `json:"healthCheckTimeOut"`
}
//Decode 解码
//Read 解码
func (i *Info) Decode() {
json.Unmarshal([]byte(i.ClusterConfig), &i.ClusterConfigObj)
}
......
package strategy
import (
"github.com/eolinker/goku-api-gateway/common/pdao"
"github.com/eolinker/goku-api-gateway/server/dao"
)
var(
strategyDao dao.StrategyDao
strategyGroupDao dao.StrategyGroupDao
strategyPluginDao dao.StrategyPluginDao
)
func init() {
pdao.Need(&strategyDao,&strategyGroupDao,&strategyPluginDao)
}
\ No newline at end of file
此差异已折叠。
......@@ -2,37 +2,35 @@ package strategy
import (
"errors"
console_sqlite3 "github.com/eolinker/goku-api-gateway/server/dao/console-sqlite3"
)
//AddStrategyGroup 新建策略组分组
func AddStrategyGroup(groupName string) (bool, interface{}, error) {
return console_sqlite3.AddStrategyGroup(groupName)
return strategyGroupDao.AddStrategyGroup(groupName)
}
//EditStrategyGroup 修改策略组分组
func EditStrategyGroup(groupName string, groupID int) (bool, string, error) {
return console_sqlite3.EditStrategyGroup(groupName, groupID)
return strategyGroupDao.EditStrategyGroup(groupName, groupID)
}
// DeleteStrategyGroup 删除策略组分组
func DeleteStrategyGroup(groupID int) (bool, string, error) {
flag := console_sqlite3.CheckIsOpenGroup(groupID)
flag := strategyGroupDao.CheckIsOpenGroup(groupID)
if flag {
return false, "[ERROR]The group is an open group", errors.New("[ERROR]The group is an open group")
}
flag, result, err := console_sqlite3.DeleteStrategyGroup(groupID)
flag, result, err := strategyGroupDao.DeleteStrategyGroup(groupID)
return flag, result, err
}
//GetStrategyGroupList 获取策略组分组列表
func GetStrategyGroupList() (bool, []map[string]interface{}, error) {
return console_sqlite3.GetStrategyGroupList()
return strategyGroupDao.GetStrategyGroupList()
}
//CheckIsOpenGroup 判断是否是开放分组
func CheckIsOpenGroup(groupID int) bool {
return console_sqlite3.CheckIsOpenGroup(groupID)
return strategyGroupDao.CheckIsOpenGroup(groupID)
}
此差异已折叠。
此差异已折叠。
......@@ -18,7 +18,7 @@ func NewIDCreate() *IDCreate {
//Next next
func (c *IDCreate) Next() uint64 {
var id uint64 = 0
var id uint64
c.locker.Lock()
id = uint64(time.Now().UnixNano())
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册