api.go 3.1 KB
Newer Older
E
eoLinker API Management 已提交
1 2 3
package api

import (
黄孟柱 已提交
4 5 6
	"github.com/eolinker/goku-api-gateway/server/dao"
	console_mysql "github.com/eolinker/goku-api-gateway/server/dao/console-mysql"
	entity "github.com/eolinker/goku-api-gateway/server/entity/console-entity"
E
eoLinker API Management 已提交
7 8
)

Y
Your Name 已提交
9 10
//AddAPI 新增接口
func AddAPI(apiName, requestURL, targetURL, requestMethod, targetMethod, isFollow, stripPrefix, stripSlash, balanceName, protocol string, projectID, groupID, timeout, retryCount, alertValve, managerID, userID int) (bool, int, error) {
E
eoLinker API Management 已提交
11 12
	name := "goku_gateway_api"

Y
Your Name 已提交
13
	flag, result, err := console_mysql.AddAPI(apiName, requestURL, targetURL, requestMethod, targetMethod, isFollow, stripPrefix, stripSlash, balanceName, protocol, projectID, groupID, timeout, retryCount, alertValve, managerID, userID)
E
eoLinker API Management 已提交
14 15 16 17 18 19
	if flag {
		dao.UpdateTable(name)
	}
	return flag, result, err
}

Y
Your Name 已提交
20 21
//EditAPI 新增接口
func EditAPI(apiName, requestURL, targetURL, requestMethod, targetMethod, isFollow, stripPrefix, stripSlash, balanceName, protocol string, projectID, groupID, timeout, retryCount, alertValve, apiID, managerID, userID int) (bool, error) {
E
eoLinker API Management 已提交
22
	name := "goku_gateway_api"
Y
Your Name 已提交
23
	flag, err := console_mysql.EditAPI(apiName, requestURL, targetURL, requestMethod, targetMethod, isFollow, stripPrefix, stripSlash, balanceName, protocol, projectID, groupID, timeout, retryCount, alertValve, apiID, managerID, userID)
E
eoLinker API Management 已提交
24 25 26 27 28 29
	if flag {
		dao.UpdateTable(name)
	}
	return flag, err
}

Y
Your Name 已提交
30 31 32
//GetAPIInfo 获取接口信息
func GetAPIInfo(apiID int) (bool, *entity.API, error) {
	return console_mysql.GetAPIInfo(apiID)
E
eoLinker API Management 已提交
33 34 35 36 37 38 39 40 41 42 43 44
}

// GetAPIIDList 获取接口ID列表
func GetAPIIDList(projectID int, groupID int, keyword string, condition int, ids []int) (bool, []int, error) {
	return console_mysql.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_mysql.GetAPIList(projectID, groupID, keyword, condition, page, pageSize, ids)
}

Y
Your Name 已提交
45
//CheckURLIsExist 接口路径是否存在
E
eoLinker API Management 已提交
46 47 48 49
func CheckURLIsExist(requestURL, requestMethod string, projectID, apiID int) bool {
	return console_mysql.CheckURLIsExist(requestURL, requestMethod, projectID, apiID)
}

Y
Your Name 已提交
50 51 52
//CheckAPIIsExist 检查接口是否存在
func CheckAPIIsExist(apiID int) (bool, error) {
	return console_mysql.CheckAPIIsExist(apiID)
E
eoLinker API Management 已提交
53 54
}

Y
Your Name 已提交
55 56 57
//BatchEditAPIGroup 批量修改接口分组
func BatchEditAPIGroup(apiIDList []string, groupID int) (bool, string, error) {
	r, e := console_mysql.BatchEditAPIGroup(apiIDList, groupID)
E
eoLinker API Management 已提交
58 59 60 61

	return e == nil, r, e
}

Y
Your Name 已提交
62 63
//BatchEditAPIBalance 批量修改接口负载
func BatchEditAPIBalance(apiIDList []string, balance string) (string, error) {
E
eoLinker API Management 已提交
64

Y
Your Name 已提交
65
	r, err := console_mysql.BatchEditAPIBalance(apiIDList, balance)
E
eoLinker API Management 已提交
66 67 68 69 70 71 72
	if err != nil {
		name := "goku_gateway_api"
		dao.UpdateTable(name)
	}
	return r, err
}

Y
Your Name 已提交
73 74
//BatchDeleteAPI 批量删除接口
func BatchDeleteAPI(apiIDList string) (bool, string, error) {
E
eoLinker API Management 已提交
75

Y
Your Name 已提交
76
	flag, result, err := console_mysql.BatchDeleteAPI(apiIDList)
E
eoLinker API Management 已提交
77 78 79 80 81 82
	if flag {
		name := "goku_gateway_api"
		dao.UpdateTable(name)
	}
	return flag, result, err
}