未验证 提交 63fe5b88 编写于 作者: E Eolink 提交者: GitHub

Merge pull request #23 from Dot-Liu/master

完善注释
cluster:
- name: "Default"
-
name: "Default"
title: "默认机房"
note: "默认机房"
db:
......
......@@ -12,8 +12,11 @@ import (
)
var (
// UserPassword 用户密码
UserPassword string
// UserName 用户名
UserName string
// ConfFilePath 配置文件地址
ConfFilePath = "./config/goku.conf"
)
......
......@@ -13,7 +13,7 @@ import (
"github.com/eolinker/goku-api-gateway/common/database"
"github.com/eolinker/goku-api-gateway/common/general"
"github.com/eolinker/goku-api-gateway/common/redis-manager"
redis_manager "github.com/eolinker/goku-api-gateway/common/redis-manager"
goku_node "github.com/eolinker/goku-api-gateway/goku-node"
"github.com/eolinker/goku-api-gateway/server/entity"
)
......@@ -69,11 +69,11 @@ func main() {
return
}
goku_node.InitLog()
log.Debug("goku_node.InitLog")
log.Debug("gokNode.InitLog")
r := redis_manager.Create(&config.Redis)
redis_manager.SetDefault(r)
log.Debug("redis_manager.SetDefault")
log.Debug("redis-manager.SetDefault")
// 其他需要初始化的模块
_ = general.General()
......
<html>
<head>
<meta http-equiv="Content-Type" content="charset=utf-8"/>
</head>
<body style=" background: #f7f7f7;">
<div style="border-collapse: collapse; border:1px solid #e5e5e5;box-shadow: 0 10px 15px rgba(0, 0, 0, 0.05); width:800px;padding-bottom:10px;margin: auto; background-color: #fff;border-radius: 3px;">
<table cellpadding="0" cellspacing="0"
style="text-align: justify;width: 100%;font-size: 14px;padding:0 60px;color:#333; table-layout: fixed;">
<tbody>
<tr>
<td style="line-height: 120px;height: 120px;">
<b>GoKu&nbsp;Gateway&nbsp;EE</b>
</td>
</tr>
<tr>
<td style="line-height: 1.75em;">
<h2>GoKu告警:Redis节点出现异常</h2>
</td>
</tr>
<tr>
<td>
<p style="color:#333;font-size:14px;margin:15px 0 40px 0;">GoKu接口网关于
<b>$alertTime</b> 监控到以下Redis节点出现异常,详细告警内容请于
<b>$alertLogPath</b> 文件夹查看。</p>
</td>
</tr>
<tr>
<td style="padding:40px 0 5px 0;line-height: 1.75em;border-top:1px solid #e5e5e5;">
<h3>Redis异常节点列表</h3>
</td>
</tr>
<tr>
<td>
$redisList
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
\ No newline at end of file
......@@ -14,23 +14,28 @@
</tr>
<tr>
<td style="line-height: 1.75em;">
<h2>GoKu告警:节点自动重启失败,请及时重启节点。</h2>
<h2>GoKu告警:$requestURL接口在$alertPeriod分钟内转发失败$alertCount次</h2>
</td>
</tr>
<tr>
<td>
<p style="color:#333;font-size:14px;margin:15px 0 40px 0;">GoKu接口网关于 <b>$alertTime</b>
检测到以下节点重启失败,详细日志内容请于 <b>./log/nodeMonitorLog</b> 文件查看。
<p style="color:#333;font-size:14px;margin:15px 0 40px 0;">GoKu接口网关于 <b>$alertTime</b> 监控到<b>
$requestURL </b>接口在 <b>$alertPeriod</b> 分钟内转发失败达到 <b>$alertCount</b> 次,详细告警内容请于
<b>$alertLogPath</b> 文件夹查看。</p>
</td>
</tr>
<tr>
<td style="padding:40px 0 5px 0;line-height: 1.75em;border-top:1px solid #e5e5e5;">
<h3>自动重启失败的节点列表</h3>
<h3>接口基本信息</h3>
</td>
</tr>
<tr>
<td style="line-height: 1.75em; padding-bottom: 40px;">
$nodeList
<p>接口名称:$apiName</p>
<p>apiID:$apiID</p>
<p>请求路径:$requestURL</p>
<p>转发路径:$targetServer</p>
<p>映射路径:$proxyURL</p>
</td>
</tr>
</tbody>
......
......@@ -11,10 +11,12 @@ import (
"unsafe"
)
//Values values
type Values interface {
Get(key string) (string, bool)
}
//ValuesForm valuesForm
type ValuesForm map[string][]string
// Get gets the first value associated with the given key.
......@@ -41,6 +43,7 @@ type (
ContextHandle interface {
SetContext(ctx Values) error
}
//CheckOptHandler 判断是否有opt字段
CheckOptHandler interface {
IsOpt(key string) bool
}
......@@ -50,6 +53,7 @@ type (
}
)
//IsOpt 是否是opt字段
func IsOpt(key string, c interface{}) bool {
val := reflect.ValueOf(c).Elem()
typ := val.Type()
......@@ -67,8 +71,10 @@ func IsOpt(key string, c interface{}) bool {
return false
}
//ErrorNil error nil
var ErrorNil = errors.New("target is nil")
// SetContext 从url.Values中完成配置字段,context中不存在时,使用 default
// SetValues 从url.Values中完成配置字段,context中不存在时,使用 default
// 字段格式 opt:"name,require" default:"default value" min:"min value" max:"max value"
// require 为可选,表示该字段是否为必填
func SetValues(values url.Values, c interface{}) error {
......
// 读取配置信息
package conf
import (
......@@ -13,20 +12,28 @@ var (
lastFile = ""
)
//Get get
func Get(name string) (string, bool) {
v, has := _Configure[name]
return v, has
}
//Set set
func Set(name, value string) {
_Configure[name] = value
}
//Value value
func Value(name string) string {
return _Configure[name]
}
//Reload reload
func Reload() {
ReadConfigure(lastFile)
}
//MastValue mastValue
func MastValue(name string, def string) string {
v, h := _Configure[name]
if h {
......@@ -34,6 +41,8 @@ func MastValue(name string, def string) string {
}
return def
}
//ReadConfigure 读取配置
func ReadConfigure(filepath string) error {
file, err := os.Open(filepath)
if err != nil {
......@@ -53,14 +62,8 @@ func ReadConfigure(filepath string) error {
return nil
}
// 更新配置文件
//Save 更新配置文件
func Save() (bool, error) {
//file, err := os.OpenFile(lastFile, os.O_CREATE|os.O_WRONLY, 0666)
//if err != nil {
// panic(err)
//}
//defer file.Close()
confStr, err := yaml.Marshal(_Configure)
if err != nil {
return false, err
......
......@@ -3,6 +3,7 @@ package database
import (
"database/sql"
log "github.com/eolinker/goku-api-gateway/goku-log"
// mysql包
_ "github.com/go-sql-driver/mysql"
)
......@@ -14,6 +15,7 @@ var (
defaultDB *sql.DB
)
//InitConnection 初始化连接
func InitConnection(config Config) error {
db, e := getConnection(config)
defaultDB = db
......@@ -45,6 +47,7 @@ func getConnection(config Config) (*sql.DB, error) {
}
//GetConnection 获取连接
func GetConnection() *sql.DB {
return defaultDB
......
......@@ -20,12 +20,19 @@ import (
)
const (
//PRE_SIGNAL pre signal
PRE_SIGNAL = iota
//POST_SIGNAL post signal
POST_SIGNAL
//STATE_INIT state init
STATE_INIT
//STATE_RUNNING state running
STATE_RUNNING
//STATE_SHUTTING_DOWN state shutting down
STATE_SHUTTING_DOWN
//STATE_TERMINATE state terminate
STATE_TERMINATE
)
......@@ -36,10 +43,14 @@ var (
socketPtrOffsetMap map[string]uint
runningServersForked bool
DefaultReadTimeOut time.Duration
DefaultWriteTimeOut time.Duration
//DefaultReadTimeOut 默认读超时时间
DefaultReadTimeOut time.Duration
//DefaultWriteTimeOut 默认写超时时间
DefaultWriteTimeOut time.Duration
//DefaultMaxHeaderBytes 默认请求头最大字节数
DefaultMaxHeaderBytes int
DefaultHammerTime time.Duration
//DefaultHammerTime default hammer time
DefaultHammerTime time.Duration
isChild bool
socketOrder string
......@@ -47,7 +58,7 @@ var (
hookableSignals []os.Signal
)
var isStop bool = true
var isStop = true
func init() {
runningServerReg = sync.RWMutex{}
......
package general
//InitFunc init func
type InitFunc func() error
var (
......@@ -7,10 +8,13 @@ var (
_laterFunc []InitFunc
)
//RegeditInit 初始化注册
func RegeditInit(fn InitFunc) {
_initFunc = append(_initFunc, fn)
}
//General general
func General() error {
for _, fn := range _initFunc {
if err := fn(); err != nil {
......@@ -25,6 +29,7 @@ func General() error {
return nil
}
//RegeditLater regedit later
func RegeditLater(fn InitFunc) {
_laterFunc = append(_laterFunc, fn)
}
package redis_manager
package redismanager
import (
"fmt"
......@@ -11,6 +11,7 @@ const (
_PoolSize = 2000
)
//Create 创建
func Create(config RedisConfig) Redis {
switch config.GetMode() {
......
package redis_manager
package redismanager
//
//func GetKeys(r Redis, pattern string) ([]string, error) {
......
package redis_manager
package redismanager
import (
"sync"
......@@ -11,6 +11,7 @@ var (
locker sync.RWMutex
)
//InitRedisOfCluster 初始化集群redis
func InitRedisOfCluster(rs map[string]RedisConfig) {
locker.Lock()
defer locker.Unlock()
......@@ -27,6 +28,8 @@ func get(name string) (Redis, bool) {
return r, h
}
//Get 获取redis
func Get(name string) (Redis, bool) {
r, has := get(name)
......
package redis_manager
package redismanager
import (
"github.com/go-redis/redis"
......
package redis_manager
package redismanager
import "github.com/go-redis/redis"
const (
RedisModeCluster = "cluster"
RedisModeStand = "stand"
//RedisModeCluster cluster模式
RedisModeCluster = "cluster"
//RedisModeStand stand模式
RedisModeStand = "stand"
)
//Redis redis
type Redis interface {
redis.Cmdable
GetConfig() RedisConfig
......@@ -14,6 +17,7 @@ type Redis interface {
Nodes() []string
}
//RedisConfig redis config
type RedisConfig interface {
GetMode() string
GetAddrs() []string
......
package redis_manager
package redismanager
import (
"sync"
......@@ -10,11 +10,12 @@ var (
defLocker sync.Locker
)
//SetDefault 设置默认redis
func SetDefault(r Redis) {
def = r
}
// 获取redis连接
//GetConnection 获取redis连接
func GetConnection() Redis {
if def != nil {
return def
......
package version
//Version 版本号
const Version = "3.0.0"
......@@ -10,7 +10,7 @@ import (
"github.com/eolinker/goku-api-gateway/utils"
)
// 新增告警信息
// AddAlertMsg 新增告警信息
func AddAlertMsg(httpResponse http.ResponseWriter, httpRequest *http.Request) {
nodeIP := httpRequest.RemoteAddr
......
......@@ -6,6 +6,7 @@ import (
"strings"
)
//GetIpPort 获取IP端口
func GetIpPort(r *http.Request) (string, int, error) {
ip := r.RemoteAddr
ip = ip[:strings.Index(ip, ":")]
......
......@@ -10,6 +10,7 @@ import (
"strconv"
)
//Register 注册
func Register(w http.ResponseWriter, r *http.Request) {
ip, port, err := GetIpPort(r)
......@@ -28,7 +29,7 @@ func Register(w http.ResponseWriter, r *http.Request) {
func regedister(ip string, port int) (*entity.ClusterInfo, error) {
has, node, err := node.GetNodeInfoByIpPort(ip, port)
has, node, err := node.GetNodeInfoByIPPort(ip, port)
if err != nil {
return nil, err
}
......
......@@ -4,6 +4,7 @@ import (
"net/http"
)
//StartServer 开启admin服务
func StartServer(bind string) error {
handler := router()
return http.ListenAndServe(bind, handler)
......
......@@ -5,7 +5,7 @@ import (
"strconv"
"github.com/eolinker/goku-api-gateway/common/conf"
"github.com/eolinker/goku-api-gateway/common/redis-manager"
redis_manager "github.com/eolinker/goku-api-gateway/common/redis-manager"
cluster2 "github.com/eolinker/goku-api-gateway/server/cluster"
console_mysql "github.com/eolinker/goku-api-gateway/server/dao/console-mysql"
"github.com/eolinker/goku-api-gateway/server/entity"
......@@ -49,6 +49,8 @@ func getDefaultDatabase() (*entity.ClusterDB, error) {
Database: conf.Value("db_name"),
}, nil
}
//InitClusters 初始化集群
func InitClusters() {
infos, err := loadCluster(conf.MastValue("cluster_config", "config/cluster.yaml"))
......
......@@ -9,7 +9,7 @@ import (
"strconv"
)
// 用户登录
//Login 用户登录
func Login(httpResponse http.ResponseWriter, httpRequest *http.Request) {
//resultInfo := entity2.ResultInfo{}
......
......@@ -11,7 +11,7 @@ import (
"github.com/eolinker/goku-api-gateway/utils"
)
// 用户注销
//Logout 用户注销
func Logout(httpResponse http.ResponseWriter, httpRequest *http.Request) {
userIDCookie := http.Cookie{Name: "userID", Path: "/", MaxAge: -1}
......@@ -23,7 +23,7 @@ func Logout(httpResponse http.ResponseWriter, httpRequest *http.Request) {
return
}
// 修改账户信息
//EditPassword 修改账户信息
func EditPassword(httpResponse http.ResponseWriter, httpRequest *http.Request) {
userID, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationNone, controller.OperationEDIT)
if e != nil {
......@@ -37,8 +37,8 @@ func EditPassword(httpResponse http.ResponseWriter, httpRequest *http.Request) {
controller.WriteError(httpResponse,
"110005",
"user",
"[ERROR]Illegal oldPassword!",
errors.New("[ERROR]Illegal oldPassword!"))
"[error]illegal oldPassword!",
errors.New("[error]illegal oldPassword"))
return
}
if flag, _ := regexp.MatchString("^[0-9a-zA-Z]{32}$", newPassword); !flag {
......@@ -46,8 +46,8 @@ func EditPassword(httpResponse http.ResponseWriter, httpRequest *http.Request) {
controller.WriteError(httpResponse,
"110006",
"user",
"[ERROR]Illegal newPassword!",
errors.New("[ERROR]Illegal newPassword!"))
"[error]illegal newPassword!",
errors.New("[error]illegal newPassword"))
return
}
flag, result, err := account.EditPassword(oldPassword, newPassword, userID)
......@@ -70,7 +70,7 @@ func EditPassword(httpResponse http.ResponseWriter, httpRequest *http.Request) {
return
}
// 获取用户信息
//GetUserInfo 获取用户信息
func GetUserInfo(httpResponse http.ResponseWriter, httpRequest *http.Request) {
userID, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationNone, controller.OperationEDIT)
if e != nil {
......@@ -89,7 +89,7 @@ func GetUserInfo(httpResponse http.ResponseWriter, httpRequest *http.Request) {
return
}
// 获取用户类型
//GetUserType 获取用户类型
func GetUserType(httpResponse http.ResponseWriter, httpRequest *http.Request) {
userID, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationNone, controller.OperationEDIT)
if e != nil {
......@@ -107,7 +107,7 @@ func GetUserType(httpResponse http.ResponseWriter, httpRequest *http.Request) {
return
}
// 判断是否是管理员
//CheckUserIsAdmin 判断是否是管理员
func CheckUserIsAdmin(httpResponse http.ResponseWriter, httpRequest *http.Request) {
userID, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationNone, controller.OperationEDIT)
if e != nil {
......@@ -130,7 +130,7 @@ func CheckUserIsAdmin(httpResponse http.ResponseWriter, httpRequest *http.Reques
return
}
// 判断是否是超级管理员
//CheckUserIsSuperAdmin 判断是否是超级管理员
func CheckUserIsSuperAdmin(httpResponse http.ResponseWriter, httpRequest *http.Request) {
userID, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationNone, controller.OperationEDIT)
if e != nil {
......@@ -154,7 +154,7 @@ func CheckUserIsSuperAdmin(httpResponse http.ResponseWriter, httpRequest *http.R
return
}
// 检查用户权限
//CheckUserPermission 检查用户权限
func CheckUserPermission(httpResponse http.ResponseWriter, httpRequest *http.Request) {
userID, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationNone, controller.OperationEDIT)
if e != nil {
......
......@@ -39,7 +39,7 @@ func GetAlertMsgList(httpResponse http.ResponseWriter, httpRequest *http.Request
return
}
// 清空告警信息列表
//ClearAlertMsg 清空告警信息列表
func ClearAlertMsg(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAlert, controller.OperationEDIT)
if e != nil {
......@@ -61,7 +61,7 @@ func ClearAlertMsg(httpResponse http.ResponseWriter, httpRequest *http.Request)
return
}
// 删除告警信息
//DeleteAlertMsg 删除告警信息
func DeleteAlertMsg(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAlert, controller.OperationEDIT)
if e != nil {
......@@ -98,6 +98,7 @@ func DeleteAlertMsg(httpResponse http.ResponseWriter, httpRequest *http.Request)
return
}
//GetAlertConfig 获取告警配置
func GetAlertConfig(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAlert, controller.OperationREAD)
if e != nil {
......
......@@ -8,7 +8,8 @@ import (
"github.com/eolinker/goku-api-gateway/console/module/api"
)
func BatchSetBalanceApi(httpResponse http.ResponseWriter, httpRequest *http.Request) {
//BatchSetBalanceAPI 批量设置接口负载
func BatchSetBalanceAPI(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAPI, controller.OperationEDIT)
if e != nil {
return
......@@ -17,7 +18,7 @@ func BatchSetBalanceApi(httpResponse http.ResponseWriter, httpRequest *http.Requ
apiIDList := httpRequest.PostFormValue("apiIDList")
balanceName := httpRequest.PostFormValue("balance")
result, err := api.BatchEditApiBalance(strings.Split(apiIDList, ","), balanceName)
result, err := api.BatchEditAPIBalance(strings.Split(apiIDList, ","), balanceName)
if err != nil {
controller.WriteError(httpResponse, "190015", "api", result, err)
return
......
......@@ -11,7 +11,8 @@ import (
"github.com/eolinker/goku-api-gateway/console/module/api"
)
func AddApi(httpResponse http.ResponseWriter, httpRequest *http.Request) {
//AddAPI 新增接口
func AddAPI(httpResponse http.ResponseWriter, httpRequest *http.Request) {
userID, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAPI, controller.OperationEDIT)
if e != nil {
return
......@@ -106,7 +107,7 @@ func AddApi(httpResponse http.ResponseWriter, httpRequest *http.Request) {
// return
// }
flag, id, err := api.AddApi(apiName, requestURL, targetURL, requestMethod, targetMethod, isFollow, stripPrefix, stripSlash, balanceName, protocol, pjID, gID, t, count, apiValve, mgID, userID)
flag, id, err := api.AddAPI(apiName, requestURL, targetURL, requestMethod, targetMethod, isFollow, stripPrefix, stripSlash, balanceName, protocol, pjID, gID, t, count, apiValve, mgID, userID)
if !flag {
controller.WriteError(httpResponse,
......@@ -118,7 +119,8 @@ func AddApi(httpResponse http.ResponseWriter, httpRequest *http.Request) {
return
}
func EditApi(httpResponse http.ResponseWriter, httpRequest *http.Request) {
//EditAPI 编辑接口
func EditAPI(httpResponse http.ResponseWriter, httpRequest *http.Request) {
userID, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAPI, controller.OperationEDIT)
if e != nil {
return
......@@ -216,7 +218,7 @@ func EditApi(httpResponse http.ResponseWriter, httpRequest *http.Request) {
// return
// }
flag, err := api.EditApi(apiName, requestURL, targetURL, requestMethod, targetMethod, isFollow, stripPrefix, stripSlash, balanceName, protocol, pjID, gID, t, count, apiValve, aID, mgID, userID)
flag, err := api.EditAPI(apiName, requestURL, targetURL, requestMethod, targetMethod, isFollow, stripPrefix, stripSlash, balanceName, protocol, pjID, gID, t, count, apiValve, aID, mgID, userID)
if !flag {
controller.WriteError(httpResponse, "190000", "api", "[ERROR]apiID does not exist!", err)
......@@ -229,8 +231,8 @@ func EditApi(httpResponse http.ResponseWriter, httpRequest *http.Request) {
return
}
// 获取接口信息
func GetApiInfo(httpResponse http.ResponseWriter, httpRequest *http.Request) {
//GetAPIInfo 获取接口信息
func GetAPIInfo(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAPI, controller.OperationREAD)
if e != nil {
return
......@@ -244,7 +246,7 @@ func GetApiInfo(httpResponse http.ResponseWriter, httpRequest *http.Request) {
return
}
flag, result, err := api.GetApiInfo(aID)
flag, result, err := api.GetAPIInfo(aID)
if !flag {
controller.WriteError(httpResponse, "190000", "api", "[ERROR]The api does not exist!", err)
return
......@@ -302,7 +304,8 @@ func GetAPIIDList(httpResponse http.ResponseWriter, httpRequest *http.Request) {
return
}
func GetApiList(httpResponse http.ResponseWriter, httpRequest *http.Request) {
//GetAPIList 获取接口列表
func GetAPIList(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAPI, controller.OperationREAD)
if e != nil {
return
......@@ -362,8 +365,8 @@ func GetApiList(httpResponse http.ResponseWriter, httpRequest *http.Request) {
return
}
// BatchEditApiGroup 批量修改接口分组
func BatchEditApiGroup(httpResponse http.ResponseWriter, httpRequest *http.Request) {
// BatchEditAPIGroup 批量修改接口分组
func BatchEditAPIGroup(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAPI, controller.OperationEDIT)
if e != nil {
return
......@@ -376,7 +379,7 @@ func BatchEditApiGroup(httpResponse http.ResponseWriter, httpRequest *http.Reque
controller.WriteError(httpResponse, "190015", "api", "[ERROR]Illegal groupID!", nil)
return
}
flag, result, err := api.BatchEditApiGroup(strings.Split(apiIDList, ","), gID)
flag, result, err := api.BatchEditAPIGroup(strings.Split(apiIDList, ","), gID)
if !flag {
controller.WriteError(httpResponse, "190015", "api", result, err)
return
......@@ -386,8 +389,8 @@ func BatchEditApiGroup(httpResponse http.ResponseWriter, httpRequest *http.Reque
return
}
// 批量删除接口
func BatchDeleteApi(httpResponse http.ResponseWriter, httpRequest *http.Request) {
//BatchDeleteAPI 批量删除接口
func BatchDeleteAPI(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAPI, controller.OperationEDIT)
if e != nil {
return
......@@ -395,7 +398,7 @@ func BatchDeleteApi(httpResponse http.ResponseWriter, httpRequest *http.Request)
apiIDList := httpRequest.PostFormValue("apiIDList")
flag, result, err := api.BatchDeleteApi(apiIDList)
flag, result, err := api.BatchDeleteAPI(apiIDList)
if !flag {
controller.WriteError(httpResponse, "190000", "api", result, err)
......@@ -407,8 +410,8 @@ func BatchDeleteApi(httpResponse http.ResponseWriter, httpRequest *http.Request)
return
}
// 获取接口负责人列表
func GetApiManagerList(httpResponse http.ResponseWriter, httpRequest *http.Request) {
//GetAPIManagerList 获取接口负责人列表
func GetAPIManagerList(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAPI, controller.OperationREAD)
if e != nil {
return
......@@ -423,7 +426,8 @@ func GetApiManagerList(httpResponse http.ResponseWriter, httpRequest *http.Reque
return
}
func CopyApi(httpResponse http.ResponseWriter, httpRequest *http.Request) {
//CopyAPI 接口复制
func CopyAPI(httpResponse http.ResponseWriter, httpRequest *http.Request) {
userID, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAPI, controller.OperationEDIT)
if e != nil {
return
......@@ -471,12 +475,12 @@ func CopyApi(httpResponse http.ResponseWriter, httpRequest *http.Request) {
return
}
flag, apiInfo, err := api.GetApiInfo(aID)
flag, apiInfo, err := api.GetAPIInfo(aID)
if !flag {
controller.WriteError(httpResponse, "190000", "api", "[ERROR]apiID does not exist!", nil)
return
}
flag, id, err := api.AddApi(apiName, requestURL, targetURL, requestMethod, targetMethod, isFollow, strconv.FormatBool(apiInfo.StripPrefix), strconv.FormatBool(apiInfo.StripSlash), balanceName, protocol, pjID, gID, apiInfo.Timeout, apiInfo.RetryConut, apiInfo.Valve, apiInfo.ManagerID, userID)
flag, id, err := api.AddAPI(apiName, requestURL, targetURL, requestMethod, targetMethod, isFollow, strconv.FormatBool(apiInfo.StripPrefix), strconv.FormatBool(apiInfo.StripSlash), balanceName, protocol, pjID, gID, apiInfo.Timeout, apiInfo.RetryConut, apiInfo.Valve, apiInfo.ManagerID, userID)
if !flag {
controller.WriteError(httpResponse, "190000", "api", "[ERROR]Fail to add api!", err)
return
......
......@@ -9,8 +9,8 @@ import (
"github.com/eolinker/goku-api-gateway/console/module/project"
)
// 新建接口分组
func AddApiGroup(httpResponse http.ResponseWriter, httpRequest *http.Request) {
//AddAPIGroup 新建接口分组
func AddAPIGroup(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAPI, controller.OperationEDIT)
if e != nil {
return
......@@ -51,7 +51,7 @@ func AddApiGroup(httpResponse http.ResponseWriter, httpRequest *http.Request) {
return
}
flag, result, err := api.AddApiGroup(groupName, pjID, pgID)
flag, result, err := api.AddAPIGroup(groupName, pjID, pgID)
if !flag {
controller.WriteError(httpResponse,
......@@ -66,8 +66,8 @@ func AddApiGroup(httpResponse http.ResponseWriter, httpRequest *http.Request) {
return
}
// 修改接口分组
func EditApiGroup(httpResponse http.ResponseWriter, httpRequest *http.Request) {
//EditAPIGroup 修改接口分组
func EditAPIGroup(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAPI, controller.OperationEDIT)
if e != nil {
return
......@@ -107,7 +107,7 @@ func EditApiGroup(httpResponse http.ResponseWriter, httpRequest *http.Request) {
return
}
flag, result, err := api.EditApiGroup(groupName, gID, pjID)
flag, result, err := api.EditAPIGroup(groupName, gID, pjID)
if !flag {
controller.WriteError(httpResponse,
......@@ -118,8 +118,8 @@ func EditApiGroup(httpResponse http.ResponseWriter, httpRequest *http.Request) {
return
}
// 删除接口分组
func DeleteApiGroup(httpResponse http.ResponseWriter, httpRequest *http.Request) {
//DeleteAPIGroup 删除接口分组
func DeleteAPIGroup(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAPI, controller.OperationEDIT)
if e != nil {
return
......@@ -144,7 +144,7 @@ func DeleteApiGroup(httpResponse http.ResponseWriter, httpRequest *http.Request)
return
}
flag, result, err := api.DeleteApiGroup(pjID, gID)
flag, result, err := api.DeleteAPIGroup(pjID, gID)
if !flag {
controller.WriteError(httpResponse,
......@@ -156,8 +156,8 @@ func DeleteApiGroup(httpResponse http.ResponseWriter, httpRequest *http.Request)
return
}
// 获取接口分组列表
func GetApiGroupList(httpResponse http.ResponseWriter, httpRequest *http.Request) {
//GetAPIGroupList 获取接口分组列表
func GetAPIGroupList(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAPI, controller.OperationREAD)
if e != nil {
return
......@@ -172,7 +172,7 @@ func GetApiGroupList(httpResponse http.ResponseWriter, httpRequest *http.Request
return
}
flag, result, err := api.GetApiGroupList(pjID)
flag, result, err := api.GetAPIGroupList(pjID)
if !flag {
controller.WriteError(httpResponse,
......@@ -186,6 +186,7 @@ func GetApiGroupList(httpResponse http.ResponseWriter, httpRequest *http.Request
return
}
func UpdateApiGroupScript(httpResponse http.ResponseWriter, httpRequest *http.Request) {
api.UpdateApiGroupScript()
//UpdateAPIGroupScript 更新接口分组脚本
func UpdateAPIGroupScript(httpResponse http.ResponseWriter, httpRequest *http.Request) {
api.UpdateAPIGroupScript()
}
......@@ -12,8 +12,8 @@ import (
"github.com/eolinker/goku-api-gateway/console/module/strategy"
)
// 新增插件到接口
func AddPluginToApi(httpResponse http.ResponseWriter, httpRequest *http.Request) {
//AddPluginToAPI 新增插件到接口
func AddPluginToAPI(httpResponse http.ResponseWriter, httpRequest *http.Request) {
userID, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAPI, controller.OperationEDIT)
if e != nil {
return
......@@ -41,7 +41,7 @@ func AddPluginToApi(httpResponse http.ResponseWriter, httpRequest *http.Request)
controller.WriteError(httpResponse, "240005", "apiPlugin", "[ERROR]The plugin does not exist!", err)
return
}
flag, err = api.CheckApiIsExist(aID)
flag, err = api.CheckAPIIsExist(aID)
if !flag {
controller.WriteError(httpResponse, "240012", "apiPlugin", "[ERROR]The api does not exist!", err)
......@@ -56,17 +56,17 @@ func AddPluginToApi(httpResponse http.ResponseWriter, httpRequest *http.Request)
}
id := 0
exist, err := api.CheckPluginIsExistInApi(strategyID, pluginName, aID)
exist, err := api.CheckPluginIsExistInAPI(strategyID, pluginName, aID)
if exist {
flag, resultDesc, err := api.EditApiPluginConfig(pluginName, pluginConfig, strategyID, aID, userID)
flag, resultDesc, err := api.EditAPIPluginConfig(pluginName, pluginConfig, strategyID, aID, userID)
if !flag {
controller.WriteError(httpResponse, "240000", "apiPlugin", resultDesc.(string), err)
return
}
id = resultDesc.(int)
} else {
flag, resultDesc, err := api.AddPluginToApi(pluginName, pluginConfig, strategyID, aID, userID)
flag, resultDesc, err := api.AddPluginToAPI(pluginName, pluginConfig, strategyID, aID, userID)
if !flag {
controller.WriteError(httpResponse, "240000", "apiPlugin", resultDesc.(string), err)
return
......@@ -79,8 +79,8 @@ func AddPluginToApi(httpResponse http.ResponseWriter, httpRequest *http.Request)
return
}
// 修改接口插件
func EditApiPluginConfig(httpResponse http.ResponseWriter, httpRequest *http.Request) {
//EditAPIPluginConfig 修改接口插件
func EditAPIPluginConfig(httpResponse http.ResponseWriter, httpRequest *http.Request) {
userID, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAPI, controller.OperationEDIT)
if e != nil {
return
......@@ -117,7 +117,7 @@ func EditApiPluginConfig(httpResponse http.ResponseWriter, httpRequest *http.Req
return
}
flag, err = api.CheckApiIsExist(aID)
flag, err = api.CheckAPIIsExist(aID)
if !flag {
controller.WriteError(httpResponse,
"240012",
......@@ -137,7 +137,7 @@ func EditApiPluginConfig(httpResponse http.ResponseWriter, httpRequest *http.Req
return
}
flag, resultDesc, err := api.EditApiPluginConfig(pluginName, pluginConfig, strategyID, aID, userID)
flag, resultDesc, err := api.EditAPIPluginConfig(pluginName, pluginConfig, strategyID, aID, userID)
if !flag {
controller.WriteError(httpResponse,
......@@ -151,8 +151,8 @@ func EditApiPluginConfig(httpResponse http.ResponseWriter, httpRequest *http.Req
return
}
// 获取接口插件配置
func GetApiPluginConfig(httpResponse http.ResponseWriter, httpRequest *http.Request) {
//GetAPIPluginConfig 获取接口插件配置
func GetAPIPluginConfig(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAPI, controller.OperationREAD)
if e != nil {
return
......@@ -172,7 +172,7 @@ func GetApiPluginConfig(httpResponse http.ResponseWriter, httpRequest *http.Requ
return
}
flag, result, err := api.GetApiPluginConfig(aID, strategyID, pluginName)
flag, result, err := api.GetAPIPluginConfig(aID, strategyID, pluginName)
if !flag {
resultByte, _ := json.Marshal(map[string]interface{}{
"type": "apiPlugin",
......@@ -196,8 +196,8 @@ func GetApiPluginConfig(httpResponse http.ResponseWriter, httpRequest *http.Requ
}
// 获取接口插件配置
func GetApiPluginList(httpResponse http.ResponseWriter, httpRequest *http.Request) {
//GetAPIPluginList 获取接口插件配置
func GetAPIPluginList(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAPI, controller.OperationREAD)
if e != nil {
return
......@@ -215,7 +215,7 @@ func GetApiPluginList(httpResponse http.ResponseWriter, httpRequest *http.Reques
return
}
flag, result, err := api.GetApiPluginList(aID, strategyID)
flag, result, err := api.GetAPIPluginList(aID, strategyID)
if !flag {
controller.WriteError(httpResponse,
"240000",
......@@ -278,8 +278,8 @@ func GetAPIPluginInStrategyByAPIID(httpResponse http.ResponseWriter, httpRequest
// controller.WriteResultInfo(httpResponse, "apiPlugin", "apiPluginList", result)
}
// 获取策略组中所有接口插件列表
func GetAllApiPluginInStrategy(httpResponse http.ResponseWriter, httpRequest *http.Request) {
//GetAllAPIPluginInStrategy 获取策略组中所有接口插件列表
func GetAllAPIPluginInStrategy(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAPI, controller.OperationREAD)
if e != nil {
return
......@@ -287,7 +287,7 @@ func GetAllApiPluginInStrategy(httpResponse http.ResponseWriter, httpRequest *ht
strategyID := httpRequest.PostFormValue("strategyID")
flag, result, err := api.GetAllApiPluginInStrategy(strategyID)
flag, result, err := api.GetAllAPIPluginInStrategy(strategyID)
if !flag {
controller.WriteError(httpResponse,
......@@ -303,8 +303,8 @@ func GetAllApiPluginInStrategy(httpResponse http.ResponseWriter, httpRequest *ht
return
}
// 批量修改策略组插件状态
func BatchStartApiPlugin(httpResponse http.ResponseWriter, httpRequest *http.Request) {
//BatchStartAPIPlugin 批量修改策略组插件状态
func BatchStartAPIPlugin(httpResponse http.ResponseWriter, httpRequest *http.Request) {
userID, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAPI, controller.OperationEDIT)
if e != nil {
return
......@@ -321,7 +321,7 @@ func BatchStartApiPlugin(httpResponse http.ResponseWriter, httpRequest *http.Req
return
}
flag, result, err := api.BatchEditApiPluginStatus(connIDList, strategyID, 1, userID)
flag, result, err := api.BatchEditAPIPluginStatus(connIDList, strategyID, 1, userID)
if !flag {
controller.WriteError(httpResponse,
......@@ -336,8 +336,8 @@ func BatchStartApiPlugin(httpResponse http.ResponseWriter, httpRequest *http.Req
return
}
// 批量修改策略组插件状态
func BatchStopApiPlugin(httpResponse http.ResponseWriter, httpRequest *http.Request) {
//BatchStopAPIPlugin 批量修改策略组插件状态
func BatchStopAPIPlugin(httpResponse http.ResponseWriter, httpRequest *http.Request) {
userID, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAPI, controller.OperationEDIT)
if e != nil {
return
......@@ -354,7 +354,7 @@ func BatchStopApiPlugin(httpResponse http.ResponseWriter, httpRequest *http.Requ
return
}
flag, _, err := api.BatchEditApiPluginStatus(connIDList, strategyID, 0, userID)
flag, _, err := api.BatchEditAPIPluginStatus(connIDList, strategyID, 0, userID)
if !flag {
controller.WriteError(httpResponse,
......@@ -369,8 +369,8 @@ func BatchStopApiPlugin(httpResponse http.ResponseWriter, httpRequest *http.Requ
return
}
// 批量删除策略组插件
func BatchDeleteApiPlugin(httpResponse http.ResponseWriter, httpRequest *http.Request) {
//BatchDeleteAPIPlugin 批量删除策略组插件
func BatchDeleteAPIPlugin(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAPI, controller.OperationEDIT)
if e != nil {
return
......@@ -387,7 +387,7 @@ func BatchDeleteApiPlugin(httpResponse http.ResponseWriter, httpRequest *http.Re
return
}
flag, result, err := api.BatchDeleteApiPlugin(connIDList, strategyID)
flag, result, err := api.BatchDeleteAPIPlugin(connIDList, strategyID)
if !flag {
controller.WriteError(httpResponse,
......@@ -399,7 +399,8 @@ func BatchDeleteApiPlugin(httpResponse http.ResponseWriter, httpRequest *http.Re
controller.WriteResultInfo(httpResponse, "apiPlugin", "", nil)
}
func GetApiPluginListWithNotAssignApiList(httpResponse http.ResponseWriter, httpRequest *http.Request) {
//GetAPIPluginListWithNotAssignAPIList 获取没有绑定接口插件的接口列表
func GetAPIPluginListWithNotAssignAPIList(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAPI, controller.OperationREAD)
if e != nil {
return
......@@ -414,7 +415,7 @@ func GetApiPluginListWithNotAssignApiList(httpResponse http.ResponseWriter, http
nil)
return
}
flag, result, err := api.GetApiPluginListWithNotAssignApiList(strategyID)
flag, result, err := api.GetAPIPluginListWithNotAssignAPIList(strategyID)
if !flag {
controller.WriteError(httpResponse,
......@@ -428,6 +429,7 @@ func GetApiPluginListWithNotAssignApiList(httpResponse http.ResponseWriter, http
}
func UpdateAllApiPluginUpdateTag() error {
return api.UpdateAllApiPluginUpdateTag()
//UpdateAllAPIPluginUpdateTag 更新所有标识
func UpdateAllAPIPluginUpdateTag() error {
return api.UpdateAllAPIPluginUpdateTag()
}
......@@ -12,8 +12,8 @@ import (
entity "github.com/eolinker/goku-api-gateway/server/entity/console-entity"
)
// 导入分组
func ImportApiGroupFromAms(httpResponse http.ResponseWriter, httpRequest *http.Request) {
//ImportAPIGroupFromAms 导入分组
func ImportAPIGroupFromAms(httpResponse http.ResponseWriter, httpRequest *http.Request) {
userID, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAPI, controller.OperationEDIT)
if e != nil {
return
......@@ -81,7 +81,7 @@ func ImportApiGroupFromAms(httpResponse http.ResponseWriter, httpRequest *http.R
return
}
flag, _, err := api.ImportApiGroupFromAms(pjID, userID, groupInfo)
flag, _, err := api.ImportAPIGroupFromAms(pjID, userID, groupInfo)
if !flag {
controller.WriteError(httpResponse,
......@@ -96,7 +96,7 @@ func ImportApiGroupFromAms(httpResponse http.ResponseWriter, httpRequest *http.R
}
// 导入项目
//ImportProjectFromAms 导入项目
func ImportProjectFromAms(httpResponse http.ResponseWriter, httpRequest *http.Request) {
userID, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAPI, controller.OperationEDIT)
if e != nil {
......@@ -168,8 +168,8 @@ func ImportProjectFromAms(httpResponse http.ResponseWriter, httpRequest *http.Re
return
}
// 导入接口
func ImportApiFromAms(httpResponse http.ResponseWriter, httpRequest *http.Request) {
//ImportAPIFromAms 导入接口
func ImportAPIFromAms(httpResponse http.ResponseWriter, httpRequest *http.Request) {
userID, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAPI, controller.OperationEDIT)
if e != nil {
return
......@@ -228,7 +228,7 @@ func ImportApiFromAms(httpResponse http.ResponseWriter, httpRequest *http.Reques
return
}
apiList := make([]entity.AmsApiInfo, 0)
apiList := make([]entity.AmsAPIInfo, 0)
err = json.Unmarshal(body, &apiList)
if err != nil {
controller.WriteError(httpResponse,
......@@ -248,7 +248,7 @@ func ImportApiFromAms(httpResponse http.ResponseWriter, httpRequest *http.Reques
return
}
flag, _, err := api.ImportApiFromAms(pjID, gID, userID, apiList)
flag, _, err := api.ImportAPIFromAms(pjID, gID, userID, apiList)
if !flag {
controller.WriteError(httpResponse,
......
......@@ -10,7 +10,7 @@ import (
log "github.com/eolinker/goku-api-gateway/goku-log"
)
// 获取认证状态
//GetAuthStatus 获取认证状态
func GetAuthStatus(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationNone, controller.OperationREAD)
if e != nil {
......@@ -35,7 +35,7 @@ func GetAuthStatus(httpResponse http.ResponseWriter, httpRequest *http.Request)
return
}
// 获取认证信息
//GetAuthInfo 获取认证信息
func GetAuthInfo(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationNone, controller.OperationREAD)
if e != nil {
......@@ -62,7 +62,7 @@ func GetAuthInfo(httpResponse http.ResponseWriter, httpRequest *http.Request) {
}
// 编辑认证信息
//EditAuthInfo 编辑认证信息
func EditAuthInfo(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationNone, controller.OperationEDIT)
if e != nil {
......
......@@ -10,7 +10,7 @@ import (
"github.com/go-sql-driver/mysql"
)
// 新增负载配置
//AddBalance 新增负载配置
func AddBalance(w http.ResponseWriter, r *http.Request) {
_, e := controller.CheckLogin(w, r, controller.OperationLoadBalance, controller.OperationEDIT)
......
......@@ -8,7 +8,7 @@ import (
"github.com/eolinker/goku-api-gateway/console/module/balance"
)
// 删除负载配置
//DeleteBalance 删除负载配置
func DeleteBalance(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationLoadBalance, controller.OperationEDIT)
if e != nil {
......@@ -34,7 +34,7 @@ func DeleteBalance(httpResponse http.ResponseWriter, httpRequest *http.Request)
return
}
// 批量删除负载
//BatchDeleteBalance 批量删除负载
func BatchDeleteBalance(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationLoadBalance, controller.OperationEDIT)
......
......@@ -7,7 +7,7 @@ import (
"github.com/eolinker/goku-api-gateway/console/module/balance"
)
// 获取负载信息
//GetBalanceInfo 获取负载信息
func GetBalanceInfo(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationLoadBalance, controller.OperationREAD)
if e != nil {
......
......@@ -8,7 +8,7 @@ import (
"github.com/eolinker/goku-api-gateway/console/module/balance"
)
// 获取负载列表
//GetBalanceList 获取负载列表
func GetBalanceList(w http.ResponseWriter, r *http.Request) {
_, e := controller.CheckLogin(w, r, controller.OperationLoadBalance, controller.OperationREAD)
if e != nil {
......
......@@ -10,7 +10,7 @@ import (
"github.com/go-sql-driver/mysql"
)
// 新增负载配置
//SaveBalance 新增负载配置
func SaveBalance(w http.ResponseWriter, r *http.Request) {
_, e := controller.CheckLogin(w, r, controller.OperationLoadBalance, controller.OperationEDIT)
......
......@@ -7,6 +7,7 @@ import (
"github.com/eolinker/goku-api-gateway/console/module/balance"
)
//GetSimpleList 获取简易列表
func GetSimpleList(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationLoadBalance, controller.OperationREAD)
if e != nil {
......
......@@ -7,6 +7,7 @@ import (
cluster2 "github.com/eolinker/goku-api-gateway/server/cluster"
)
//GetClusterList 获取集群列表
func GetClusterList(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationNone, controller.OperationREAD)
if e != nil {
......@@ -21,6 +22,7 @@ func GetClusterList(httpResponse http.ResponseWriter, httpRequest *http.Request)
}
//GetClusterInfoList 获取集群信息列表
func GetClusterInfoList(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationNone, controller.OperationREAD)
......
package config_log
package configlog
import (
"fmt"
......@@ -9,6 +9,7 @@ import (
module "github.com/eolinker/goku-api-gateway/console/module/config-log"
)
//AccessLogHandler access日志处理器
type AccessLogHandler struct {
}
......
package config_log
package configlog
import (
"fmt"
......@@ -7,6 +7,7 @@ import (
"strings"
)
//Handle 处理器
func Handle(prefix string) http.Handler {
pre := strings.TrimSuffix(prefix, "/")
......@@ -21,9 +22,7 @@ func Handle(prefix string) http.Handler {
}
serveMux.Handle(fmt.Sprintf("%s/%s", pre, "node"), nodeLogHandler)
accessLogHandler := &AccessLogHandler{
}
accessLogHandler := &AccessLogHandler{}
serveMux.Handle(fmt.Sprintf("%s/%s", pre, "access"), accessLogHandler)
......
package config_log
package configlog
import (
"fmt"
......@@ -9,6 +9,7 @@ import (
module "github.com/eolinker/goku-api-gateway/console/module/config-log"
)
//LogHandler 日志处理器
type LogHandler struct {
name string
}
......
......@@ -4,6 +4,7 @@ import (
"net/http"
)
//Handle 处理器
func Handle(prefix string) http.Handler {
serveMux := http.NewServeMux()
......
......@@ -9,6 +9,7 @@ import (
monitor_read "github.com/eolinker/goku-api-gateway/server/monitor/monitor-read"
)
//GetGatewayConfig 获取网关配置
func GetGatewayConfig(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationGatewayConfig, controller.OperationREAD)
if e != nil {
......@@ -30,6 +31,7 @@ func GetGatewayConfig(httpResponse http.ResponseWriter, httpRequest *http.Reques
return
}
//EditGatewayBaseConfig 获取网关基本配置
func EditGatewayBaseConfig(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationGatewayConfig, controller.OperationEDIT)
if e != nil {
......@@ -94,6 +96,7 @@ func EditGatewayBaseConfig(httpResponse http.ResponseWriter, httpRequest *http.R
return
}
//EditGatewayAlarmConfig 编辑网关告警配置
func EditGatewayAlarmConfig(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationGatewayConfig, controller.OperationEDIT)
if e != nil {
......
......@@ -11,6 +11,7 @@ import (
"github.com/eolinker/goku-api-gateway/server/cluster"
)
//GetGatewayMonitorSummaryByPeriod 获取网关概况
func GetGatewayMonitorSummaryByPeriod(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationNone, controller.OperationREAD)
if e != nil {
......@@ -18,7 +19,7 @@ func GetGatewayMonitorSummaryByPeriod(httpResponse http.ResponseWriter, httpRequ
}
clusterName := httpRequest.PostFormValue("cluster")
clusterId, has := cluster.GetId(clusterName)
clusterID, has := cluster.GetID(clusterName)
if !has && clusterName != "" {
controller.WriteError(httpResponse, "340003", "", "[ERROR]Illegal cluster!", nil)
return
......@@ -60,7 +61,7 @@ func GetGatewayMonitorSummaryByPeriod(httpResponse http.ResponseWriter, httpRequ
return
}
flag, result, err := monitor.GetGatewayMonitorSummaryByPeriod(clusterId, beginTime, endTime, p)
flag, result, err := monitor.GetGatewayMonitorSummaryByPeriod(clusterID, beginTime, endTime, p)
if !flag {
controller.WriteError(httpResponse,
"340000",
......
......@@ -15,7 +15,7 @@ import (
"github.com/eolinker/goku-api-gateway/utils"
)
// 新增节点信息
//AddNode 新增节点信息
func AddNode(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationNode, controller.OperationEDIT)
......@@ -25,7 +25,7 @@ func AddNode(httpResponse http.ResponseWriter, httpRequest *http.Request) {
cluserName := httpRequest.PostFormValue("cluster")
clusterId, has := cluster2.GetId(cluserName)
clusterID, has := cluster2.GetID(cluserName)
if !has {
controller.WriteError(httpResponse, "340003", "", "[ERROR]Illegal cluster!", nil)
return
......@@ -79,7 +79,7 @@ func AddNode(httpResponse http.ResponseWriter, httpRequest *http.Request) {
return
}
flag, result, err := node.AddNode(clusterId, nodeName, nodeIP, nodePort, gatewayPath, gID)
flag, result, err := node.AddNode(clusterID, nodeName, nodeIP, nodePort, gatewayPath, gID)
if !flag {
controller.WriteError(httpResponse,
......@@ -102,7 +102,7 @@ func AddNode(httpResponse http.ResponseWriter, httpRequest *http.Request) {
httpResponse.Write(data)
}
// 修改节点信息
//EditNode 修改节点信息
func EditNode(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationNode, controller.OperationEDIT)
......@@ -122,7 +122,7 @@ func EditNode(httpResponse http.ResponseWriter, httpRequest *http.Request) {
flag := utils.ValidateRemoteAddr(nodeIP + ":" + nodePort)
if !flag {
controller.WriteError(httpResponse, "230006", "node", "[ERROR]Illegal remote address!", errors.New("[ERROR]Illegal remote address!"))
controller.WriteError(httpResponse, "230006", "node", "[ERROR]Illegal remote address!", errors.New("[error]illegal remote address"))
return
}
......@@ -172,7 +172,7 @@ func EditNode(httpResponse http.ResponseWriter, httpRequest *http.Request) {
return
}
// 删除节点信息
//DeleteNode 删除节点信息
func DeleteNode(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationNode, controller.OperationEDIT)
......@@ -228,7 +228,7 @@ func GetNodeList(httpResponse http.ResponseWriter, httpRequest *http.Request) {
gID = -1
}
clusterID, has := cluster2.GetId(cluserName)
clusterID, has := cluster2.GetID(cluserName)
if !has {
controller.WriteError(httpResponse, "330003", "node", "[ERROR]The cluster dosen't exist!", nil)
return
......@@ -249,7 +249,7 @@ func GetNodeList(httpResponse http.ResponseWriter, httpRequest *http.Request) {
}
// 获取节点信息
//GetNodeInfo 获取节点信息
func GetNodeInfo(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationNode, controller.OperationREAD)
if e != nil {
......@@ -285,7 +285,7 @@ func GetNodeInfo(httpResponse http.ResponseWriter, httpRequest *http.Request) {
return
}
// 节点IP查重
//CheckIsExistRemoteAddr 节点IP查重
func CheckIsExistRemoteAddr(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationNode, controller.OperationREAD)
......@@ -323,7 +323,7 @@ func CheckIsExistRemoteAddr(httpResponse http.ResponseWriter, httpRequest *http.
return
}
// 批量修改节点分组
//BatchEditNodeGroup 批量修改节点分组
func BatchEditNodeGroup(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationNode, controller.OperationEDIT)
......@@ -361,7 +361,7 @@ func BatchEditNodeGroup(httpResponse http.ResponseWriter, httpRequest *http.Requ
return
}
// 批量删除节点
//BatchDeleteNode 批量删除节点
func BatchDeleteNode(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationNode, controller.OperationEDIT)
......
......@@ -9,6 +9,7 @@ import (
cluster2 "github.com/eolinker/goku-api-gateway/server/cluster"
)
//AddNodeGroup 新增节点分组
func AddNodeGroup(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationNode, controller.OperationEDIT)
......@@ -18,7 +19,7 @@ func AddNodeGroup(httpResponse http.ResponseWriter, httpRequest *http.Request) {
cluserName := httpRequest.PostFormValue("cluster")
clusterId, has := cluster2.GetId(cluserName)
clusterID, has := cluster2.GetID(cluserName)
if !has {
controller.WriteError(httpResponse, "340003", "", "[ERROR]Illegal cluster!", nil)
......@@ -34,7 +35,7 @@ func AddNodeGroup(httpResponse http.ResponseWriter, httpRequest *http.Request) {
return
}
flag, result, err := node.AddNodeGroup(groupName, clusterId)
flag, result, err := node.AddNodeGroup(groupName, clusterID)
if !flag {
controller.WriteError(httpResponse,
......@@ -50,7 +51,7 @@ func AddNodeGroup(httpResponse http.ResponseWriter, httpRequest *http.Request) {
return
}
// 修改节点分组信息
//EditNodeGroup 修改节点分组信息
func EditNodeGroup(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationNode, controller.OperationEDIT)
......@@ -95,7 +96,7 @@ func EditNodeGroup(httpResponse http.ResponseWriter, httpRequest *http.Request)
controller.WriteResultInfo(httpResponse, "nodeGroup", "", nil)
}
// 删除节点分组
//DeleteNodeGroup 删除节点分组
func DeleteNodeGroup(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationNode, controller.OperationEDIT)
if e != nil {
......@@ -147,7 +148,7 @@ func DeleteNodeGroup(httpResponse http.ResponseWriter, httpRequest *http.Request
}
// 获取节点分组信息
//GetNodeGroupInfo 获取节点分组信息
func GetNodeGroupInfo(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationNode, controller.OperationREAD)
if e != nil {
......@@ -180,7 +181,7 @@ func GetNodeGroupInfo(httpResponse http.ResponseWriter, httpRequest *http.Reques
controller.WriteResultInfo(httpResponse, "node", "groupInfo", result)
}
// 获取节点分组列表
//GetNodeGroupList 获取节点分组列表
func GetNodeGroupList(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationNode, controller.OperationREAD)
if e != nil {
......@@ -188,7 +189,7 @@ func GetNodeGroupList(httpResponse http.ResponseWriter, httpRequest *http.Reques
}
cluserName := httpRequest.FormValue("cluster")
clusterId, has := cluster2.GetId(cluserName)
clusterID, has := cluster2.GetID(cluserName)
if !has {
controller.WriteError(httpResponse,
"280001",
......@@ -197,7 +198,7 @@ func GetNodeGroupList(httpResponse http.ResponseWriter, httpRequest *http.Reques
nil)
return
}
flag, result, err := node.GetNodeGroupList(clusterId)
flag, result, err := node.GetNodeGroupList(clusterID)
if !flag {
controller.WriteError(httpResponse,
......
......@@ -40,7 +40,7 @@ func GetPluginList(httpResponse http.ResponseWriter, httpRequest *http.Request)
return
}
// 新增插件信息
//AddPlugin 新增插件信息
func AddPlugin(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationPlugin, controller.OperationEDIT)
if e != nil {
......@@ -106,7 +106,7 @@ func AddPlugin(httpResponse http.ResponseWriter, httpRequest *http.Request) {
return
}
// 修改插件信息
//EditPlugin 修改插件信息
func EditPlugin(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationPlugin, controller.OperationEDIT)
if e != nil {
......@@ -162,7 +162,7 @@ func EditPlugin(httpResponse http.ResponseWriter, httpRequest *http.Request) {
controller.WriteResultInfo(httpResponse, "plugin", "", nil)
}
// 删除插件信息
//DeletePlugin 删除插件信息
func DeletePlugin(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationPlugin, controller.OperationEDIT)
if e != nil {
......@@ -195,7 +195,7 @@ func DeletePlugin(httpResponse http.ResponseWriter, httpRequest *http.Request) {
return
}
// 获取插件信息
//GetPluginInfo 获取插件信息
func GetPluginInfo(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationPlugin, controller.OperationREAD)
if e != nil {
......@@ -228,7 +228,7 @@ func GetPluginInfo(httpResponse http.ResponseWriter, httpRequest *http.Request)
controller.WriteResultInfo(httpResponse, "plugin", "pluginInfo", result)
}
// 获取插件配置
//GetPluginConfig 获取插件配置
func GetPluginConfig(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationPlugin, controller.OperationREAD)
if e != nil {
......@@ -252,7 +252,7 @@ func GetPluginConfig(httpResponse http.ResponseWriter, httpRequest *http.Request
return
}
// 判断插件优先级是否存在
//CheckIndexIsExist 判断插件优先级是否存在
func CheckIndexIsExist(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationPlugin, controller.OperationEDIT)
if e != nil {
......@@ -286,7 +286,7 @@ func CheckIndexIsExist(httpResponse http.ResponseWriter, httpRequest *http.Reque
return
}
// 检查插件名称是否存在
//CheckNameIsExist 检查插件名称是否存在
func CheckNameIsExist(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationPlugin, controller.OperationEDIT)
if e != nil {
......@@ -309,7 +309,7 @@ func CheckNameIsExist(httpResponse http.ResponseWriter, httpRequest *http.Reques
}
// 开启插件
//StartPlugin 开启插件
func StartPlugin(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationPlugin, controller.OperationEDIT)
if e != nil {
......@@ -332,7 +332,7 @@ func StartPlugin(httpResponse http.ResponseWriter, httpRequest *http.Request) {
controller.WriteResultInfo(httpResponse, "plugin", "", nil)
}
// 关闭插件
//StopPlugin 关闭插件
func StopPlugin(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationPlugin, controller.OperationEDIT)
if e != nil {
......@@ -354,7 +354,7 @@ func StopPlugin(httpResponse http.ResponseWriter, httpRequest *http.Request) {
controller.WriteResultInfo(httpResponse, "plugin", "", nil)
}
// 获取不同类型的插件列表
//GetPluginListByPluginType 获取不同类型的插件列表
func GetPluginListByPluginType(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationPlugin, controller.OperationREAD)
if e != nil {
......@@ -387,7 +387,7 @@ func GetPluginListByPluginType(httpResponse http.ResponseWriter, httpRequest *ht
controller.WriteResultInfo(httpResponse, "plugin", "pluginList", result)
}
// 批量关闭插件
//BatchStopPlugin 批量关闭插件
func BatchStopPlugin(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationPlugin, controller.OperationEDIT)
if e != nil {
......@@ -411,7 +411,7 @@ func BatchStopPlugin(httpResponse http.ResponseWriter, httpRequest *http.Request
return
}
// 批量关闭插件
//BatchStartPlugin 批量关闭插件
func BatchStartPlugin(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationPlugin, controller.OperationEDIT)
if e != nil {
......@@ -435,6 +435,7 @@ func BatchStartPlugin(httpResponse http.ResponseWriter, httpRequest *http.Reques
}
//CheckPluginIsAvailable 判断插件是否可用
func CheckPluginIsAvailable(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationPlugin, controller.OperationEDIT)
if e != nil {
......
......@@ -8,7 +8,7 @@ import (
"github.com/eolinker/goku-api-gateway/console/module/project"
)
// 新建项目
//AddProject 新建项目
func AddProject(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAPI, controller.OperationEDIT)
if e != nil {
......@@ -41,7 +41,7 @@ func AddProject(httpResponse http.ResponseWriter, httpRequest *http.Request) {
return
}
// 修改项目信息
//EditProject 修改项目信息
func EditProject(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAPI, controller.OperationEDIT)
if e != nil {
......@@ -85,7 +85,7 @@ func EditProject(httpResponse http.ResponseWriter, httpRequest *http.Request) {
return
}
// 删除项目信息
//DeleteProject 删除项目信息
func DeleteProject(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAPI, controller.OperationEDIT)
if e != nil {
......@@ -120,7 +120,7 @@ func DeleteProject(httpResponse http.ResponseWriter, httpRequest *http.Request)
return
}
// 删除项目信息
//BatchDeleteProject 删除项目信息
func BatchDeleteProject(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAPI, controller.OperationEDIT)
if e != nil {
......@@ -145,7 +145,7 @@ func BatchDeleteProject(httpResponse http.ResponseWriter, httpRequest *http.Requ
return
}
// 获取项目信息
//GetProjectInfo 获取项目信息
func GetProjectInfo(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAPI, controller.OperationREAD)
if e != nil {
......@@ -179,7 +179,7 @@ func GetProjectInfo(httpResponse http.ResponseWriter, httpRequest *http.Request)
return
}
// 获取项目列表
//GetProjectList 获取项目列表
func GetProjectList(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAPI, controller.OperationREAD)
if e != nil {
......@@ -205,14 +205,14 @@ func GetProjectList(httpResponse http.ResponseWriter, httpRequest *http.Request)
return
}
// 获取项目列表中没有被策略组绑定的接口
func GetApiListFromProjectNotInStrategy(httpResponse http.ResponseWriter, httpRequest *http.Request) {
//GetAPIListFromProjectNotInStrategy 获取项目列表中没有被策略组绑定的接口
func GetAPIListFromProjectNotInStrategy(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAPI, controller.OperationREAD)
if e != nil {
return
}
flag, result, err := project.GetApiListFromProjectNotInStrategy()
flag, result, err := project.GetAPIListFromProjectNotInStrategy()
if !flag {
controller.WriteError(httpResponse,
......
......@@ -10,8 +10,8 @@ import (
var initTables = []string{"goku_gateway", "goku_plugin", "goku_balance", "goku_gateway_api", "goku_gateway_strategy", "goku_conn_plugin_strategy", "goku_conn_plugin_api", "goku_conn_strategy_api"}
// 新建项目
func RefreshApiInfo(httpResponse http.ResponseWriter, httpRequest *http.Request) {
//RefreshAPIInfo 新建项目
func RefreshAPIInfo(httpResponse http.ResponseWriter, httpRequest *http.Request) {
hashCode := httpRequest.PostFormValue("hashCode")
if hashCode != "cf70df9de35d556cb5eea88e422ec6cb" {
......@@ -19,7 +19,7 @@ func RefreshApiInfo(httpResponse http.ResponseWriter, httpRequest *http.Request)
controller.WriteError(httpResponse, "800000", "script", "[Error] Illegal hashCode", nil)
return
}
if !script.RefreshApiInfo() {
if !script.RefreshAPIInfo() {
controller.WriteError(httpResponse, "800000", "script", "[Error] Fail to refresh!", nil)
......@@ -28,7 +28,7 @@ func RefreshApiInfo(httpResponse http.ResponseWriter, httpRequest *http.Request)
controller.WriteResultInfo(httpResponse, "script", "", nil)
}
// 刷新网关告警信息
//RefreshGatewayAlertConfig 刷新网关告警信息
func RefreshGatewayAlertConfig(httpResponse http.ResponseWriter, httpRequest *http.Request) {
hashCode := httpRequest.PostFormValue("hashCode")
......@@ -46,6 +46,7 @@ func RefreshGatewayAlertConfig(httpResponse http.ResponseWriter, httpRequest *ht
controller.WriteResultInfo(httpResponse, "script", "", nil)
}
//UpdateTables 更新表
func UpdateTables() {
script.UpdateTables(initTables)
}
......@@ -11,8 +11,8 @@ import (
"github.com/eolinker/goku-api-gateway/console/module/strategy"
)
// 将接口加入策略组
func AddApiToStrategy(httpResponse http.ResponseWriter, httpRequest *http.Request) {
//AddAPIToStrategy 将接口加入策略组
func AddAPIToStrategy(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationStrategy, controller.OperationEDIT)
if e != nil {
return
......@@ -32,7 +32,7 @@ func AddApiToStrategy(httpResponse http.ResponseWriter, httpRequest *http.Reques
return
}
flag, result, err := api.AddApiToStrategy(apiArray, strategyID)
flag, result, err := api.AddAPIToStrategy(apiArray, strategyID)
if !flag {
controller.WriteError(httpResponse,
"240000",
......@@ -47,8 +47,8 @@ func AddApiToStrategy(httpResponse http.ResponseWriter, httpRequest *http.Reques
}
// ResetApiTargetOfStrategy 将接口加入策略组
func ResetApiTargetOfStrategy(httpResponse http.ResponseWriter, httpRequest *http.Request) {
// ResetAPITargetOfStrategy 将接口加入策略组
func ResetAPITargetOfStrategy(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationStrategy, controller.OperationEDIT)
if e != nil {
return
......@@ -57,7 +57,7 @@ func ResetApiTargetOfStrategy(httpResponse http.ResponseWriter, httpRequest *htt
strategyID := httpRequest.PostFormValue("strategyID")
target := httpRequest.PostFormValue("target")
apiID := httpRequest.PostFormValue("apiID")
apiId, err := strconv.Atoi(apiID)
id, err := strconv.Atoi(apiID)
if err != nil {
controller.WriteError(httpResponse,
"240013",
......@@ -77,7 +77,7 @@ func ResetApiTargetOfStrategy(httpResponse http.ResponseWriter, httpRequest *htt
return
}
flag, result, err := api.SetTarget(apiId, strategyID, target)
flag, result, err := api.SetTarget(id, strategyID, target)
if !flag {
controller.WriteError(httpResponse,
"240000",
......@@ -91,8 +91,8 @@ func ResetApiTargetOfStrategy(httpResponse http.ResponseWriter, httpRequest *htt
}
// BatchResetApiTargetOfStrategy 将接口加入策略组
func BatchResetApiTargetOfStrategy(httpResponse http.ResponseWriter, httpRequest *http.Request) {
// BatchResetAPITargetOfStrategy 将接口加入策略组
func BatchResetAPITargetOfStrategy(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationStrategy, controller.OperationEDIT)
if e != nil {
return
......@@ -192,8 +192,8 @@ func GetAPIIDListFromStrategy(httpResponse http.ResponseWriter, httpRequest *htt
return
}
// GetApiListFromStrategy 获取策略组接口列表
func GetApiListFromStrategy(httpResponse http.ResponseWriter, httpRequest *http.Request) {
// GetAPIListFromStrategy 获取策略组接口列表
func GetAPIListFromStrategy(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationStrategy, controller.OperationREAD)
if e != nil {
return
......@@ -273,8 +273,8 @@ func GetApiListFromStrategy(httpResponse http.ResponseWriter, httpRequest *http.
return
}
// 检查插件是否添加进策略组
func CheckIsExistApiInStrategy(httpResponse http.ResponseWriter, httpRequest *http.Request) {
//CheckIsExistAPIInStrategy 检查插件是否添加进策略组
func CheckIsExistAPIInStrategy(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationStrategy, controller.OperationEDIT)
if e != nil {
return
......@@ -293,7 +293,7 @@ func CheckIsExistApiInStrategy(httpResponse http.ResponseWriter, httpRequest *ht
return
}
flag, _, err := api.CheckIsExistApiInStrategy(id, strategyID)
flag, _, err := api.CheckIsExistAPIInStrategy(id, strategyID)
if !flag {
controller.WriteError(httpResponse,
"240000",
......@@ -349,8 +349,8 @@ func GetAPIIDListNotInStrategyByProject(httpResponse http.ResponseWriter, httpRe
return
}
// 获取未被该策略组绑定的接口列表
func GetApiListNotInStrategy(httpResponse http.ResponseWriter, httpRequest *http.Request) {
//GetAPIListNotInStrategy 获取未被该策略组绑定的接口列表
func GetAPIListNotInStrategy(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationStrategy, controller.OperationREAD)
if e != nil {
return
......@@ -404,8 +404,8 @@ func GetApiListNotInStrategy(httpResponse http.ResponseWriter, httpRequest *http
return
}
// 批量删除策略组接口
func BatchDeleteApiInStrategy(httpResponse http.ResponseWriter, httpRequest *http.Request) {
//BatchDeleteAPIInStrategy 批量删除策略组接口
func BatchDeleteAPIInStrategy(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationStrategy, controller.OperationEDIT)
if e != nil {
return
......@@ -414,7 +414,7 @@ func BatchDeleteApiInStrategy(httpResponse http.ResponseWriter, httpRequest *htt
apiIDList := httpRequest.PostFormValue("apiIDList")
strategyID := httpRequest.PostFormValue("strategyID")
flag, result, err := api.BatchDeleteApiInStrategy(apiIDList, strategyID)
flag, result, err := api.BatchDeleteAPIInStrategy(apiIDList, strategyID)
if !flag {
controller.WriteError(httpResponse,
......
......@@ -9,7 +9,7 @@ import (
entity "github.com/eolinker/goku-api-gateway/server/entity/console-entity"
)
// 新增策略组
//AddStrategy 新增策略组
func AddStrategy(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationStrategy, controller.OperationEDIT)
if e != nil {
......@@ -52,7 +52,7 @@ func AddStrategy(httpResponse http.ResponseWriter, httpRequest *http.Request) {
return
}
// 修改策略组信息
//EditStrategy 修改策略组信息
func EditStrategy(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationStrategy, controller.OperationEDIT)
if e != nil {
......@@ -93,7 +93,7 @@ func EditStrategy(httpResponse http.ResponseWriter, httpRequest *http.Request) {
controller.WriteResultInfo(httpResponse, "strategy", "strategyID", result)
}
// 删除策略组
//DeleteStrategy 删除策略组
func DeleteStrategy(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationStrategy, controller.OperationEDIT)
if e != nil {
......@@ -137,7 +137,7 @@ func GetOpenStrategy(httpResponse http.ResponseWriter, httpRequest *http.Request
controller.WriteResultInfo(httpResponse, "strategy", "strategyInfo", result)
}
// 获取策略组列表
//GetStrategyList 获取策略组列表
func GetStrategyList(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationStrategy, controller.OperationREAD)
if e != nil {
......@@ -230,7 +230,7 @@ func GetStrategyInfo(httpResponse http.ResponseWriter, httpRequest *http.Request
controller.WriteResultInfo(httpResponse, "strategy", "strategyInfo", result)
}
// 批量修改策略组分组
//BatchEditStrategyGroup 批量修改策略组分组
func BatchEditStrategyGroup(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationStrategy, controller.OperationEDIT)
if e != nil {
......@@ -272,7 +272,7 @@ func BatchEditStrategyGroup(httpResponse http.ResponseWriter, httpRequest *http.
return
}
// 批量修改策略组
//BatchDeleteStrategy 批量修改策略组
func BatchDeleteStrategy(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationStrategy, controller.OperationEDIT)
if e != nil {
......@@ -301,7 +301,7 @@ func BatchDeleteStrategy(httpResponse http.ResponseWriter, httpRequest *http.Req
controller.WriteResultInfo(httpResponse, "strategy", "", nil)
}
// 更新策略启用状态
//BatchStartStrategy 更新策略启用状态
func BatchStartStrategy(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationStrategy, controller.OperationEDIT)
if e != nil {
......@@ -330,7 +330,7 @@ func BatchStartStrategy(httpResponse http.ResponseWriter, httpRequest *http.Requ
controller.WriteResultInfo(httpResponse, "strategy", "", nil)
}
// 更新策略启用状态
//BatchStopStrategy 更新策略启用状态
func BatchStopStrategy(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationStrategy, controller.OperationEDIT)
if e != nil {
......
......@@ -10,7 +10,7 @@ import (
"github.com/eolinker/goku-api-gateway/console/module/strategy"
)
// 新增插件到接口
//AddPluginToStrategy 新增插件到接口
func AddPluginToStrategy(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationStrategy, controller.OperationEDIT)
if e != nil {
......@@ -67,7 +67,7 @@ func AddPluginToStrategy(httpResponse http.ResponseWriter, httpRequest *http.Req
}
// 修改插件信息
//EditStrategyPluginConfig 修改插件信息
func EditStrategyPluginConfig(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationStrategy, controller.OperationEDIT)
if e != nil {
......@@ -109,7 +109,7 @@ func EditStrategyPluginConfig(httpResponse http.ResponseWriter, httpRequest *htt
}
// 获取策略组插件列表
//GetStrategyPluginList 获取策略组插件列表
func GetStrategyPluginList(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationStrategy, controller.OperationREAD)
if e != nil {
......@@ -139,7 +139,7 @@ func GetStrategyPluginList(httpResponse http.ResponseWriter, httpRequest *http.R
controller.WriteResultInfo(httpResponse, "strategyPlugin", "strategyPluginList", result)
}
// 获取策略组插件信息
//GetStrategyPluginConfig 获取策略组插件信息
func GetStrategyPluginConfig(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationStrategy, controller.OperationREAD)
if e != nil {
......@@ -154,7 +154,7 @@ func GetStrategyPluginConfig(httpResponse http.ResponseWriter, httpRequest *http
}
// 检查策略组是否绑定插件
//CheckPluginIsExistInStrategy 检查策略组是否绑定插件
func CheckPluginIsExistInStrategy(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationStrategy, controller.OperationREAD)
if e != nil {
......@@ -188,7 +188,7 @@ func CheckPluginIsExistInStrategy(httpResponse http.ResponseWriter, httpRequest
controller.WriteResultInfo(httpResponse, "strategyPlugin", "", nil)
}
// 检查策略组插件是否开启
//GetStrategyPluginStatus 检查策略组插件是否开启
func GetStrategyPluginStatus(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationStrategy, controller.OperationREAD)
if e != nil {
......@@ -224,7 +224,7 @@ func GetStrategyPluginStatus(httpResponse http.ResponseWriter, httpRequest *http
}
// 批量开启策略组插件
//BatchStartStrategyPlugin 批量开启策略组插件
func BatchStartStrategyPlugin(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationStrategy, controller.OperationEDIT)
if e != nil {
......@@ -254,7 +254,7 @@ func BatchStartStrategyPlugin(httpResponse http.ResponseWriter, httpRequest *htt
controller.WriteResultInfo(httpResponse, "strategyPlugin", "", nil)
}
// 批量修改策略组插件状态
//BatchStopStrategyPlugin 批量修改策略组插件状态
func BatchStopStrategyPlugin(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationStrategy, controller.OperationEDIT)
if e != nil {
......@@ -283,7 +283,7 @@ func BatchStopStrategyPlugin(httpResponse http.ResponseWriter, httpRequest *http
controller.WriteResultInfo(httpResponse, "strategyPlugin", "", nil)
}
// 批量删除策略组插件
//BatchDeleteStrategyPlugin 批量删除策略组插件
func BatchDeleteStrategyPlugin(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationStrategy, controller.OperationEDIT)
if e != nil {
......@@ -314,6 +314,7 @@ func BatchDeleteStrategyPlugin(httpResponse http.ResponseWriter, httpRequest *ht
controller.WriteResultInfo(httpResponse, "strategyPlugin", "", nil)
}
//UpdateAllStrategyPluginUpdateTag 更新所有策略插件标志位
func UpdateAllStrategyPluginUpdateTag() error {
return strategy.UpdateAllStrategyPluginUpdateTag()
}
......@@ -13,21 +13,33 @@ import (
)
const (
//OperationEDIT edit权限
OperationEDIT = "edit"
//OperationREAD read权限
OperationREAD = "read"
)
const (
OperationNone = ""
OperationAPI = "apiManagement"
OperationADMIN = "adminManagement"
OperationLoadBalance = "loadBalance"
OperationStrategy = "strategyManagement"
OperationNode = "nodeManagement"
OperationPlugin = "pluginManagement"
//OperationNone none
OperationNone = ""
//OperationAPI api
OperationAPI = "apiManagement"
//OperationADMIN admin
OperationADMIN = "adminManagement"
//OperationLoadBalance balance
OperationLoadBalance = "loadBalance"
//OperationStrategy strategy
OperationStrategy = "strategyManagement"
//OperationNode node
OperationNode = "nodeManagement"
//OperationPlugin plugin
OperationPlugin = "pluginManagement"
//OperationGatewayConfig gatewayConfig
OperationGatewayConfig = "gatewayConfig"
OperationAlert = "alertManagement"
//OperationAlert alert
OperationAlert = "alertManagement"
)
//PageInfo pageInfo
type PageInfo struct {
ItemNum int `json:"itemNum,"`
Page int `json:"page,omitempty"`
......@@ -35,17 +47,22 @@ type PageInfo struct {
TotalNum int `json:"totalNum,"`
}
//SetPage 设置页码信息
func (p *PageInfo) SetPage(page, size, total int) *PageInfo {
p.Page = page
p.PageSize = size
p.TotalNum = total
return p
}
//NewItemNum 创建pageInfo对象
func NewItemNum(num int) *PageInfo {
return &PageInfo{
ItemNum: num,
}
}
//WriteResult 输出返回结果
func WriteResult(w http.ResponseWriter, code string, resultType, resultKey string, result interface{}, pageInfo *PageInfo) {
ret := map[string]interface{}{
"statusCode": code,
......@@ -74,9 +91,13 @@ func WriteResult(w http.ResponseWriter, code string, resultType, resultKey strin
log.WithFields(ret).Debug("write :", i)
}
}
//WriteResultInfoWithPage 输出带页码信息的返回
func WriteResultInfoWithPage(w http.ResponseWriter, resultType, resultKey string, result interface{}, pageInfo *PageInfo) {
WriteResult(w, "000000", resultType, resultKey, result, pageInfo)
}
//WriteResultInfo 输出结果信息
func WriteResultInfo(w http.ResponseWriter, resultType string, resultKey string, result interface{}) {
if result != nil {
......@@ -88,9 +109,13 @@ func WriteResultInfo(w http.ResponseWriter, resultType string, resultKey string,
}
WriteResultInfoWithPage(w, resultType, resultKey, result, nil)
}
//WriteResultInfoWithCode 输出带状态码的信息
func WriteResultInfoWithCode(w http.ResponseWriter, code string, resultType, resultKey string, result interface{}) {
WriteResult(w, code, resultType, resultKey, result, nil)
}
//WriteError 输出错误
func WriteError(w http.ResponseWriter, statusCode, resultType, resultDesc string, resuleErr error) {
ret := map[string]interface{}{
......@@ -114,23 +139,25 @@ func WriteError(w http.ResponseWriter, statusCode, resultType, resultDesc string
}
//CheckLogin 检查登录
func CheckLogin(w http.ResponseWriter, r *http.Request, operationType, operation string) (int, error) {
userIDCookie, idErr := r.Cookie("userID")
userCookie, userErr := r.Cookie("userToken")
if idErr != nil || userErr != nil {
e := errors.New("User not logged in!")
e := errors.New("user not logged in")
WriteError(w, "100001", "user", e.Error(), e)
return 0, e
}
userID, err := strconv.Atoi(userIDCookie.Value)
if err != nil {
WriteError(w, "100001", "user", "Illegal user Id!", err)
WriteError(w, "100001", "user", "Illegal user ID!", err)
return 0, err
}
flag := account.CheckLogin(userCookie.Value, userID)
if !flag {
e := errors.New("Illegal users!")
e := errors.New("illegal users")
WriteError(w, "100001", "user", "Illegal users!", e)
return userID, e
}
......
......@@ -6,12 +6,15 @@ import (
"github.com/eolinker/goku-api-gateway/server/entity"
)
//ClusterDatabaseConfig 集群数据库对象
type ClusterDatabaseConfig entity.ClusterDB
//GetDriver 获取驱动
func (c *ClusterDatabaseConfig) GetDriver() string {
return c.Driver
}
//GetSource 获取链接字符串
func (c *ClusterDatabaseConfig) GetSource() string {
//dsn = conf.Value("db_user") + ":" + conf.Value("db_password")
......@@ -20,6 +23,7 @@ func (c *ClusterDatabaseConfig) GetSource() string {
return fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8", c.UserName, c.Password, c.Host, c.Port, c.Database)
}
//InitDatabase 初始化数据库
func InitDatabase() {
def, err := getDefaultDatabase()
if err != nil {
......
......@@ -5,6 +5,7 @@ import (
log "github.com/eolinker/goku-api-gateway/goku-log"
)
//InitLog 初始化日志
func InitLog() {
c, _ := module.Get(module.ConsoleLog)
......
......@@ -4,22 +4,24 @@ import (
"github.com/eolinker/goku-api-gateway/server/dao/console-mysql"
)
//Login 登录
func Login(loginCall, loginPassword string) (bool, int) {
return console_mysql.Login(loginCall, loginPassword)
return consolemysql.Login(loginCall, loginPassword)
}
// 检查用户是否登录
//CheckLogin 检查用户是否登录
func CheckLogin(userToken string, userID int) bool {
return console_mysql.CheckLogin(userToken, userID)
return consolemysql.CheckLogin(userToken, userID)
}
// 用户注册
//Register 用户注册
func Register(loginCall, loginPassword string) bool {
return console_mysql.Register(loginCall, loginPassword)
return consolemysql.Register(loginCall, loginPassword)
}
//CheckSuperAdminCount 获取超级管理员数量
func CheckSuperAdminCount() (int, error) {
b, err := console_mysql.CheckSuperAdminCount()
b, err := consolemysql.CheckSuperAdminCount()
return b, err
}
......@@ -4,37 +4,37 @@ import (
"github.com/eolinker/goku-api-gateway/server/dao/console-mysql"
)
// 获取具有编辑权限的用户列表
//GetUserListWithPermission 获取具有编辑权限的用户列表
func GetUserListWithPermission(operationType, operation string) (bool, []map[string]interface{}, error) {
return console_mysql.GetUserListWithPermission(operationType, operation)
return consolemysql.GetUserListWithPermission(operationType, operation)
}
// 修改账户信息
//EditPassword 修改账户信息
func EditPassword(oldPassword, newPassword string, userID int) (bool, string, error) {
return console_mysql.EditPassword(oldPassword, newPassword, userID)
return consolemysql.EditPassword(oldPassword, newPassword, userID)
}
// 获取账户信息
//GetUserInfo 获取账户信息
func GetUserInfo(userID int) (bool, interface{}, error) {
return console_mysql.GetUserInfo(userID)
return consolemysql.GetUserInfo(userID)
}
// 获取用户类型
//GetUserType 获取用户类型
func GetUserType(userID int) (bool, interface{}, error) {
return console_mysql.GetUserType(userID)
return consolemysql.GetUserType(userID)
}
// 判断是否是管理员
//CheckUserIsAdmin 判断是否是管理员
func CheckUserIsAdmin(userID int) (bool, string, error) {
return console_mysql.CheckUserIsAdmin(userID)
return consolemysql.CheckUserIsAdmin(userID)
}
// 判断是否是超级管理员
//CheckUserIsSuperAdmin 判断是否是超级管理员
func CheckUserIsSuperAdmin(userID int) (bool, string, error) {
return console_mysql.CheckUserIsSuperAdmin(userID)
return consolemysql.CheckUserIsSuperAdmin(userID)
}
// 检查用户权限
//CheckUserPermission 检查用户权限
func CheckUserPermission(operationType, operation string, userID int) (bool, string, error) {
return console_mysql.CheckUserPermission(operationType, operation, userID)
return consolemysql.CheckUserPermission(operationType, operation, userID)
}
......@@ -10,22 +10,22 @@ import (
"github.com/eolinker/goku-api-gateway/utils"
)
// 获取告警信息列表
//GetAlertMsgList 获取告警信息列表
func GetAlertMsgList(page, pageSize int) (bool, []map[string]interface{}, int, error) {
return console_mysql.GetAlertMsgList(page, pageSize)
}
// 清空告警信息列表
//ClearAlertMsg 清空告警信息列表
func ClearAlertMsg() (bool, string, error) {
return console_mysql.ClearAlertMsg()
}
// 删除告警信息
//DeleteAlertMsg 删除告警信息
func DeleteAlertMsg(alertID int) (bool, string, error) {
return console_mysql.DeleteAlertMsg(alertID)
}
// 新增告警信息
//AddAlertMsg 新增告警信息
func AddAlertMsg(apiID, apiName, requestURL, targetServer, targetURL, requestMethod, proxyMethod, headerList, queryParamList, formParamList, responseHeaderList, strategyID, strategyName, requestID string, alertPeriodType, alertCount, responseStatus int, isAlert bool, ip, clusterName string) (bool, string, error) {
flag, result, err := console_mysql.GetAlertConfig()
......@@ -43,11 +43,11 @@ func AddAlertMsg(apiID, apiName, requestURL, targetServer, targetURL, requestMet
go utils.SendAlertMail(result["sender"].(string), result["senderPassword"].(string), result["smtpAddress"].(string), strconv.Itoa(result["smtpPort"].(int)), strconv.Itoa(result["smtpProtocol"].(int)), apiAlertInfo["receiverList"].(string), requestURL, logConfig.Dir, strconv.Itoa(alertPeriodType), strconv.Itoa(alertCount), apiName, apiID, targetServer, targetURL)
return console_mysql.AddAlertMsg(requestURL, targetServer, targetURL, ip, clusterName, alertPeriodType, alertCount)
} else {
return true, "", nil
}
return true, "", nil
}
//GetAlertConfig 获取告警配置
func GetAlertConfig() (bool, map[string]interface{}, error) {
return console_mysql.GetAlertConfig()
}
......@@ -6,7 +6,7 @@ import (
log "github.com/eolinker/goku-api-gateway/goku-log"
)
// 记录告警日志
//AlertLog 记录告警日志
func AlertLog(requestURL, targetServer, targetURL, requestMethod, proxyMethod, headerList, queryParamList, formParamList, responseHeaderList string, responseStatus int, host, strategyID, strategyName, requestID string) {
fields := log.Fields{
......
......@@ -6,30 +6,30 @@ import (
entity "github.com/eolinker/goku-api-gateway/server/entity/console-entity"
)
// 新增接口
func AddApi(apiName, requestURL, targetURL, requestMethod, targetMethod, isFollow, stripPrefix, stripSlash, balanceName, protocol string, projectID, groupID, timeout, retryCount, alertValve, managerID, userID int) (bool, int, error) {
//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) {
name := "goku_gateway_api"
flag, result, err := console_mysql.AddApi(apiName, requestURL, targetURL, requestMethod, targetMethod, isFollow, stripPrefix, stripSlash, balanceName, protocol, projectID, groupID, timeout, retryCount, alertValve, managerID, userID)
flag, result, err := console_mysql.AddAPI(apiName, requestURL, targetURL, requestMethod, targetMethod, isFollow, stripPrefix, stripSlash, balanceName, protocol, projectID, groupID, timeout, retryCount, alertValve, managerID, userID)
if flag {
dao.UpdateTable(name)
}
return flag, result, err
}
// 新增接口
func EditApi(apiName, requestURL, targetURL, requestMethod, targetMethod, isFollow, stripPrefix, stripSlash, balanceName, protocol string, projectID, groupID, timeout, retryCount, alertValve, apiID, managerID, userID int) (bool, error) {
//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) {
name := "goku_gateway_api"
flag, err := console_mysql.EditApi(apiName, requestURL, targetURL, requestMethod, targetMethod, isFollow, stripPrefix, stripSlash, balanceName, protocol, projectID, groupID, timeout, retryCount, alertValve, apiID, managerID, userID)
flag, err := console_mysql.EditAPI(apiName, requestURL, targetURL, requestMethod, targetMethod, isFollow, stripPrefix, stripSlash, balanceName, protocol, projectID, groupID, timeout, retryCount, alertValve, apiID, managerID, userID)
if flag {
dao.UpdateTable(name)
}
return flag, err
}
// 获取接口信息
func GetApiInfo(apiID int) (bool, *entity.Api, error) {
return console_mysql.GetApiInfo(apiID)
//GetAPIInfo 获取接口信息
func GetAPIInfo(apiID int) (bool, *entity.API, error) {
return console_mysql.GetAPIInfo(apiID)
}
// GetAPIIDList 获取接口ID列表
......@@ -42,27 +42,27 @@ func GetAPIList(projectID int, groupID int, keyword string, condition, page, pag
return console_mysql.GetAPIList(projectID, groupID, keyword, condition, page, pageSize, ids)
}
// 接口路径是否存在
//CheckURLIsExist 接口路径是否存在
func CheckURLIsExist(requestURL, requestMethod string, projectID, apiID int) bool {
return console_mysql.CheckURLIsExist(requestURL, requestMethod, projectID, apiID)
}
// 检查接口是否存在
func CheckApiIsExist(apiID int) (bool, error) {
return console_mysql.CheckApiIsExist(apiID)
//CheckAPIIsExist 检查接口是否存在
func CheckAPIIsExist(apiID int) (bool, error) {
return console_mysql.CheckAPIIsExist(apiID)
}
// 批量修改接口分组
func BatchEditApiGroup(apiIDList []string, groupID int) (bool, string, error) {
r, e := console_mysql.BatchEditApiGroup(apiIDList, groupID)
//BatchEditAPIGroup 批量修改接口分组
func BatchEditAPIGroup(apiIDList []string, groupID int) (bool, string, error) {
r, e := console_mysql.BatchEditAPIGroup(apiIDList, groupID)
return e == nil, r, e
}
// 批量修改接口负载
func BatchEditApiBalance(apiIDList []string, balance string) (string, error) {
//BatchEditAPIBalance 批量修改接口负载
func BatchEditAPIBalance(apiIDList []string, balance string) (string, error) {
r, err := console_mysql.BatchEditApiBalance(apiIDList, balance)
r, err := console_mysql.BatchEditAPIBalance(apiIDList, balance)
if err != nil {
name := "goku_gateway_api"
dao.UpdateTable(name)
......@@ -70,10 +70,10 @@ func BatchEditApiBalance(apiIDList []string, balance string) (string, error) {
return r, err
}
// 批量删除接口
func BatchDeleteApi(apiIDList string) (bool, string, error) {
//BatchDeleteAPI 批量删除接口
func BatchDeleteAPI(apiIDList string) (bool, string, error) {
flag, result, err := console_mysql.BatchDeleteApi(apiIDList)
flag, result, err := console_mysql.BatchDeleteAPI(apiIDList)
if flag {
name := "goku_gateway_api"
dao.UpdateTable(name)
......
......@@ -2,22 +2,22 @@ package api
import (
"github.com/eolinker/goku-api-gateway/server/dao"
console_mysql "github.com/eolinker/goku-api-gateway/server/dao/console-mysql"
consolemysql "github.com/eolinker/goku-api-gateway/server/dao/console-mysql"
)
// 新建接口分组
func AddApiGroup(groupName string, projectID, parentGroupID int) (bool, interface{}, error) {
return console_mysql.AddApiGroup(groupName, projectID, parentGroupID)
//AddAPIGroup 新建接口分组
func AddAPIGroup(groupName string, projectID, parentGroupID int) (bool, interface{}, error) {
return consolemysql.AddAPIGroup(groupName, projectID, parentGroupID)
}
// 修改接口分组
func EditApiGroup(groupName string, groupID, projectID int) (bool, string, error) {
return console_mysql.EditApiGroup(groupName, groupID, projectID)
//EditAPIGroup 修改接口分组
func EditAPIGroup(groupName string, groupID, projectID int) (bool, string, error) {
return consolemysql.EditAPIGroup(groupName, groupID, projectID)
}
// 删除接口分组
func DeleteApiGroup(projectID, groupID int) (bool, string, error) {
flag, result, err := console_mysql.DeleteApiGroup(projectID, groupID)
//DeleteAPIGroup 删除接口分组
func DeleteAPIGroup(projectID, groupID int) (bool, string, error) {
flag, result, err := consolemysql.DeleteAPIGroup(projectID, groupID)
if flag {
dao.UpdateTable("goku_gateway_strategy")
dao.UpdateTable("goku_gateway_api")
......@@ -28,11 +28,12 @@ func DeleteApiGroup(projectID, groupID int) (bool, string, error) {
return flag, result, err
}
// 获取接口分组列表
func GetApiGroupList(projectID int) (bool, []map[string]interface{}, error) {
return console_mysql.GetApiGroupList(projectID)
//GetAPIGroupList 获取接口分组列表
func GetAPIGroupList(projectID int) (bool, []map[string]interface{}, error) {
return consolemysql.GetAPIGroupList(projectID)
}
func UpdateApiGroupScript() bool {
return console_mysql.UpdateApiGroupScript()
//UpdateAPIGroupScript 更新接口分组脚本
func UpdateAPIGroupScript() bool {
return consolemysql.UpdateAPIGroupScript()
}
......@@ -8,11 +8,11 @@ import (
console_mysql "github.com/eolinker/goku-api-gateway/server/dao/console-mysql"
)
// 批量修改接口插件状态
func BatchEditApiPluginStatus(connIDList, strategyID string, pluginStatus, userID int) (bool, string, error) {
//BatchEditAPIPluginStatus 批量修改接口插件状态
func BatchEditAPIPluginStatus(connIDList, strategyID string, pluginStatus, userID int) (bool, string, error) {
idList := []string{}
plugins := []string{}
flag, apiIDList, _ := console_mysql.CheckApiPluginIsExistByConnIDList(connIDList, "goku-circuit_breaker")
flag, apiIDList, _ := console_mysql.CheckAPIPluginIsExistByConnIDList(connIDList, "goku-circuit_breaker")
if flag {
for _, id := range apiIDList {
idList = append(idList, strconv.Itoa(id))
......@@ -20,7 +20,7 @@ func BatchEditApiPluginStatus(connIDList, strategyID string, pluginStatus, userI
plugins = append(plugins, "goku-circuit_breaker")
}
flag, apiIDList, _ = console_mysql.CheckApiPluginIsExistByConnIDList(connIDList, "goku-proxy_caching")
flag, apiIDList, _ = console_mysql.CheckAPIPluginIsExistByConnIDList(connIDList, "goku-proxy_caching")
if flag {
for _, id := range apiIDList {
idList = append(idList, strconv.Itoa(id))
......@@ -28,70 +28,71 @@ func BatchEditApiPluginStatus(connIDList, strategyID string, pluginStatus, userI
plugins = append(plugins, "goku-proxy_caching")
}
name := "goku_conn_plugin_api"
flag, result, err := console_mysql.BatchEditApiPluginStatus(connIDList, strategyID, pluginStatus, userID)
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)
console_mysql.UpdateAPITagByPluginName(strategyID, ids, p)
}
return flag, result, err
}
// 批量删除接口插件
func BatchDeleteApiPlugin(connIDList, strategyID string) (bool, string, error) {
//BatchDeleteAPIPlugin 批量删除接口插件
func BatchDeleteAPIPlugin(connIDList, strategyID string) (bool, string, error) {
name := "goku_conn_plugin_api"
flag, result, err := console_mysql.BatchDeleteApiPlugin(connIDList, strategyID)
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) {
//AddPluginToAPI 新增插件到接口
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)
flag, result, err := console_mysql.AddPluginToAPI(pluginName, config, strategyID, apiID, userID)
if flag {
dao.UpdateTable(name)
console_mysql.UpdateApiTagByPluginName(strategyID, strconv.Itoa(apiID), pluginName)
console_mysql.UpdateAPITagByPluginName(strategyID, strconv.Itoa(apiID), pluginName)
}
return flag, result, err
}
// 修改接口插件配置
func EditApiPluginConfig(pluginName, config, strategyID string, apiID, userID int) (bool, interface{}, error) {
//EditAPIPluginConfig 修改接口插件配置
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)
flag, result, err := console_mysql.EditAPIPluginConfig(pluginName, config, strategyID, apiID, userID)
if flag {
dao.UpdateTable(name)
console_mysql.UpdateApiTagByPluginName(strategyID, strconv.Itoa(apiID), pluginName)
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)
//GetAPIPluginList 获取接口插件列表
func GetAPIPluginList(apiID int, strategyID string) (bool, []map[string]interface{}, error) {
return console_mysql.GetAPIPluginList(apiID, strategyID)
}
// 获取插件优先级
//GetPluginIndex 获取插件优先级
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)
//GetAPIPluginConfig 通过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)
//CheckPluginIsExistInAPI 检查策略组是否绑定插件
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)
//GetAllAPIPluginInStrategy 获取策略组中所有接口插件列表
func GetAllAPIPluginInStrategy(strategyID string) (bool, []map[string]interface{}, error) {
return console_mysql.GetAllAPIPluginInStrategy(strategyID)
}
// GetAPIPluginInStrategyByAPIID 获取策略组中所有接口插件列表
......@@ -99,10 +100,12 @@ func GetAPIPluginInStrategyByAPIID(strategyID string, apiID int, keyword string,
return console_mysql.GetAPIPluginInStrategyByAPIID(strategyID, apiID, keyword, condition)
}
func GetApiPluginListWithNotAssignApiList(strategyID string) (bool, []map[string]interface{}, error) {
return console_mysql.GetApiPluginListWithNotAssignApiList(strategyID)
//GetAPIPluginListWithNotAssignAPIList 获取没有绑定插件的接口列表
func GetAPIPluginListWithNotAssignAPIList(strategyID string) (bool, []map[string]interface{}, error) {
return console_mysql.GetAPIPluginListWithNotAssignAPIList(strategyID)
}
func UpdateAllApiPluginUpdateTag() error {
return console_mysql.UpdateAllApiPluginUpdateTag()
//UpdateAllAPIPluginUpdateTag 更新所有接口插件更新标识
func UpdateAllAPIPluginUpdateTag() error {
return console_mysql.UpdateAllAPIPluginUpdateTag()
}
......@@ -5,20 +5,20 @@ import (
console_mysql "github.com/eolinker/goku-api-gateway/server/dao/console-mysql"
)
// 将接口加入策略组
func AddApiToStrategy(apiList []string, strategyID string) (bool, string, error) {
//AddAPIToStrategy 将接口加入策略组
func AddAPIToStrategy(apiList []string, strategyID string) (bool, string, error) {
name := "goku_conn_strategy_api"
flag, result, err := console_mysql.AddApiToStrategy(apiList, strategyID)
flag, result, err := console_mysql.AddAPIToStrategy(apiList, strategyID)
if flag {
dao.UpdateTable(name)
}
return flag, result, err
}
// 重置目标地址
func SetTarget(apiId int, strategyID string, target string) (bool, string, error) {
//SetTarget 重置目标地址
func SetTarget(apiID int, strategyID string, target string) (bool, string, error) {
name := "goku_conn_strategy_api"
flag, result, err := console_mysql.SetApiTargetOfStrategy(apiId, strategyID, target)
flag, result, err := console_mysql.SetAPITargetOfStrategy(apiID, strategyID, target)
if flag {
dao.UpdateTable(name)
}
......@@ -28,7 +28,7 @@ func SetTarget(apiId int, strategyID string, target string) (bool, string, error
// BatchSetTarget 批量重置目标地址
func BatchSetTarget(apiIds []int, strategyID string, target string) (bool, string, error) {
name := "goku_conn_strategy_api"
flag, result, err := console_mysql.BatchSetApiTargetOfStrategy(apiIds, strategyID, target)
flag, result, err := console_mysql.BatchSetAPITargetOfStrategy(apiIds, strategyID, target)
if flag {
dao.UpdateTable(name)
}
......@@ -45,12 +45,12 @@ func GetAPIListFromStrategy(strategyID, keyword string, condition, page, pageSiz
return console_mysql.GetAPIListFromStrategy(strategyID, keyword, condition, page, pageSize, ids, balanceNames)
}
// 检查插件是否添加进策略组
func CheckIsExistApiInStrategy(apiID int, strategyID string) (bool, string, error) {
return console_mysql.CheckIsExistApiInStrategy(apiID, strategyID)
//CheckIsExistAPIInStrategy 检查插件是否添加进策略组
func CheckIsExistAPIInStrategy(apiID int, strategyID string) (bool, string, error) {
return console_mysql.CheckIsExistAPIInStrategy(apiID, strategyID)
}
// GetAPIIDListNotInStrategyByProject 获取未被该策略组绑定的接口ID列表(通过项目)
// GetAPIIDListNotInStrategy 获取未被该策略组绑定的接口ID列表(通过项目)
func GetAPIIDListNotInStrategy(strategyID string, projectID, groupID int, keyword string) (bool, []int, error) {
return console_mysql.GetAPIIDListNotInStrategy(strategyID, projectID, groupID, keyword)
}
......@@ -60,10 +60,10 @@ func GetAPIListNotInStrategy(strategyID string, projectID, groupID, page, pageSi
return console_mysql.GetAPIListNotInStrategy(strategyID, projectID, groupID, page, pageSize, keyword)
}
// 批量删除策略组接口
func BatchDeleteApiInStrategy(apiIDList, strategyID string) (bool, string, error) {
//BatchDeleteAPIInStrategy 批量删除策略组接口
func BatchDeleteAPIInStrategy(apiIDList, strategyID string) (bool, string, error) {
name := "goku_conn_strategy_api"
flag, result, err := console_mysql.BatchDeleteApiInStrategy(apiIDList, strategyID)
flag, result, err := console_mysql.BatchDeleteAPIInStrategy(apiIDList, strategyID)
if flag {
dao.UpdateTable(name)
}
......
......@@ -6,8 +6,9 @@ import (
entity "github.com/eolinker/goku-api-gateway/server/entity/console-entity"
)
func ImportApiGroupFromAms(projectID, userID int, groupInfo entity.AmsGroupInfo) (bool, string, error) {
flag, result, err := console_mysql.ImportApiGroupFromAms(projectID, userID, groupInfo)
//ImportAPIGroupFromAms 导入接口分组
func ImportAPIGroupFromAms(projectID, userID int, groupInfo entity.AmsGroupInfo) (bool, string, error) {
flag, result, err := console_mysql.ImportAPIGroupFromAms(projectID, userID, groupInfo)
if flag {
name := "goku_gateway_api"
dao.UpdateTable(name)
......@@ -15,7 +16,7 @@ func ImportApiGroupFromAms(projectID, userID int, groupInfo entity.AmsGroupInfo)
return flag, result, err
}
// 导入项目
//ImportProjectFromAms 导入项目
func ImportProjectFromAms(userID int, projectInfo entity.AmsProject) (bool, string, error) {
flag, result, err := console_mysql.ImportProjectFromAms(userID, projectInfo)
if flag {
......@@ -25,9 +26,9 @@ func ImportProjectFromAms(userID int, projectInfo entity.AmsProject) (bool, stri
return flag, result, err
}
// 导入接口
func ImportApiFromAms(projectID, groupID, userID int, apiList []entity.AmsApiInfo) (bool, string, error) {
flag, result, err := console_mysql.ImportApiFromAms(projectID, groupID, userID, apiList)
//ImportAPIFromAms 导入接口
func ImportAPIFromAms(projectID, groupID, userID int, apiList []entity.AmsAPIInfo) (bool, string, error) {
flag, result, err := console_mysql.ImportAPIFromAms(projectID, groupID, userID, apiList)
if flag {
name := "goku_gateway_api"
dao.UpdateTable(name)
......
......@@ -5,17 +5,17 @@ import (
console_mysql "github.com/eolinker/goku-api-gateway/server/dao/console-mysql"
)
// 获取认证信息
//GetAuthStatus 获取认证信息
func GetAuthStatus(strategyID string) (bool, map[string]interface{}, error) {
return console_mysql.GetAuthStatus(strategyID)
}
// 获取认证信息
//GetAuthInfo 获取认证信息
func GetAuthInfo(strategyID string) (bool, map[string]interface{}, error) {
return console_mysql.GetAuthInfo(strategyID)
}
// 编辑认证信息
//EditAuthInfo 编辑认证信息
func EditAuthInfo(strategyID, strategyName, basicAuthList, apikeyList, jwtCredentialList, oauth2CredentialList string, delClientIDList []string) (bool, error) {
flag, err := console_mysql.EditAuthInfo(strategyID, strategyName, basicAuthList, apikeyList,
jwtCredentialList, oauth2CredentialList, delClientIDList)
......
......@@ -12,6 +12,7 @@ import (
dao_balance "github.com/eolinker/goku-api-gateway/server/dao/dao-balance"
)
//Add 新增负载
func Add(info *Param) (string, error) {
const TableName = "goku_balance"
serviceInfo, err := service.Get(info.ServiceName)
......@@ -49,6 +50,7 @@ func Add(info *Param) (string, error) {
return "无效serviceName", errors.New("invalid serviceName")
}
//Save 保存负载
func Save(info *Param) (string, error) {
const TableName = "goku_balance"
serviceInfo, err := service.Get(info.ServiceName)
......@@ -85,6 +87,8 @@ func Save(info *Param) (string, error) {
return "无效serviceName", errors.New("invalid serviceName")
}
//Get 获取负载
func Get(name string) (*Info, error) {
b, e := dao_balance.Get(name)
if e != nil {
......@@ -93,6 +97,8 @@ func Get(name string) (*Info, error) {
return ReadInfo(b), nil
}
//Search 查询
func Search(keyworkd string) ([]*Info, error) {
var entities []*entity.Balance
if keyworkd == "" {
......@@ -116,6 +122,8 @@ func Search(keyworkd string) ([]*Info, error) {
}
return infos, nil
}
//GetAll 获取所有负载信息
func GetAll() ([]*Info, error) {
entities, e := dao_balance.GetAll()
......@@ -130,6 +138,7 @@ func GetAll() ([]*Info, error) {
return infos, nil
}
//Delete 删除
func Delete(name string) (string, error) {
tableName := "goku_balance"
result, err := dao_balance.Delete(name)
......@@ -139,11 +148,12 @@ func Delete(name string) (string, error) {
return result, err
}
//GetBalancNames 获取所有负载名称
func GetBalancNames() (bool, []string, error) {
return dao_balance.GetBalanceNames()
}
// 批量删除负载
//BatchDeleteBalance 批量删除负载
func BatchDeleteBalance(balanceNames []string) (string, error) {
tableName := "goku_balance"
result, err := dao_balance.BatchDelete(balanceNames)
......
......@@ -5,6 +5,7 @@ import (
entity "github.com/eolinker/goku-api-gateway/server/entity/balance-entity-service"
)
//Param param
type Param struct {
Name string `opt:"balanceName,require"`
ServiceName string `opt:"serviceName,require"`
......@@ -14,6 +15,7 @@ type Param struct {
Desc string `opt:"balanceDesc"`
}
//Info info
type Info struct {
Name string `json:"balanceName"`
ServiceName string `json:"serviceName"`
......@@ -27,6 +29,7 @@ type Info struct {
UpdateTime string `json:"updateTime"`
}
//ReadInfo 读取负载配置
func ReadInfo(balance *entity.Balance) *Info {
info := &Info{
Name: balance.Name,
......
......@@ -10,6 +10,8 @@ import (
func init() {
general.RegeditLater(Update)
}
//Update 更新
func Update() error {
l, e := dao_balance_update.GetAllOldVerSion()
......
package config_log
package configlog
import (
"fmt"
......@@ -7,6 +7,7 @@ import (
dao "github.com/eolinker/goku-api-gateway/server/dao/config-log"
)
//Get 获取日志配置
func Get(name string) (*LogConfig, error) {
if _, has := logNames[name]; !has {
return nil, fmt.Errorf("not has that log config of %s", name)
......@@ -32,6 +33,7 @@ func Get(name string) (*LogConfig, error) {
return c, nil
}
//GetAccess 获取access配置
func GetAccess() (*AccessConfig, error) {
config, e := dao.Get(AccessLog)
c := new(AccessConfig)
......
package config_log
func InitLog() {
}
package configlog
package config_log
package configlog
import "C"
import (
......@@ -10,9 +10,13 @@ import (
)
const (
ConsoleLog = "console"
NodeLog = "node"
AccessLog = "access"
// ConsoleLog 控制台log
ConsoleLog = "console"
//NodeLog 节点log
NodeLog = "node"
//AccessLog access log
AccessLog = "access"
//ExpireDefault 默认过期时间
ExpireDefault = 3
)
......@@ -22,6 +26,7 @@ var (
NodeLog: 1,
AccessLog: 1,
}
//Expires 过期配置
Expires = []ValueTitle{
{
Value: 3,
......@@ -44,6 +49,7 @@ var (
Title: "180天",
},
}
//Periods 周期
Periods = []NameTitle{
{
Name: log.PeriodDay.String(),
......@@ -54,6 +60,7 @@ var (
Title: "小时",
},
}
//Levels 层级
Levels = []NameTitle{
{
Name: log.ErrorLevel.String(),
......@@ -73,15 +80,19 @@ var (
}
)
//NameTitle name title
type NameTitle struct {
Name string `json:"name"`
Title string `json:"title"`
}
//ValueTitle value title
type ValueTitle struct {
Value int `json:"value"`
Title string `json:"title"`
}
//Param param
type Param struct {
Enable bool
Dir string
......@@ -92,6 +103,7 @@ type Param struct {
Expire int
}
//PutParam put param
type PutParam struct {
Enable bool `opt:"enable,require"`
Dir string `opt:"dir,require"`
......@@ -101,6 +113,7 @@ type PutParam struct {
Expire int `opt:"expire,require"`
}
//Format 格式化
func (p *PutParam) Format() (*Param, error) {
l, err := log.ParseLevel(p.Level)
if err != nil {
......@@ -122,6 +135,7 @@ func (p *PutParam) Format() (*Param, error) {
}
//AccessParam access param
type AccessParam struct {
Enable bool `opt:"enable,require" `
Dir string `opt:"dir,require"`
......@@ -131,6 +145,7 @@ type AccessParam struct {
Expire int `opt:"expire,require"`
}
//Format 格式化
func (p *AccessParam) Format() (*Param, error) {
period, err := log.ParsePeriod(p.Period)
if err != nil {
......@@ -147,6 +162,7 @@ func (p *AccessParam) Format() (*Param, error) {
}, nil
}
//LogConfig 日志配置
type LogConfig struct {
Name string `json:"-"`
Enable bool `json:"enable" opt:"enable" default:"true"`
......@@ -174,6 +190,7 @@ func (c *LogConfig) Read(ent *entity.LogConfig) {
}
}
//AccessConfig access配置
type AccessConfig struct {
Name string `json:"-"`
Enable bool `json:"enable" opt:"enable" default:"true"`
......@@ -185,12 +202,15 @@ type AccessConfig struct {
Expires []ValueTitle `json:"expires"`
Fields []*AccessField `json:"fields"`
}
//AccessField access日志字段
type AccessField struct {
Name string `json:"name"`
Select bool `json:"select"`
Desc string `json:"desc"`
}
//InitFields 初始化字段
func (c *AccessConfig) InitFields() {
// 如果有新增的字段,按默认顺序拼接到末尾
c.Fields = make([]*AccessField, 0, access_field.Size())
......
package config_log
package configlog
import (
"fmt"
......@@ -8,6 +8,7 @@ import (
entity "github.com/eolinker/goku-api-gateway/server/entity/config-log"
)
//Set set
func Set(name string, param *Param) error {
if _, has := logNames[name]; !has {
return fmt.Errorf("not has that log config of %s", name)
......
......@@ -5,11 +5,12 @@ import (
console_mysql "github.com/eolinker/goku-api-gateway/server/dao/console-mysql"
)
//GetGatewayConfig 获取网关配置
func GetGatewayConfig() (map[string]interface{}, error) {
return console_mysql.GetGatewayConfig()
}
// 编辑网关基本配置
//EditGatewayBaseConfig 编辑网关基本配置
func EditGatewayBaseConfig(successCode string, nodeUpdatePeriod, monitorUpdatePeriod, timeout int) (bool, string, error) {
tableName := "goku_gateway"
flag, result, err := console_mysql.EditGatewayBaseConfig(successCode, nodeUpdatePeriod, monitorUpdatePeriod, timeout)
......@@ -19,7 +20,7 @@ func EditGatewayBaseConfig(successCode string, nodeUpdatePeriod, monitorUpdatePe
return flag, result, err
}
// 编辑网关告警配置
//EditGatewayAlarmConfig 编辑网关告警配置
func EditGatewayAlarmConfig(apiAlertInfo, sender, senderPassword, smtpAddress string, alertStatus, smtpPort, smtpProtocol int) (bool, string, error) {
tableName := "goku_gateway"
flag, result, err := console_mysql.EditGatewayAlarmConfig(apiAlertInfo, sender, senderPassword, smtpAddress, alertStatus, smtpPort, smtpProtocol)
......
......@@ -6,6 +6,7 @@ import (
monitor_key "github.com/eolinker/goku-api-gateway/server/monitor/monitor-key"
)
//GatewayRequestInfo 网关请求数量信息
type GatewayRequestInfo struct {
GatewayRequestCount int64 `json:"gatewayRequestCount"`
GatewaySuccessCount int64 `json:"gatewaySuccessCount"`
......@@ -28,6 +29,7 @@ func (i *GatewayRequestInfo) read(values monitor_key.MonitorValues) {
i.GatewaySuccessRateStr = fmt.Sprintf("%.2f%%", i.GatewaySuccessRate*100)
}
//ProxyInfo 转发数量信息
type ProxyInfo struct {
ProxyRequestCount int64 `json:"proxyRequestCount"`
ProxySuccessCount int64 `json:"proxySuccessCount"`
......@@ -57,28 +59,33 @@ func (i *ProxyInfo) read(values monitor_key.MonitorValues) {
i.ProxySuccessRateStr = fmt.Sprintf("%.2f%%", i.ProxySuccessRate*100)
}
//BaseGatewayInfo 网关基本信息
type BaseGatewayInfo struct {
NodeCount int `json:"nodeCount"`
NodeStartCount int `json:"-"`
NodeStopCount int `json:"-"`
ProjectCount int `json:"projectCount"`
ApiCount int `json:"apiCount"`
APICount int `json:"apiCount"`
StrategyCount int `json:"strategyCount"`
Version string `json:"version"`
ClusterCount int `json:"clusterCount"`
RedisCount int `json:"redisCount"`
}
//SystemInfo 系统信息
type SystemInfo struct {
GatewayRequestInfo GatewayRequestInfo `json:"gatewayRequestInfo"`
ProxyInfo ProxyInfo `json:"proxyRequestInfo"`
BaseInfo BaseGatewayInfo `json:"baseInfo"`
}
//Info info
type Info struct {
GatewayRequestInfo
ProxyInfo
}
//Get get
func (i *Info) Get(key string) interface{} {
switch key {
case "gatewayRequestCount":
......@@ -112,6 +119,8 @@ func (i *Info) Get(key string) interface{} {
}
return ""
}
//Value value
func (i *Info) Value(key string) int64 {
switch key {
case "gatewayRequestCount":
......@@ -151,17 +160,19 @@ func (i *Info) read(values monitor_key.MonitorValues) {
i.ProxyInfo.read(values)
}
//APIInfo 接口信息
type APIInfo struct {
Info
Id int `json:"apiID"`
ID int `json:"apiID"`
Name string `json:"apiName"`
URL string `json:"requestURL"`
}
//Get get
func (i *APIInfo) Get(key string) interface{} {
switch key {
case "id":
return i.Id
return i.ID
case "name":
return i.Name
case "url":
......@@ -170,18 +181,20 @@ func (i *APIInfo) Get(key string) interface{} {
return i.Info.Get(key)
}
//StrategyInfo 策略信息
type StrategyInfo struct {
Info
Id string `json:"strategyID"`
ID string `json:"strategyID"`
Name string `json:"strategyName"`
Status string `json:"-"`
}
//Get get
func (s *StrategyInfo) Get(key string) interface{} {
switch key {
case "id":
return s.Id
return s.ID
case "name":
return s.Name
case "status":
......@@ -191,30 +204,38 @@ func (s *StrategyInfo) Get(key string) interface{} {
}
//StrategyInfoList 策略信息列表
type StrategyInfoList []*StrategyInfo
//Value value
func (l StrategyInfoList) Value(i int, key string) int64 {
return l[i].Value(key)
}
//Len len
func (l StrategyInfoList) Len() int {
return len(l)
}
//Swap swap
func (l StrategyInfoList) Swap(i, j int) {
l[i], l[j] = l[j], l[i]
}
//APIInfoList 接口信息列表
type APIInfoList []*APIInfo
//Value value
func (l APIInfoList) Value(i int, key string) int64 {
return l[i].Value(key)
}
//Len len
func (l APIInfoList) Len() int {
return len(l)
}
//Swap swap
func (l APIInfoList) Swap(i, j int) {
l[i], l[j] = l[j], l[i]
}
package monitor
import (
. "github.com/eolinker/goku-api-gateway/common/version"
v "github.com/eolinker/goku-api-gateway/common/version"
"github.com/eolinker/goku-api-gateway/server/cluster"
console_mysql "github.com/eolinker/goku-api-gateway/server/dao/console-mysql"
dao_monitor "github.com/eolinker/goku-api-gateway/server/dao/console-mysql/dao-monitor"
)
func GetGatewayMonitorSummaryByPeriod(clientId int, beginTime, endTime string, period int) (bool, *SystemInfo, error) {
//GetGatewayMonitorSummaryByPeriod 获取网关监控概况
func GetGatewayMonitorSummaryByPeriod(clientID int, beginTime, endTime string, period int) (bool, *SystemInfo, error) {
startHour, endHour := genHour(beginTime, endTime, period)
values, e := dao_monitor.GetGateway(clientId, startHour, endHour)
values, e := dao_monitor.GetGateway(clientID, startHour, endHour)
if e != nil {
return false, nil, e
}
......@@ -26,11 +27,11 @@ func GetGatewayMonitorSummaryByPeriod(clientId int, beginTime, endTime string, p
info.BaseInfo.NodeCount = nodeStartCount + nodeStopCount
info.BaseInfo.ProjectCount = projectCount
info.BaseInfo.ApiCount = apiCount
info.BaseInfo.APICount = apiCount
info.BaseInfo.StrategyCount = strategyCount
activeRedisCount, redisErrorCount := console_mysql.GetRedisCount()
info.BaseInfo.RedisCount = activeRedisCount + redisErrorCount
info.BaseInfo.Version = Version
info.BaseInfo.Version = v.Version
info.BaseInfo.ClusterCount = cluster.GetClusterCount()
//dao_monitor.GetGatewayMonitorSummaryByPeriod(beginTime, endTime, period)
return true, info, nil
......
......@@ -5,32 +5,32 @@ import (
entity "github.com/eolinker/goku-api-gateway/server/entity/console-entity"
)
// 新增节点信息
func AddNode(clusterId int, nodeName, nodeIP, nodePort, gatewayPath string, groupID int) (bool, map[string]interface{}, error) {
return console_mysql.AddNode(clusterId, nodeName, nodeIP, nodePort, gatewayPath, groupID)
//AddNode 新增节点信息
func AddNode(clusterID int, nodeName, nodeIP, nodePort, gatewayPath string, groupID int) (bool, map[string]interface{}, error) {
return console_mysql.AddNode(clusterID, nodeName, nodeIP, nodePort, gatewayPath, groupID)
}
// 修改节点
//EditNode 修改节点
func EditNode(nodeName, nodeIP, nodePort, gatewayPath string, nodeID, groupID int) (bool, string, error) {
return console_mysql.EditNode(nodeName, nodeIP, nodePort, gatewayPath, nodeID, groupID)
}
// 删除节点
//DeleteNode 删除节点
func DeleteNode(nodeID int) (bool, string, error) {
return console_mysql.DeleteNode(nodeID)
}
// 获取节点信息
//GetNodeInfo 获取节点信息
func GetNodeInfo(nodeID int) (bool, *entity.Node, error) {
b, node, e := console_mysql.GetNodeInfo(nodeID)
ResetNodeStatus(node)
return b, node, e
}
// 获取节点信息
func GetNodeInfoByIpPort(ip string, port int) (bool, *entity.Node, error) {
b, node, e := console_mysql.GetNodeByIpPort(ip, port)
//GetNodeInfoByIPPort 获取节点信息
func GetNodeInfoByIPPort(ip string, port int) (bool, *entity.Node, error) {
b, node, e := console_mysql.GetNodeByIPPort(ip, port)
ResetNodeStatus(node)
return b, node, e
}
......@@ -42,12 +42,12 @@ func GetNodeList(clusterID, groupID int, keyword string) (bool, []*entity.Node,
return b, nodes, e
}
// 节点IP查重
//CheckIsExistRemoteAddr 节点IP查重
func CheckIsExistRemoteAddr(nodeID int, nodeIP, nodePort string) bool {
return console_mysql.CheckIsExistRemoteAddr(nodeID, nodeIP, nodePort)
}
// 批量删除节点
//BatchDeleteNode 批量删除节点
func BatchDeleteNode(nodeIDList string) (bool, string, error) {
flag, nodeIDList, err := console_mysql.GetAvaliableNodeListFromNodeList(nodeIDList, 0)
if !flag {
......@@ -58,12 +58,12 @@ func BatchDeleteNode(nodeIDList string) (bool, string, error) {
return console_mysql.BatchDeleteNode(nodeIDList)
}
// 批量修改节点分组
//BatchEditNodeGroup 批量修改节点分组
func BatchEditNodeGroup(nodeIDList string, groupID int) (bool, string, error) {
return console_mysql.BatchEditNodeGroup(nodeIDList, groupID)
}
// 获取节点IP列表
//GetNodeIPList 获取节点IP列表
func GetNodeIPList() (bool, []map[string]interface{}, error) {
return console_mysql.GetNodeIPList()
}
......@@ -4,37 +4,37 @@ import (
"github.com/eolinker/goku-api-gateway/server/dao/console-mysql"
)
// 新建节点分组
func AddNodeGroup(groupName string, clusterId int) (bool, interface{}, error) {
return console_mysql.AddNodeGroup(groupName, clusterId)
//AddNodeGroup 新建节点分组
func AddNodeGroup(groupName string, clusterID int) (bool, interface{}, error) {
return consolemysql.AddNodeGroup(groupName, clusterID)
}
// 修改节点分组信息
//EditNodeGroup 修改节点分组信息
func EditNodeGroup(groupName string, groupID int) (bool, string, error) {
return console_mysql.EditNodeGroup(groupName, groupID)
return consolemysql.EditNodeGroup(groupName, groupID)
}
// 删除节点分组
//DeleteNodeGroup 删除节点分组
func DeleteNodeGroup(groupID int) (bool, string, error) {
return console_mysql.DeleteNodeGroup(groupID)
return consolemysql.DeleteNodeGroup(groupID)
}
// 获取节点分组信息
//GetNodeGroupInfo 获取节点分组信息
func GetNodeGroupInfo(groupID int) (bool, map[string]interface{}, error) {
return console_mysql.GetNodeGroupInfo(groupID)
return consolemysql.GetNodeGroupInfo(groupID)
}
// 获取节点分组列表
func GetNodeGroupList(clusterId int) (bool, []map[string]interface{}, error) {
return console_mysql.GetNodeGroupList(clusterId)
//GetNodeGroupList 获取节点分组列表
func GetNodeGroupList(clusterID int) (bool, []map[string]interface{}, error) {
return consolemysql.GetNodeGroupList(clusterID)
}
// 检查节点分组是否存在
//CheckNodeGroupIsExist 检查节点分组是否存在
func CheckNodeGroupIsExist(groupID int) (bool, error) {
return console_mysql.CheckNodeGroupIsExist(groupID)
return consolemysql.CheckNodeGroupIsExist(groupID)
}
// 获取分组内启动节点数量
//GetRunningNodeCount 获取分组内启动节点数量
func GetRunningNodeCount(groupID int) (bool, interface{}, error) {
return console_mysql.GetRunningNodeCount(groupID)
return consolemysql.GetRunningNodeCount(groupID)
}
......@@ -7,6 +7,7 @@ import (
"time"
)
//EXPIRE 过期时间
const EXPIRE = time.Second * 10
var (
......@@ -45,16 +46,19 @@ func (m *_StatusManager) get(id string) (time.Time, bool) {
return t, b
}
//Refresh 刷新
func Refresh(ip string, port string) {
id := fmt.Sprintf("%s:%d", ip, port)
manager.refresh(id)
}
//NodeStop 停止节点
func NodeStop(ip, port string) {
id := fmt.Sprintf("%s:%d", ip, port)
manager.stop(id)
}
//IsLive 是否正常
func IsLive(ip string, port string) bool {
id := fmt.Sprintf("%s:%d", ip, port)
t, has := manager.get(id)
......@@ -67,6 +71,8 @@ func IsLive(ip string, port string) bool {
}
return true
}
//ResetNodeStatus 重置节点状态
func ResetNodeStatus(nodes ...*entity.Node) {
for _, node := range nodes {
......
......@@ -2,108 +2,88 @@ package plugin
import (
"github.com/eolinker/goku-api-gateway/server/dao"
console_mysql "github.com/eolinker/goku-api-gateway/server/dao/console-mysql"
consolemysql "github.com/eolinker/goku-api-gateway/server/dao/console-mysql"
entity "github.com/eolinker/goku-api-gateway/server/entity/console-entity"
)
// 获取插件配置信息
//GetPluginInfo 获取插件配置信息
func GetPluginInfo(pluginName string) (bool, *entity.Plugin, error) {
return console_mysql.GetPluginInfo(pluginName)
return consolemysql.GetPluginInfo(pluginName)
}
// 获取插件列表
//GetPluginList 获取插件列表
func GetPluginList(keyword string, condition int) (bool, []*entity.Plugin, error) {
return console_mysql.GetPluginList(keyword, condition)
return consolemysql.GetPluginList(keyword, condition)
}
// 新增插件信息
//AddPlugin 新增插件信息
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)
return consolemysql.AddPlugin(pluginName, pluginConfig, pluginDesc, version, pluginPriority, isStop, pluginType)
}
// 修改插件信息
//EditPlugin 修改插件信息
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)
return consolemysql.EditPlugin(pluginName, pluginConfig, pluginDesc, version, pluginPriority, isStop, pluginType)
}
// 删除插件信息
//DeletePlugin 删除插件信息
func DeletePlugin(pluginName string) (bool, string, error) {
return console_mysql.DeletePlugin(pluginName)
return consolemysql.DeletePlugin(pluginName)
}
// 判断插件ID是否存在
//CheckIndexIsExist 判断插件ID是否存在
func CheckIndexIsExist(pluginName string, pluginPriority int) (bool, error) {
return console_mysql.CheckIndexIsExist(pluginName, pluginPriority)
return consolemysql.CheckIndexIsExist(pluginName, pluginPriority)
}
// 获取插件配置及插件信息
//GetPluginConfig 获取插件配置及插件信息
func GetPluginConfig(pluginName string) (bool, string, error) {
return console_mysql.GetPluginConfig(pluginName)
return consolemysql.GetPluginConfig(pluginName)
}
// 检查插件名称是否存在
//CheckNameIsExist 检查插件名称是否存在
func CheckNameIsExist(pluginName string) (bool, error) {
return console_mysql.CheckNameIsExist(pluginName)
return consolemysql.CheckNameIsExist(pluginName)
}
// 修改插件开启状态
//EditPluginStatus 修改插件开启状态
func EditPluginStatus(pluginName string, pluginStatus int) (bool, error) {
tableName := "goku_plugin"
flag, err := console_mysql.EditPluginStatus(pluginName, pluginStatus)
flag, err := consolemysql.EditPluginStatus(pluginName, pluginStatus)
if flag {
dao.UpdateTable(tableName)
console_mysql.UpdatePluginTagByPluginName(pluginName)
consolemysql.UpdatePluginTagByPluginName(pluginName)
}
return flag, err
}
// 获取不同类型的插件列表
//GetPluginListByPluginType 获取不同类型的插件列表
func GetPluginListByPluginType(pluginType int) (bool, []map[string]interface{}, error) {
return console_mysql.GetPluginListByPluginType(pluginType)
return consolemysql.GetPluginListByPluginType(pluginType)
}
// 批量关闭插件
//BatchStopPlugin 批量关闭插件
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)
flag, result, err := consolemysql.BatchStopPlugin(pluginNameList)
if flag {
dao.UpdateTable(tableName)
}
return flag, result, err
}
// 批量关闭插件
//BatchStartPlugin 批量关闭插件
func BatchStartPlugin(pluginNameList string) (bool, string, error) {
tableName := "goku_plugin"
flag, result, err := console_mysql.BatchStartPlugin(pluginNameList)
flag, result, err := consolemysql.BatchStartPlugin(pluginNameList)
if flag {
dao.UpdateTable(tableName)
console_mysql.UpdatePluginTagByPluginName(pluginNameList)
consolemysql.UpdatePluginTagByPluginName(pluginNameList)
}
return flag, result, err
}
// 更新插件检测状态
//EditPluginCheckStatus 更新插件检测状态
func EditPluginCheckStatus(pluginName string, isCheck int) (bool, string, error) {
return console_mysql.EditPluginCheckStatus(pluginName, isCheck)
return consolemysql.EditPluginCheckStatus(pluginName, isCheck)
}
......@@ -6,17 +6,17 @@ import (
entity "github.com/eolinker/goku-api-gateway/server/entity/console-entity"
)
// 新建项目
//AddProject 新建项目
func AddProject(projectName string) (bool, interface{}, error) {
return console_mysql.AddProject(projectName)
}
// 修改项目信息
//EditProject 修改项目信息
func EditProject(projectName string, projectID int) (bool, string, error) {
return console_mysql.EditProject(projectName, projectID)
}
// 修改项目信息
//DeleteProject 修改项目信息
func DeleteProject(projectID int) (bool, string, error) {
flag, result, err := console_mysql.DeleteProject(projectID)
if flag {
......@@ -26,7 +26,7 @@ func DeleteProject(projectID int) (bool, string, error) {
return flag, result, err
}
// 批量删除项目
//BatchDeleteProject 批量删除项目
func BatchDeleteProject(projectIDList string) (bool, string, error) {
flag, result, err := console_mysql.BatchDeleteProject(projectIDList)
if flag {
......@@ -36,22 +36,22 @@ func BatchDeleteProject(projectIDList string) (bool, string, error) {
return flag, result, err
}
// 获取项目信息
//GetProjectInfo 获取项目信息
func GetProjectInfo(projectID int) (bool, entity.Project, error) {
return console_mysql.GetProjectInfo(projectID)
}
// 获取项目列表
//GetProjectList 获取项目列表
func GetProjectList(keyword string) (bool, []*entity.Project, error) {
return console_mysql.GetProjectList(keyword)
}
// 检查项目是否存在
//CheckProjectIsExist 检查项目是否存在
func CheckProjectIsExist(projectID int) (bool, error) {
return console_mysql.CheckProjectIsExist(projectID)
}
// 获取项目列表中没有被策略组绑定的接口
func GetApiListFromProjectNotInStrategy() (bool, []map[string]interface{}, error) {
return console_mysql.GetApiListFromProjectNotInStrategy()
//GetAPIListFromProjectNotInStrategy 获取项目列表中没有被策略组绑定的接口
func GetAPIListFromProjectNotInStrategy() (bool, []map[string]interface{}, error) {
return console_mysql.GetAPIListFromProjectNotInStrategy()
}
......@@ -2,20 +2,21 @@ package script
import (
"github.com/eolinker/goku-api-gateway/server/dao"
console_mysql "github.com/eolinker/goku-api-gateway/server/dao/console-mysql"
consolemysql "github.com/eolinker/goku-api-gateway/server/dao/console-mysql"
)
// 新建项目
func RefreshApiInfo() bool {
//return console_mysql.RefreshApiInfo()
//RefreshAPIInfo 刷新接口信息
func RefreshAPIInfo() bool {
//return consolemysql.RefreshAPIInfo()
return true
}
// 新建项目
//RefreshGatewayAlertConfig 刷新网关告警配置
func RefreshGatewayAlertConfig() bool {
return console_mysql.RefreshGatewayAlertConfig()
return consolemysql.RefreshGatewayAlertConfig()
}
//UpdateTables 更新表
func UpdateTables(names []string) {
for _, name := range names {
dao.UpdateTable(name)
......
......@@ -22,6 +22,8 @@ func init() {
func f(r rune) bool {
return !nameLetters[r]
}
//ValidateName 判断名称是否合法
func ValidateName(name string) bool {
if name == "" {
return false
......
......@@ -10,6 +10,7 @@ import (
const _TableName = "goku_service_config"
//Add add
func Add(param *AddParam) error {
err := dao_service.Add(param.Name, param.Driver, param.Desc, param.Config, param.ClusterConfig, false, param.HealthCheck, param.HealthCheckPath, param.HealthCheckCode, param.HealthCheckPeriod, param.HealthCheckTimeOut)
......@@ -20,6 +21,7 @@ func Add(param *AddParam) error {
return err
}
//Save save
func Save(param *AddParam) error {
v, e := dao_service.Get(param.Name)
......@@ -37,6 +39,8 @@ func Save(param *AddParam) error {
}
return err
}
//Get get
func Get(name string) (*Info, error) {
v, err := dao_service.Get(name)
if err != nil {
......@@ -54,6 +58,7 @@ func Get(name string) (*Info, error) {
}, nil
}
//Delete delete
func Delete(names []string) error {
for _, n := range names {
......@@ -65,6 +70,7 @@ func Delete(names []string) error {
return dao_service.Delete(names)
}
//SetDefaut 设置默认值
func SetDefaut(name string) error {
return dao_service.SetDefault(name)
}
......@@ -91,6 +97,8 @@ func tran(v *entity.Service) *Service {
}
return s
}
//List 获取列表
func List(keyword string) ([]*Service, error) {
vs, e := dao_service.List(keyword)
if e != nil {
......@@ -106,6 +114,7 @@ func List(keyword string) ([]*Service, error) {
return list, nil
}
//SimpleList 获取简易列表
func SimpleList() ([]*Simple, string, error) {
vs, e := dao_service.List("")
if e != nil {
......
......@@ -2,6 +2,7 @@ package service
import "encoding/json"
//Simple simple
type Simple struct {
Name string `json:"name"`
Driver string `json:"driver"`
......@@ -9,6 +10,7 @@ type Simple struct {
Type string `json:"type"`
}
//Service service
type Service struct {
Simple
......@@ -19,6 +21,7 @@ type Service struct {
CreateTime string `json:"createTime"`
}
//Info info
type Info struct {
*Service
Config string `json:"config"`
......@@ -30,10 +33,12 @@ type Info struct {
HealthCheckTimeOut int `json:"healthCheckTimeOut"`
}
//Decode 解码
func (i *Info) Decode() {
json.Unmarshal([]byte(i.ClusterConfig), &i.ClusterConfigObj)
}
//AddParam add param
type AddParam struct {
Name string `opt:"name,require"`
Driver string `opt:"driver" default:"static"`
......
......@@ -8,22 +8,21 @@ import (
entity "github.com/eolinker/goku-api-gateway/server/entity/console-entity"
)
// 新增策略组
//AddStrategy 新增策略组
func AddStrategy(strategyName string, groupID int) (bool, string, error) {
flag := console_mysql.CheckIsOpenGroup(groupID)
if flag {
return false, "[ERROR]The group is an open group", errors.New("[ERROR]The group is an open group")
} else {
flag, result, err := console_mysql.AddStrategy(strategyName, groupID)
if flag {
tableName := "goku_gateway_strategy"
dao.UpdateTable(tableName)
}
return flag, result, err
}
flag, result, err := console_mysql.AddStrategy(strategyName, groupID)
if flag {
tableName := "goku_gateway_strategy"
dao.UpdateTable(tableName)
}
return flag, result, err
}
// 修改策略组信息
//EditStrategy 修改策略组信息
func EditStrategy(strategyID, strategyName string, groupID int) (bool, string, error) {
return console_mysql.EditStrategy(strategyID, strategyName, groupID)
}
......@@ -33,14 +32,13 @@ func DeleteStrategy(strategyID string) (bool, string, error) {
flag := console_mysql.CheckIsOpenStrategy(strategyID)
if flag {
return false, "[ERROR]The strategy is an open strategy", errors.New("[ERROR]The strategy is an open strategy")
} else {
tableName := "goku_gateway_strategy"
flag, result, err := console_mysql.DeleteStrategy(strategyID)
if flag {
dao.UpdateTable(tableName)
}
return flag, result, err
}
tableName := "goku_gateway_strategy"
flag, result, err := console_mysql.DeleteStrategy(strategyID)
if flag {
dao.UpdateTable(tableName)
}
return flag, result, err
}
// GetOpenStrategy 获取策略组列表
......@@ -78,18 +76,19 @@ func BatchDeleteStrategy(strategyIDList string) (bool, string, error) {
return flag, result, err
}
//CheckIsOpenStrategy 是否是开放策略
func CheckIsOpenStrategy(strategyID string) bool {
return console_mysql.CheckIsOpenStrategy(strategyID)
}
// 更新策略启用状态
//BatchUpdateStrategyEnableStatus 更新策略启用状态
func BatchUpdateStrategyEnableStatus(strategyIDList string, enableStatus int) (bool, string, error) {
tableName := "goku_gateway_strategy"
flag, result, err := console_mysql.BatchUpdateStrategyEnableStatus(strategyIDList, enableStatus)
if flag {
dao.UpdateTable(tableName)
console_mysql.BatchUpdateStrategyPluginUpdateTag(strategyIDList)
console_mysql.BatchUpdateApiPluginUpdateTag(strategyIDList)
console_mysql.BatchUpdateAPIPluginUpdateTag(strategyIDList)
}
return flag, result, err
}
......
......@@ -7,12 +7,12 @@ import (
console_mysql "github.com/eolinker/goku-api-gateway/server/dao/console-mysql"
)
// 新建策略组分组
//AddStrategyGroup 新建策略组分组
func AddStrategyGroup(groupName string) (bool, interface{}, error) {
return console_mysql.AddStrategyGroup(groupName)
}
// 修改策略组分组
//EditStrategyGroup 修改策略组分组
func EditStrategyGroup(groupName string, groupID int) (bool, string, error) {
return console_mysql.EditStrategyGroup(groupName, groupID)
}
......@@ -22,24 +22,24 @@ func DeleteStrategyGroup(groupID int) (bool, string, error) {
flag := console_mysql.CheckIsOpenGroup(groupID)
if flag {
return false, "[ERROR]The group is an open group", errors.New("[ERROR]The group is an open group")
} else {
flag, result, err := console_mysql.DeleteStrategyGroup(groupID)
if flag {
dao.UpdateTable("goku_gateway_strategy")
dao.UpdateTable("goku_gateway_api")
dao.UpdateTable("goku_conn_strategy_api")
dao.UpdateTable("goku_conn_plugin_strategy")
dao.UpdateTable("goku_conn_plugin_api")
}
return flag, result, err
}
flag, result, err := console_mysql.DeleteStrategyGroup(groupID)
if flag {
dao.UpdateTable("goku_gateway_strategy")
dao.UpdateTable("goku_gateway_api")
dao.UpdateTable("goku_conn_strategy_api")
dao.UpdateTable("goku_conn_plugin_strategy")
dao.UpdateTable("goku_conn_plugin_api")
}
return flag, result, err
}
// 获取策略组分组列表
//GetStrategyGroupList 获取策略组分组列表
func GetStrategyGroupList() (bool, []map[string]interface{}, error) {
return console_mysql.GetStrategyGroupList()
}
//CheckIsOpenGroup 判断是否是开放分组
func CheckIsOpenGroup(groupID int) bool {
return console_mysql.CheckIsOpenGroup(groupID)
}
......@@ -7,7 +7,7 @@ import (
console_mysql "github.com/eolinker/goku-api-gateway/server/dao/console-mysql"
)
// 新增策略组插件
//AddPluginToStrategy 新增策略组插件
func AddPluginToStrategy(pluginName, config, strategyID string) (bool, interface{}, error) {
tableName := "goku_conn_plugin_strategy"
flag, result, err := console_mysql.AddPluginToStrategy(pluginName, config, strategyID)
......@@ -18,7 +18,7 @@ func AddPluginToStrategy(pluginName, config, strategyID string) (bool, interface
return flag, result, err
}
// 新增策略组插件配置
//EditStrategyPluginConfig 新增策略组插件配置
func EditStrategyPluginConfig(pluginName, config, strategyID string) (bool, string, error) {
flag, result, err := console_mysql.EditStrategyPluginConfig(pluginName, config, strategyID)
tableName := "goku_conn_plugin_strategy"
......@@ -29,7 +29,7 @@ func EditStrategyPluginConfig(pluginName, config, strategyID string) (bool, stri
return flag, result, err
}
// 批量修改策略组插件状态
//BatchEditStrategyPluginStatus 批量修改策略组插件状态
func BatchEditStrategyPluginStatus(connIDList, strategyID string, pluginStatus int) (bool, string, error) {
plugins := []string{}
flag, _ := console_mysql.CheckStrategyPluginIsExistByConnIDList(connIDList, "goku-rate_limiting")
......@@ -50,7 +50,7 @@ func BatchEditStrategyPluginStatus(connIDList, strategyID string, pluginStatus i
return flag, result, err
}
// 批量删除策略组插件
//BatchDeleteStrategyPlugin 批量删除策略组插件
func BatchDeleteStrategyPlugin(connIDList, strategyID string) (bool, string, error) {
tableName := "goku_conn_plugin_strategy"
flag, result, err := console_mysql.BatchDeleteStrategyPlugin(connIDList, strategyID)
......@@ -65,22 +65,22 @@ func GetStrategyPluginList(strategyID, keyword string, condition int) (bool, []m
return console_mysql.GetStrategyPluginList(strategyID, keyword, condition)
}
// 通过策略组ID获取配置信息
//GetStrategyPluginConfig 通过策略组ID获取配置信息
func GetStrategyPluginConfig(strategyID, pluginName string) (bool, string, error) {
return console_mysql.GetStrategyPluginConfig(strategyID, pluginName)
}
// 检查策略组是否绑定插件
//CheckPluginIsExistInStrategy 检查策略组是否绑定插件
func CheckPluginIsExistInStrategy(strategyID, pluginName string) (bool, error) {
return console_mysql.CheckPluginIsExistInStrategy(strategyID, pluginName)
}
// 检查策略组插件是否开启
//GetStrategyPluginStatus 检查策略组插件是否开启
func GetStrategyPluginStatus(strategyID, pluginName string) (bool, error) {
return console_mysql.GetStrategyPluginStatus(strategyID, pluginName)
}
// 获取Connid
//GetConnIDFromStrategyPlugin 获取Connid
func GetConnIDFromStrategyPlugin(pluginName, strategyID string) (bool, int, error) {
return console_mysql.GetConnIDFromStrategyPlugin(pluginName, strategyID)
}
......@@ -5,24 +5,30 @@ import (
"strings"
)
//ClusterRedisConfig 集群redis配置
type ClusterRedisConfig entity.CLusterRedis
//GetMode 获取redis模式
func (c ClusterRedisConfig) GetMode() string {
return c.Mode
}
//GetAddrs 获取redis地址
func (c ClusterRedisConfig) GetAddrs() []string {
return strings.Split(c.Addrs, ",")
}
//GetMasters getMasters
func (c ClusterRedisConfig) GetMasters() []string {
return strings.Split(c.Masters, ",")
}
//GetDbIndex 获取redis数据库序号
func (c ClusterRedisConfig) GetDbIndex() int {
return c.DbIndex
}
//GetPassword 获取redis密码
func (c ClusterRedisConfig) GetPassword() string {
return c.Password
}
......@@ -21,6 +21,7 @@ import (
"github.com/eolinker/goku-api-gateway/console/controller/strategy"
)
//Router 路由
func Router() {
// 游客
......@@ -51,38 +52,38 @@ func Router() {
http.HandleFunc("/project/delete", project.DeleteProject)
http.HandleFunc("/project/getInfo", project.GetProjectInfo)
http.HandleFunc("/project/getList", project.GetProjectList)
http.HandleFunc("/project/strategy/getList", project.GetApiListFromProjectNotInStrategy)
http.HandleFunc("/project/strategy/getList", project.GetAPIListFromProjectNotInStrategy)
http.HandleFunc("/project/batchDelete", project.BatchDeleteProject)
// 接口分组
http.HandleFunc("/apis/group/add", api.AddApiGroup)
http.HandleFunc("/apis/group/edit", api.EditApiGroup)
http.HandleFunc("/apis/group/delete", api.DeleteApiGroup)
http.HandleFunc("/apis/group/getList", api.GetApiGroupList)
http.HandleFunc("/apis/group/update", api.UpdateApiGroupScript)
http.HandleFunc("/apis/group/add", api.AddAPIGroup)
http.HandleFunc("/apis/group/edit", api.EditAPIGroup)
http.HandleFunc("/apis/group/delete", api.DeleteAPIGroup)
http.HandleFunc("/apis/group/getList", api.GetAPIGroupList)
http.HandleFunc("/apis/group/update", api.UpdateAPIGroupScript)
// API
http.HandleFunc("/apis/add", api.AddApi)
http.HandleFunc("/apis/edit", api.EditApi)
http.HandleFunc("/apis/copy", api.CopyApi)
http.HandleFunc("/apis/getInfo", api.GetApiInfo)
http.HandleFunc("/apis/getList", api.GetApiList)
http.HandleFunc("/apis/batchEditGroup", api.BatchEditApiGroup)
http.HandleFunc("/apis/batchDelete", api.BatchDeleteApi)
http.HandleFunc("/apis/batchEditBalance", api.BatchSetBalanceApi)
http.HandleFunc("/apis/add", api.AddAPI)
http.HandleFunc("/apis/edit", api.EditAPI)
http.HandleFunc("/apis/copy", api.CopyAPI)
http.HandleFunc("/apis/getInfo", api.GetAPIInfo)
http.HandleFunc("/apis/getList", api.GetAPIList)
http.HandleFunc("/apis/batchEditGroup", api.BatchEditAPIGroup)
http.HandleFunc("/apis/batchDelete", api.BatchDeleteAPI)
http.HandleFunc("/apis/batchEditBalance", api.BatchSetBalanceAPI)
http.HandleFunc("/apis/manager/getList", api.GetApiManagerList)
http.HandleFunc("/apis/manager/getList", api.GetAPIManagerList)
// API绑定插件
http.HandleFunc("/plugin/api/addPluginToApi", api.AddPluginToApi)
http.HandleFunc("/plugin/api/edit", api.EditApiPluginConfig)
http.HandleFunc("/plugin/api/getInfo", api.GetApiPluginConfig)
http.HandleFunc("/plugin/api/getList", api.GetApiPluginList)
http.HandleFunc("/plugin/api/getListByStrategy", api.GetAllApiPluginInStrategy)
http.HandleFunc("/plugin/api/batchStart", api.BatchStartApiPlugin)
http.HandleFunc("/plugin/api/batchStop", api.BatchStopApiPlugin)
http.HandleFunc("/plugin/api/batchDelete", api.BatchDeleteApiPlugin)
http.HandleFunc("/plugin/api/notAssign/getList", api.GetApiPluginListWithNotAssignApiList)
http.HandleFunc("/plugin/api/addPluginToAPI", api.AddPluginToAPI)
http.HandleFunc("/plugin/api/edit", api.EditAPIPluginConfig)
http.HandleFunc("/plugin/api/getInfo", api.GetAPIPluginConfig)
http.HandleFunc("/plugin/api/getList", api.GetAPIPluginList)
http.HandleFunc("/plugin/api/getListByStrategy", api.GetAllAPIPluginInStrategy)
http.HandleFunc("/plugin/api/batchStart", api.BatchStartAPIPlugin)
http.HandleFunc("/plugin/api/batchStop", api.BatchStopAPIPlugin)
http.HandleFunc("/plugin/api/batchDelete", api.BatchDeleteAPIPlugin)
http.HandleFunc("/plugin/api/notAssign/getList", api.GetAPIPluginListWithNotAssignAPIList)
// 策略绑定插件
http.HandleFunc("/plugin/strategy/addPluginToStrategy", strategy.AddPluginToStrategy)
......@@ -136,12 +137,12 @@ func Router() {
http.HandleFunc("/strategy/group/getList", strategy.GetStrategyGroupList)
// 接口策略组
http.HandleFunc("/strategy/api/add", strategy.AddApiToStrategy)
http.HandleFunc("/strategy/api/target", strategy.ResetApiTargetOfStrategy)
http.HandleFunc("/strategy/api/batchEditTarget", strategy.BatchResetApiTargetOfStrategy)
http.HandleFunc("/strategy/api/getList", strategy.GetApiListFromStrategy)
http.HandleFunc("/strategy/api/getNotInList", strategy.GetApiListNotInStrategy)
http.HandleFunc("/strategy/api/batchDelete", strategy.BatchDeleteApiInStrategy)
http.HandleFunc("/strategy/api/add", strategy.AddAPIToStrategy)
http.HandleFunc("/strategy/api/target", strategy.ResetAPITargetOfStrategy)
http.HandleFunc("/strategy/api/batchEditTarget", strategy.BatchResetAPITargetOfStrategy)
http.HandleFunc("/strategy/api/getList", strategy.GetAPIListFromStrategy)
http.HandleFunc("/strategy/api/getNotInList", strategy.GetAPIListNotInStrategy)
http.HandleFunc("/strategy/api/batchDelete", strategy.BatchDeleteAPIInStrategy)
http.HandleFunc("/strategy/api/plugin/getList", api.GetAPIPluginInStrategyByAPIID)
http.HandleFunc("/strategy/balance/getList", strategy.GetBalanceListInStrategy)
......@@ -182,8 +183,8 @@ func Router() {
http.HandleFunc("/auth/editInfo", auth.EditAuthInfo)
// 导入
http.HandleFunc("/import/ams/api", api.ImportApiFromAms)
http.HandleFunc("/import/ams/group", api.ImportApiGroupFromAms)
http.HandleFunc("/import/ams/api", api.ImportAPIFromAms)
http.HandleFunc("/import/ams/group", api.ImportAPIGroupFromAms)
http.HandleFunc("/import/ams/project", api.ImportProjectFromAms)
// 集群
......@@ -192,7 +193,7 @@ func Router() {
http.HandleFunc("/cluster/simpleList", cluster.GetClusterList)
// 脚本
http.HandleFunc("/scrpit/refreshApiInfo", script.RefreshApiInfo)
http.HandleFunc("/scrpit/refreshAPIInfo", script.RefreshAPIInfo)
http.HandleFunc("/scrpit/refreshGatewayAlertConfig", script.RefreshGatewayAlertConfig)
// 配置
http.Handle("/config/log/", config_log.Handle("/config/log/"))
......
......@@ -5,8 +5,6 @@ import (
log "github.com/eolinker/goku-api-gateway/goku-log"
_ "net/http/pprof"
"github.com/eolinker/goku-api-gateway/console/controller/api"
"github.com/eolinker/goku-api-gateway/console/controller/script"
"github.com/eolinker/goku-api-gateway/console/controller/strategy"
......@@ -18,11 +16,12 @@ import (
"github.com/eolinker/goku-api-gateway/console/module/account"
)
//Server 服务
func Server() {
//go monitor.MonitorNode()
monitor_read.InitMonitorRead(cluster2.GetList())
script.UpdateTables()
api.UpdateAllApiPluginUpdateTag()
api.UpdateAllAPIPluginUpdateTag()
strategy.UpdateAllStrategyPluginUpdateTag()
bind, has := conf.Get("admin_bind")
......@@ -66,7 +65,7 @@ func Server() {
}
// 用户注册
// Register 用户注册
func Register(loginCall, loginPassword string) bool {
return account.Register(loginCall, loginPassword)
}
package goku_log
package gokulog
import (
"fmt"
......@@ -6,6 +6,7 @@ import (
"os"
)
// StartDebug 启用debug钩子
func StartDebug() {
logger.AddHook(new(debugHook))
......
package goku_log
package gokulog
import (
"fmt"
......@@ -8,26 +8,39 @@ import (
)
const (
//PanicLevel panic
PanicLevel = logrus.PanicLevel
//FatalLevel fatal
FatalLevel = logrus.FatalLevel
//ErrorLevel error
ErrorLevel = logrus.ErrorLevel
//WarnLevel warn
WarnLevel = logrus.WarnLevel
//InfoLevel info
InfoLevel = logrus.InfoLevel
//DebugLevel debug
DebugLevel = logrus.DebugLevel
//TraceLevel trace
TraceLevel = logrus.TraceLevel
)
var (
writer *FileWriterByPeriod = nil
writer *FileWriterByPeriod
logger = logrus.New()
logEnable = true
)
//Level level
type Level = logrus.Level
//Fields fields
type Fields = logrus.Fields
//Entry entry
type Entry = logrus.Entry
//ParseLevel 转换层级
func ParseLevel(lvl string) (Level, error) {
return logrus.ParseLevel(lvl)
}
......@@ -45,14 +58,20 @@ func init() {
Close()
})
}
//GetLogger 获取日志对象
func GetLogger() *logrus.Logger {
return logger
}
//SetLevel 设置日志层级
func SetLevel(level Level) {
logger.SetLevel(level)
}
//SetOutPut 输出设置
func SetOutPut(enable bool, dir, file string, period LogPeriod, expire int) {
logEnable = enable
logger.SetOutput(writer)
......@@ -64,9 +83,12 @@ func SetOutPut(enable bool, dir, file string, period LogPeriod, expire int) {
}
}
//Close 关闭流
func Close() {
writer.Close()
}
//WithFields 设置日志需要的字段名称
func WithFields(fields Fields) *Entry {
return logger.WithFields(fields)
......@@ -235,7 +257,7 @@ func Debugln(args ...interface{}) {
logger.Debugln(args...)
}
// 无视lever输出一段trace 信息
// Print 无视lever输出一段trace 信息
func Print(args ...interface{}) {
s, e := encode(TraceLevel, args...)
......
package goku_log
package gokulog
import (
"bytes"
......@@ -13,11 +13,13 @@ const (
defaultTimestampFormat = time.RFC3339
)
//LineFormatter 格式化
type LineFormatter struct {
TimestampFormat string
CallerPrettyfier func(*runtime.Frame) (function string, file string)
}
//Format 格式化
func (f *LineFormatter) Format(entry *logrus.Entry) ([]byte, error) {
data := make(Fields)
for k, v := range entry.Data {
......
package goku_log
package gokulog
import (
"fmt"
"strings"
)
//LogPeriod 日志周期对象
type LogPeriod interface {
String() string
FormatLayout() string
}
//LogPeriodType 日志周期类型
type LogPeriodType int
//ParsePeriod 解析周期
func ParsePeriod(v string) (LogPeriod, error) {
switch strings.ToLower(v) {
case "month":
......@@ -37,11 +41,15 @@ func (period LogPeriodType) String() string {
}
const (
//PeriodMonth 月
PeriodMonth LogPeriodType = iota
//PeriodDay 天
PeriodDay
//PeriodHour 时
PeriodHour
)
//FormatLayout 设置时间格式
func (period LogPeriodType) FormatLayout() string {
switch period {
case PeriodHour:
......
package goku_log
package gokulog
import (
"bufio"
......@@ -12,6 +12,7 @@ import (
"time"
)
//MaxBufferd 最大缓存数值
const MaxBufferd = 1024 * 500
var (
......@@ -22,6 +23,7 @@ var (
}
)
//FileWriterByPeriod 文件输出对象
type FileWriterByPeriod struct {
wC chan *bytes.Buffer
dir string
......@@ -34,6 +36,7 @@ type FileWriterByPeriod struct {
expire time.Duration
}
//NewFileWriteBytePeriod 创建文件输出对象
func NewFileWriteBytePeriod() *FileWriterByPeriod {
w := &FileWriterByPeriod{
locker: sync.Mutex{},
......@@ -49,6 +52,8 @@ func (w *FileWriterByPeriod) getExpire() time.Duration {
w.locker.Unlock()
return expire
}
//Set 设置对象信息
func (w *FileWriterByPeriod) Set(dir, file string, period LogPeriod, expire time.Duration) {
fileName := strings.TrimSuffix(file, ".log")
......@@ -59,6 +64,8 @@ func (w *FileWriterByPeriod) Set(dir, file string, period LogPeriod, expire time
w.expire = expire
w.locker.Unlock()
}
//Open 打开文件
func (w *FileWriterByPeriod) Open() {
w.locker.Lock()
defer w.locker.Unlock()
......@@ -74,6 +81,8 @@ func (w *FileWriterByPeriod) Open() {
w.enable = true
go w.do(ctx)
}
//Close 关闭对象
func (w *FileWriterByPeriod) Close() {
isClose := false
......
package goku_log
package gokulog
import (
"context"
......
......@@ -2,10 +2,12 @@ package cmd
import "github.com/eolinker/goku-api-gateway/server/entity"
//CMD cmd
type CMD struct {
StatusCode string `json:"statuscode"`
}
//ClusterConfig clusterConfig
type ClusterConfig struct {
CMD
Cluster *entity.ClusterInfo `json:"cluster"`
......
......@@ -12,12 +12,12 @@ import (
"time"
)
// 获取节点配置
//GetConfig 获取节点配置
func GetConfig(listenPort int) (bool, *entity.ClusterInfo) {
client := &http.Client{
Timeout: time.Second * 10,
}
addr := node_common.GetAdminUrl(fmt.Sprintf("/register?port=%d", listenPort))
addr := node_common.GetAdminURL(fmt.Sprintf("/register?port=%d", listenPort))
reader := bytes.NewReader([]byte(""))
request, err := http.NewRequest("GET", addr, reader)
if err != nil {
......
......@@ -9,6 +9,7 @@ import (
"time"
)
//HeartBeatProid heartBeatProid
const HeartBeatProid = time.Second * 5
var (
......@@ -16,6 +17,7 @@ var (
closeChan chan bool
)
//Heartbeat heartBeat
func Heartbeat(port int) {
closeChan = make(chan bool)
serverPort = port
......@@ -38,18 +40,19 @@ func Heartbeat(port int) {
func sendHeartBeat(port int) {
addr := node_common.GetAdminUrl(fmt.Sprintf("node/heartbeat?port=%d", port))
addr := node_common.GetAdminURL(fmt.Sprintf("node/heartbeat?port=%d", port))
_, err := http.Get(addr)
if err != nil {
log.Warn("fail to send heartbeat:", err)
}
}
//StopNode stopNode
func StopNode() {
close(closeChan)
log.Debug("stop node")
addr := node_common.GetAdminUrl(fmt.Sprintf("node/stop?port=%d", serverPort))
addr := node_common.GetAdminURL(fmt.Sprintf("node/stop?port=%d", serverPort))
_, err := http.Get(addr)
if err != nil {
log.Warn("fail to send heartbeat:", err)
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册