plugin.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 109
package plugin

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

// 获取插件配置信息
func GetPluginInfo(pluginName string) (bool, *entity.Plugin, error) {
	return console_mysql.GetPluginInfo(pluginName)
}

// 获取插件列表
func GetPluginList(keyword string, condition int) (bool, []*entity.Plugin, error) {
	return console_mysql.GetPluginList(keyword, condition)
}

// 新增插件信息
func AddPlugin(pluginName, pluginConfig, pluginDesc, version string, pluginPriority, isStop, pluginType int) (bool, string, error) {
	return console_mysql.AddPlugin(pluginName, pluginConfig, pluginDesc, version, pluginPriority, isStop, pluginType)
}

// 修改插件信息
func EditPlugin(pluginName, pluginConfig, pluginDesc, version string, pluginPriority, isStop, pluginType int) (bool, string, error) {
	return console_mysql.EditPlugin(pluginName, pluginConfig, pluginDesc, version, pluginPriority, isStop, pluginType)
}

// 删除插件信息
func DeletePlugin(pluginName string) (bool, string, error) {
	return console_mysql.DeletePlugin(pluginName)
}

// 判断插件ID是否存在
func CheckIndexIsExist(pluginName string, pluginPriority int) (bool, error) {
	return console_mysql.CheckIndexIsExist(pluginName, pluginPriority)
}

// 获取插件配置及插件信息
func GetPluginConfig(pluginName string) (bool, string, error) {
	return console_mysql.GetPluginConfig(pluginName)
}

// 检查插件名称是否存在
func CheckNameIsExist(pluginName string) (bool, error) {
	return console_mysql.CheckNameIsExist(pluginName)
}

// 修改插件开启状态
func EditPluginStatus(pluginName string, pluginStatus int) (bool, error) {
	tableName := "goku_plugin"
	flag, err := console_mysql.EditPluginStatus(pluginName, pluginStatus)
	if flag {
		dao.UpdateTable(tableName)
		console_mysql.UpdatePluginTagByPluginName(pluginName)
	}
	return flag, err
}

// 获取不同类型的插件列表
func GetPluginListByPluginType(pluginType int) (bool, []map[string]interface{}, error) {
	return console_mysql.GetPluginListByPluginType(pluginType)
}

// 批量关闭插件
func BatchStopPlugin(pluginNameList string) (bool, string, error) {
	//if strings.Contains(pluginNameList, "goku-rate_limiting") {
	//	updateFlag, errInfo := console_mysql.DeleteRateInfoInRedis("")
	//	if !updateFlag {
	//		utils.SystemLog(errInfo)
	//	}
	//} else if strings.Contains(pluginNameList, "goku-replay_attack_defender") {
	//	updateFlag, errInfo := console_mysql.DeleteReplayAttackTokenInRedis("")
	//	if !updateFlag {
	//		utils.SystemLog(errInfo)
	//	}
	//} else if strings.Contains(pluginNameList, "goku-oauth2_auth") {
	//	updateFlag, errInfo := console_mysql.DeleteOauth2InfoInRedis("", "")
	//	if !updateFlag {
	//		utils.SystemLog(errInfo)
	//	}
	//} else if strings.Contains(pluginNameList, "goku-proxy_caching") {
	//	console_mysql.ClearRedisProxyCache("", 0)
	//} else if strings.Contains(pluginNameList, "goku-circuit_breaker") {
	//	console_mysql.ClearRedisCircuitBreaker("", 0)
	//}
	tableName := "goku_plugin"
	flag, result, err := console_mysql.BatchStopPlugin(pluginNameList)
	if flag {
		dao.UpdateTable(tableName)
	}
	return flag, result, err
}

// 批量关闭插件
func BatchStartPlugin(pluginNameList string) (bool, string, error) {
	tableName := "goku_plugin"
	flag, result, err := console_mysql.BatchStartPlugin(pluginNameList)
	if flag {
		dao.UpdateTable(tableName)
		console_mysql.UpdatePluginTagByPluginName(pluginNameList)
	}
	return flag, result, err
}

// 更新插件检测状态
func EditPluginCheckStatus(pluginName string, isCheck int) (bool, string, error) {
	return console_mysql.EditPluginCheckStatus(pluginName, isCheck)
}