gateway.go 2.6 KB
Newer Older
Y
Your Name 已提交
1
package consolemysql
E
eoLinker API Management 已提交
2 3

import (
黄孟柱 已提交
4
	database2 "github.com/eolinker/goku-api-gateway/common/database"
E
eoLinker API Management 已提交
5 6
)

Y
Your Name 已提交
7
//GetGatewayConfig 获取网关配置
E
eoLinker API Management 已提交
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
func GetGatewayConfig() (map[string]interface{}, error) {
	db := database2.GetConnection()
	var successCode string
	var nodeUpdatePeriod, monitorUpdatePeriod, monitorTimeout int
	sql := `SELECT successCode,nodeUpdatePeriod,monitorUpdatePeriod,monitorTimeout FROM goku_gateway WHERE id = 1;`
	err := db.QueryRow(sql).Scan(&successCode, &nodeUpdatePeriod, &monitorUpdatePeriod, &monitorTimeout)
	if err != nil {
		return nil, err
	}
	gatewayConfig := map[string]interface{}{
		"successCode":         successCode,
		"nodeUpdatePeriod":    nodeUpdatePeriod,
		"monitorUpdatePeriod": monitorUpdatePeriod,
		"monitorTimeout":      monitorTimeout,
	}
	return gatewayConfig, nil
}

Y
Your Name 已提交
26
// EditGatewayBaseConfig 编辑网关基本配置
E
eoLinker API Management 已提交
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
func EditGatewayBaseConfig(successCode string, nodeUpdatePeriod, monitorUpdatePeriod, monitorTimeout int) (bool, string, error) {
	db := database2.GetConnection()
	sql := "SELECT successCode FROM goku_gateway WHERE id = 1;"
	code := ""
	err := db.QueryRow(sql).Scan(&code)
	if err != nil {
		sql = "INSERT INTO goku_gateway (id,successCode,nodeUpdatePeriod,monitorUpdatePeriod,monitorTimeout) VALUES (1,?,?,?,?)"
	} else {
		sql = "UPDATE goku_gateway SET successCode = ?,nodeUpdatePeriod = ?,monitorUpdatePeriod = ?,monitorTimeout = ? WHERE id = 1;"
	}
	stmt, err := db.Prepare(sql)
	if err != nil {
		return false, "[ERROR]Illegal SQL Statement!", err
	}
	_, err = stmt.Exec(successCode, nodeUpdatePeriod, monitorUpdatePeriod, monitorTimeout)
	if err != nil {
		return false, "[ERROR]Fail to excute SQL Statement!", err
	}
	return true, "", nil
}

Y
Your Name 已提交
48
// EditGatewayAlarmConfig 编辑网关告警配置
E
eoLinker API Management 已提交
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
func EditGatewayAlarmConfig(apiAlertInfo, sender, senderPassword, smtpAddress string, alertStatus, smtpPort, smtpProtocol int) (bool, string, error) {
	db := database2.GetConnection()
	sql := "SELECT successCode FROM goku_gateway WHERE id = 1;"
	code := ""
	err := db.QueryRow(sql).Scan(&code)
	if err != nil {
		sql = "INSERT INTO goku_gateway (id,apiAlertInfo,alertStatus,sender,senderPassword,smtpAddress,smtpPort,smtpProtocol) VALUES (1,?,?,?,?,?,?,?)"
	} else {
		sql = "UPDATE goku_gateway SET apiAlertInfo = ?,alertStatus = ?,sender = ?,senderPassword = ?,smtpAddress = ?,smtpPort = ?,smtpProtocol = ? WHERE id = 1;"
	}
	stmt, err := db.Prepare(sql)
	if err != nil {
		return false, "[ERROR]Illegal SQL Statement!", err
	}
	_, err = stmt.Exec(apiAlertInfo, alertStatus, sender, senderPassword, smtpAddress, smtpPort, smtpProtocol)
	if err != nil {
		return false, "[ERROR]Fail to excute SQL Statement!", err
	}
	return true, "", nil
}