apiPlugin.go 4.1 KB
Newer Older
E
eoLinker API Management 已提交
1 2 3 4 5 6
package api

import (
	"strconv"
	"strings"

黄孟柱 已提交
7 8
	"github.com/eolinker/goku-api-gateway/server/dao"
	console_mysql "github.com/eolinker/goku-api-gateway/server/dao/console-mysql"
E
eoLinker API Management 已提交
9 10
)

Y
Your Name 已提交
11 12
//BatchEditAPIPluginStatus 批量修改接口插件状态
func BatchEditAPIPluginStatus(connIDList, strategyID string, pluginStatus, userID int) (bool, string, error) {
E
eoLinker API Management 已提交
13 14
	idList := []string{}
	plugins := []string{}
Y
Your Name 已提交
15
	flag, apiIDList, _ := console_mysql.CheckAPIPluginIsExistByConnIDList(connIDList, "goku-circuit_breaker")
E
eoLinker API Management 已提交
16 17 18 19 20 21 22
	if flag {
		for _, id := range apiIDList {
			idList = append(idList, strconv.Itoa(id))
		}

		plugins = append(plugins, "goku-circuit_breaker")
	}
Y
Your Name 已提交
23
	flag, apiIDList, _ = console_mysql.CheckAPIPluginIsExistByConnIDList(connIDList, "goku-proxy_caching")
E
eoLinker API Management 已提交
24 25 26 27 28 29 30
	if flag {
		for _, id := range apiIDList {
			idList = append(idList, strconv.Itoa(id))
		}
		plugins = append(plugins, "goku-proxy_caching")
	}
	name := "goku_conn_plugin_api"
Y
Your Name 已提交
31
	flag, result, err := console_mysql.BatchEditAPIPluginStatus(connIDList, strategyID, pluginStatus, userID)
E
eoLinker API Management 已提交
32 33 34 35
	if flag {
		dao.UpdateTable(name)
		p := strings.Join(plugins, ",")
		ids := strings.Join(idList, ",")
Y
Your Name 已提交
36
		console_mysql.UpdateAPITagByPluginName(strategyID, ids, p)
E
eoLinker API Management 已提交
37 38 39 40
	}
	return flag, result, err
}

Y
Your Name 已提交
41 42
//BatchDeleteAPIPlugin 批量删除接口插件
func BatchDeleteAPIPlugin(connIDList, strategyID string) (bool, string, error) {
E
eoLinker API Management 已提交
43
	name := "goku_conn_plugin_api"
Y
Your Name 已提交
44
	flag, result, err := console_mysql.BatchDeleteAPIPlugin(connIDList, strategyID)
E
eoLinker API Management 已提交
45 46 47 48 49 50
	if flag {
		dao.UpdateTable(name)
	}
	return flag, result, err
}

Y
Your Name 已提交
51 52
//AddPluginToAPI 新增插件到接口
func AddPluginToAPI(pluginName, config, strategyID string, apiID, userID int) (bool, interface{}, error) {
E
eoLinker API Management 已提交
53
	name := "goku_conn_plugin_api"
Y
Your Name 已提交
54
	flag, result, err := console_mysql.AddPluginToAPI(pluginName, config, strategyID, apiID, userID)
E
eoLinker API Management 已提交
55 56
	if flag {
		dao.UpdateTable(name)
Y
Your Name 已提交
57
		console_mysql.UpdateAPITagByPluginName(strategyID, strconv.Itoa(apiID), pluginName)
E
eoLinker API Management 已提交
58 59 60 61
	}
	return flag, result, err
}

Y
Your Name 已提交
62 63
//EditAPIPluginConfig 修改接口插件配置
func EditAPIPluginConfig(pluginName, config, strategyID string, apiID, userID int) (bool, interface{}, error) {
E
eoLinker API Management 已提交
64
	name := "goku_conn_plugin_api"
Y
Your Name 已提交
65
	flag, result, err := console_mysql.EditAPIPluginConfig(pluginName, config, strategyID, apiID, userID)
E
eoLinker API Management 已提交
66 67
	if flag {
		dao.UpdateTable(name)
Y
Your Name 已提交
68
		console_mysql.UpdateAPITagByPluginName(strategyID, strconv.Itoa(apiID), pluginName)
E
eoLinker API Management 已提交
69 70 71 72
	}
	return flag, result, err
}

Y
Your Name 已提交
73 74 75
//GetAPIPluginList 获取接口插件列表
func GetAPIPluginList(apiID int, strategyID string) (bool, []map[string]interface{}, error) {
	return console_mysql.GetAPIPluginList(apiID, strategyID)
E
eoLinker API Management 已提交
76 77
}

Y
Your Name 已提交
78
//GetPluginIndex 获取插件优先级
E
eoLinker API Management 已提交
79 80 81 82
func GetPluginIndex(pluginName string) (bool, int, error) {
	return console_mysql.GetPluginIndex(pluginName)
}

Y
Your Name 已提交
83 84 85
//GetAPIPluginConfig 通过APIID获取配置信息
func GetAPIPluginConfig(apiID int, strategyID, pluginName string) (bool, map[string]string, error) {
	return console_mysql.GetAPIPluginConfig(apiID, strategyID, pluginName)
E
eoLinker API Management 已提交
86 87
}

Y
Your Name 已提交
88 89 90
//CheckPluginIsExistInAPI 检查策略组是否绑定插件
func CheckPluginIsExistInAPI(strategyID, pluginName string, apiID int) (bool, error) {
	return console_mysql.CheckPluginIsExistInAPI(strategyID, pluginName, apiID)
E
eoLinker API Management 已提交
91 92
}

Y
Your Name 已提交
93 94 95
//GetAllAPIPluginInStrategy 获取策略组中所有接口插件列表
func GetAllAPIPluginInStrategy(strategyID string) (bool, []map[string]interface{}, error) {
	return console_mysql.GetAllAPIPluginInStrategy(strategyID)
E
eoLinker API Management 已提交
96 97 98 99 100 101 102
}

// GetAPIPluginInStrategyByAPIID 获取策略组中所有接口插件列表
func GetAPIPluginInStrategyByAPIID(strategyID string, apiID int, keyword string, condition int) (bool, []map[string]interface{}, map[string]interface{}, error) {
	return console_mysql.GetAPIPluginInStrategyByAPIID(strategyID, apiID, keyword, condition)
}

Y
Your Name 已提交
103 104 105
//GetAPIPluginListWithNotAssignAPIList 获取没有绑定插件的接口列表
func GetAPIPluginListWithNotAssignAPIList(strategyID string) (bool, []map[string]interface{}, error) {
	return console_mysql.GetAPIPluginListWithNotAssignAPIList(strategyID)
E
eoLinker API Management 已提交
106 107
}

Y
Your Name 已提交
108 109 110
//UpdateAllAPIPluginUpdateTag 更新所有接口插件更新标识
func UpdateAllAPIPluginUpdateTag() error {
	return console_mysql.UpdateAllAPIPluginUpdateTag()
E
eoLinker API Management 已提交
111
}