apiPlugin.go 3.7 KB
Newer Older
E
eoLinker API Management 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
package api

import (
	"strconv"
	"strings"

	dao "github.com/eolinker/goku/server/dao"
	console_mysql "github.com/eolinker/goku/server/dao/console-mysql"
)

// 批量修改接口插件状态
func BatchEditApiPluginStatus(connIDList, strategyID string, pluginStatus, userID int) (bool, string, error) {
	idList := []string{}
	plugins := []string{}
	flag, apiIDList, _ := console_mysql.CheckApiPluginIsExistByConnIDList(connIDList, "goku-circuit_breaker")
	if flag {
		for _, id := range apiIDList {
			idList = append(idList, strconv.Itoa(id))
		}

		plugins = append(plugins, "goku-circuit_breaker")
	}
	flag, apiIDList, _ = console_mysql.CheckApiPluginIsExistByConnIDList(connIDList, "goku-proxy_caching")
	if flag {
		for _, id := range apiIDList {
			idList = append(idList, strconv.Itoa(id))
		}
		plugins = append(plugins, "goku-proxy_caching")
	}
	name := "goku_conn_plugin_api"
	flag, result, err := console_mysql.BatchEditApiPluginStatus(connIDList, strategyID, pluginStatus, userID)
	if flag {
		dao.UpdateTable(name)
		p := strings.Join(plugins, ",")
		ids := strings.Join(idList, ",")
		console_mysql.UpdateApiTagByPluginName(strategyID, ids, p)
	}
	return flag, result, err
}

// 批量删除接口插件
func BatchDeleteApiPlugin(connIDList, strategyID string) (bool, string, error) {
	name := "goku_conn_plugin_api"
	flag, result, err := console_mysql.BatchDeleteApiPlugin(connIDList, strategyID)
	if flag {
		dao.UpdateTable(name)
	}
	return flag, result, err
}

// 新增插件到接口
func AddPluginToApi(pluginName, config, strategyID string, apiID, userID int) (bool, interface{}, error) {
	name := "goku_conn_plugin_api"
	flag, result, err := console_mysql.AddPluginToApi(pluginName, config, strategyID, apiID, userID)
	if flag {
		dao.UpdateTable(name)
		console_mysql.UpdateApiTagByPluginName(strategyID, strconv.Itoa(apiID), pluginName)
	}
	return flag, result, err
}

// 修改接口插件配置
func EditApiPluginConfig(pluginName, config, strategyID string, apiID, userID int) (bool, interface{}, error) {
	name := "goku_conn_plugin_api"
	flag, result, err := console_mysql.EditApiPluginConfig(pluginName, config, strategyID, apiID, userID)
	if flag {
		dao.UpdateTable(name)
		console_mysql.UpdateApiTagByPluginName(strategyID, strconv.Itoa(apiID), pluginName)
	}
	return flag, result, err
}

func GetApiPluginList(apiID int, strategyID string) (bool, []map[string]interface{}, error) {
	return console_mysql.GetApiPluginList(apiID, strategyID)
}

// 获取插件优先级
func GetPluginIndex(pluginName string) (bool, int, error) {
	return console_mysql.GetPluginIndex(pluginName)
}

// 通过ApiID获取配置信息
func GetApiPluginConfig(apiID int, strategyID, pluginName string) (bool, map[string]string, error) {
	return console_mysql.GetApiPluginConfig(apiID, strategyID, pluginName)
}

// 检查策略组是否绑定插件
func CheckPluginIsExistInApi(strategyID, pluginName string, apiID int) (bool, error) {
	return console_mysql.CheckPluginIsExistInApi(strategyID, pluginName, apiID)
}

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

// 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)
}

func GetApiPluginListWithNotAssignApiList(strategyID string) (bool, []map[string]interface{}, error) {
	return console_mysql.GetApiPluginListWithNotAssignApiList(strategyID)
}

func UpdateAllApiPluginUpdateTag() error {
	return console_mysql.UpdateAllApiPluginUpdateTag()
}