提交 887d5133 编写于 作者: Y Your Name

3.1.0版本更新

上级 df660d6f
/html/
/console
/work/
/log/
/logs/
/cert/
/config/
/db/
/static/
/sql/
cluster:
-
name: "Default"
title: "默认机房"
note: "默认机房"
db:
driver: "mysql"
host: "127.0.0.1"
port: 3306
userName: "root"
password: "123456"
database: "goku_ee"
redis:
mode: "stand"
addrs: "127.0.0.1:6379" # stand、cluster模式下addrs为redis地址,多个地址间用英文逗号隔开
password: "123456"
dbIndex: 0
\ No newline at end of file
listen_port: 7000
admin_bind: 127.0.0.1:7005
db_host: 127.0.0.1
db_port: 3306
db_name: goku_ee
db_user: root
db_password: root
\ No newline at end of file
......@@ -2,6 +2,7 @@ package main
import (
"flag"
"github.com/eolinker/goku-api-gateway/console/module/account"
log "github.com/eolinker/goku-api-gateway/goku-log"
......@@ -12,19 +13,15 @@ import (
)
var (
// UserPassword 用户密码
UserPassword string
// UserName 用户名
UserName string
// ConfFilePath 配置文件地址
ConfFilePath = "./config/goku.conf"
userPassword string
userName string
confFilePath = "./config/goku.conf"
)
func main() {
flag.StringVar(&ConfFilePath, "c", "./config/goku.conf", "Please provide a valid configuration file path")
flag.StringVar(&UserName, "u", "", "Please provide user name")
flag.StringVar(&UserPassword, "p", "", "Please provide user password")
flag.StringVar(&confFilePath, "c", "./config/goku.conf", "Please provide a valid configuration file path")
flag.StringVar(&userName, "u", "", "Please provide user name")
flag.StringVar(&userPassword, "p", "", "Please provide user password")
isDebug := flag.Bool("debug", false, "")
flag.Parse()
......@@ -32,7 +29,7 @@ func main() {
log.StartDebug()
}
// 初始化配置
if err := conf.ReadConfigure(ConfFilePath); err != nil {
if err := conf.ReadConfigure(confFilePath); err != nil {
log.Panic(err)
return
}
......@@ -40,32 +37,34 @@ func main() {
console.InitDatabase()
console.InitLog()
console.InitClusters()
//console.InitClusters()
// 其他需要初始化的模块
_ = general.General()
// 检测是否安装
if s, err := account.CheckSuperAdminCount(); err != nil {
log.Panic(err)
return
} else if s == 0 {
if UserName == "" {
s, err := account.CheckSuperAdminCount()
if err != nil {
err = console.InitTable()
if err != nil {
log.Panic(err)
return
}
}
if s == 0 {
if userName == "" {
log.Fatal("[ERROR] Fail to create administrator. Please try again or contact technical support of eoLinker GOKU API Gateway.")
//fmt.Println("[ERROR] Fail to create administrator. Please try again or contact technical support of eoLinker GOKU API Gateway.")
return
}
if UserPassword == "" {
if userPassword == "" {
log.Fatal("[ERROR] Fail to create administrator. Please try again or contact technical support of eoLinker GOKU API Gateway.")
//fmt.Println("[ERROR] Fail to create administrator. Please try again or contact technical support of eoLinker GOKU API Gateway.")
return
}
// 用户注册
password := utils.Md5(utils.Md5(UserPassword))
f := console.Register(UserName, password)
password := utils.Md5(utils.Md5(userPassword))
f := console.Register(userName, password)
if !f {
log.Fatal("[ERROR] Fail to create administrator. Please try again or contact technical support of eoLinker GOKU API Gateway.")
//fmt.Println("[ERROR] Fail to create administrator. Please try again or contact technical support of eoLinker GOKU API Gateway.")
return
}
}
......
package main
import (
"encoding/json"
"flag"
"fmt"
endless2 "github.com/eolinker/goku-api-gateway/common/endless"
log "github.com/eolinker/goku-api-gateway/goku-log"
"github.com/eolinker/goku-api-gateway/goku-node/cmd"
"runtime"
node_common "github.com/eolinker/goku-api-gateway/goku-node/node-common"
"github.com/eolinker/goku-api-gateway/common/database"
"github.com/eolinker/goku-api-gateway/common/general"
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"
)
var (
adminHost string
//adminPort int
listenPort int
)
func initConfig(resultInfo map[string]interface{}) *entity.ClusterInfo {
c := entity.ClusterInfo{}
clusterConfig, err := json.Marshal(resultInfo["cluster"])
if err != nil {
log.Panic(err)
}
err = json.Unmarshal(clusterConfig, &c)
if err != nil {
log.Panic(err)
}
return &c
}
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
flag.StringVar(&adminHost, "admin", "127.0.0.1:7005", "Please provide a valid host!")
//flag.IntVar(&adminPort, "P", 7005, "Please provide a valid port")
flag.IntVar(&listenPort, "port", 6689, "Please provide a valid listen port!")
isDebug := flag.Bool("debug", false, "")
flag.Parse()
if *isDebug {
log.StartDebug()
}
//
node_common.SetAdmin(adminHost)
node_common.ListenPort = listenPort
success, config := cmd.GetConfig(listenPort)
if !success {
log.Fatal(" Fail to get node config!")
return
}
node_common.SetClusterName(config.Name)
err := database.InitConnection(&config.DB)
if err != nil {
log.Fatal("Fail to Init db:", err)
return
}
goku_node.InitLog()
log.Debug("gokNode.InitLog")
r := redis_manager.Create(&config.Redis)
redis_manager.SetDefault(r)
log.Debug("redis-manager.SetDefault")
// 其他需要初始化的模块
_ = general.General()
log.Debug("general.General()")
goku_node.InitServer()
go cmd.Heartbeat(listenPort)
server := goku_node.NewRouter()
err = endless2.ListenAndServe(fmt.Sprintf(":%d", listenPort), server)
if err != nil {
log.Fatal(err)
}
log.Fatalf("Server on :%d stoped \n", listenPort)
}
/work/
/logs/
/node
package main
import (
"github.com/eolinker/goku-api-gateway/goku-service/driver/consul"
"github.com/eolinker/goku-api-gateway/goku-service/driver/eureka"
"github.com/eolinker/goku-api-gateway/goku-service/driver/static"
)
func init() {
consul.Register()
eureka.Register()
static.Register()
}
\ No newline at end of file
package main
import "flag"
//ParseFlag 获取命令行参数
func ParseFlag() (port int, admin string, staticConfigFile string, isDebug bool) {
adminP := flag.String("admin", "", "Please provide a valid host!")
portP := flag.Int("port", 0, "Please provide a valid listen port!")
staticConfigFileP := flag.String("config", "", "Please provide a config file")
isDebugP := flag.Bool("debug", false, "")
flag.Parse()
return *portP, *adminP, *staticConfigFileP, *isDebugP
}
package main
import (
"flag"
"github.com/eolinker/goku-api-gateway/config"
log "github.com/eolinker/goku-api-gateway/goku-log"
console2 "github.com/eolinker/goku-api-gateway/node/console"
"github.com/eolinker/goku-api-gateway/node/gateway"
"github.com/eolinker/goku-api-gateway/node/router/httprouter"
"github.com/eolinker/goku-api-gateway/node/server"
"runtime"
)
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
port, admin, staticConfigFile, isDebug := ParseFlag()
if isDebug {
log.StartDebug()
}
if port == 0{
flag.Usage()
return
}
if admin != "" {
// 从控制台启动,
console := console2.NewConsole(port, admin)
ser := server.NewServer(port)
ser.SetConsole(console)
log.Fatal(ser.Server())
} else if staticConfigFile != "" {
// 从静态文件启动
c, err := config.ReadConfig(staticConfigFile)
if err != nil {
log.Panic("read config from :", staticConfigFile, "\t", err)
}
server.SetLog(c.Log)
server.SetAccessLog(c.AccessLog)
r, err := gateway.Parse(c, httprouter.Factory())
if err != nil {
log.Panic("parse config error:", err)
}
ser := server.NewServer(port)
e := ser.SetRouter(r)
if e != nil {
log.Panic("init router error:", e)
}
log.Fatal(ser.Server())
} else {
//
flag.Usage()
return
}
}
......@@ -17,12 +17,12 @@ then
fi
buildApp goku-node $VERSION
buildApp node $VERSION
OUTPATH="${BasePath}/out/goku-node-${VERSION}"
OUTPATH="${BasePath}/out/node-${VERSION}"
mkdir ${OUTPATH}/plugin
cp -a ${BasePath}/build/goku-node/resources/* ${OUTPATH}/
cp -a ${BasePath}/build/node/resources/* ${OUTPATH}/
if [ -d "${BasePath}/out/plugins" ];then
cp -a ${BasePath}/out/plugins/* ${OUTPATH}/plugin/
fi
......
......@@ -5,7 +5,7 @@ cd ${BasePath}/
VERSION=$(genVersion $1)
folder="${BasePath}/out/goku-node-${VERSION}"
folder="${BasePath}/out/node-${VERSION}"
if [[ ! -d "$folder" ]]
then
......@@ -15,6 +15,6 @@ then
exit 1
fi
fi
packageApp goku-node $VERSION
packageApp node $VERSION
cd ${ORGPATH}
listen_port: 7000
admin_bind: 127.0.0.1:7005
db_host: 127.0.0.1
db_port: 3306
db_name: goku_ee
db_user: root
db_password: root
\ No newline at end of file
<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告警:$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>
$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>
</td>
</tr>
<tr>
<td style="line-height: 1.75em; padding-bottom: 40px;">
<p>接口名称:$apiName</p>
<p>apiID:$apiID</p>
<p>请求路径:$requestURL</p>
<p>转发路径:$targetServer</p>
<p>映射路径:$proxyURL</p>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
\ No newline at end of file
......@@ -70,16 +70,14 @@ stop() {
kill $pid >/dev/null 2>&1
if [[ $? != 0 ]];then
echo "$PROG stop error"
exit 1
fi
rm -f "$WORK_PATH/$PROG.pid"
echo "$PROG stopped"
else
echo "Error! $PROG not started!" 1>&2
fi
else
## Program is not running, exit with error.
echo "Error! $PROG not started!" 1>&2
echo "note! $PROG not started!" 1>&2
fi
}
......
......@@ -17,7 +17,7 @@
<title>GoKu Gateway | 企业微服务架构的首选解决方案,加速企业数字化转型</title>
<link href="assets/images/favicon.ico" rel="shortcut icon">
<!-- <base href="/"> -->
<link rel="stylesheet" href="styles/app-6e5f7694bf.css">
<link rel="stylesheet" href="styles/app-2b0238ab04.css">
</head>
<!--[if lt IE 8]>
<style>html,body{overflow:hidden;height:100%}</style>
......@@ -34,6 +34,6 @@
</div>
<eo-modal></eo-modal>
</body>
<script src="scripts/app-9b3cb8f46b.js"></script>
<script src="scripts/app-1b47111b19.js"></script>
</html>
\ No newline at end of file
<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告警:$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>
$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>
</td>
</tr>
<tr>
<td style="line-height: 1.75em; padding-bottom: 40px;">
<p>接口名称:$apiName</p>
<p>apiID:$apiID</p>
<p>请求路径:$requestURL</p>
<p>转发路径:$targetServer</p>
<p>映射路径:$proxyURL</p>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
\ No newline at end of file
#!/usr/bin/env bash
cd $(dirname $0) # 当前位置跳到脚本位置
APP="goku-node"
APP="node"
SOURCE_DIR="$(pwd)"
PRO_DIR="$(basename `pwd`)"
cd ../
......@@ -49,7 +49,7 @@ ln -sf $PRO_DIR ./$APP
mkdir -p work
mv $PRO_DIR/goku-node $PRO_DIR/gateway-node
ln -sf $INSTALL_DIR/work $PRO_DIR/
cd $PRO_DIR
......@@ -14,7 +14,7 @@
## Fill in name of program here.
cd $(dirname $0) # 当前位置跳到脚本位置
PROG="gateway-node"
PROG="node"
PROG_PATH="$(pwd)" ## Not need, but sometimes helpful (if $PROG resides in /opt for example).
WORK_PATH="$PROG_PATH/work"
......@@ -73,11 +73,9 @@ stop() {
rm -f "$WORK_PATH/$PROG.pid"
echo "$PROG stopped"
fi
else
## Program is not running, exit with error.
echo "Error! $PROG not started!" 1>&2
echo "Note! $PROG not started!" 1>&2
fi
}
......
......@@ -43,7 +43,7 @@ type (
ContextHandle interface {
SetContext(ctx Values) error
}
//CheckOptHandler 判断是否有opt字段
//CheckOptHandler 检查配置处理器
CheckOptHandler interface {
IsOpt(key string) bool
}
......@@ -53,7 +53,7 @@ type (
}
)
//IsOpt 是否是opt字段
//IsOpt 判断是否是opt标签
func IsOpt(key string, c interface{}) bool {
val := reflect.ValueOf(c).Elem()
typ := val.Type()
......@@ -71,7 +71,7 @@ func IsOpt(key string, c interface{}) bool {
return false
}
//ErrorNil error nil
//ErrorNil 当target为nil时,报错
var ErrorNil = errors.New("target is nil")
// SetValues 从url.Values中完成配置字段,context中不存在时,使用 default
......
......@@ -12,28 +12,28 @@ var (
lastFile = ""
)
//Get get
//Get 获取配置
func Get(name string) (string, bool) {
v, has := _Configure[name]
return v, has
}
//Set set
//Set 设置配置项
func Set(name, value string) {
_Configure[name] = value
}
//Value value
//Value 获取配置值
func Value(name string) string {
return _Configure[name]
}
//Reload reload
//Reload 重载配置
func Reload() {
ReadConfigure(lastFile)
}
//MastValue mastValue
//MastValue 获取配置值,若没有,返回默认值
func MastValue(name string, def string) string {
v, h := _Configure[name]
if h {
......@@ -42,7 +42,7 @@ func MastValue(name string, def string) string {
return def
}
//ReadConfigure 读取配置
//ReadConfigure 读取配置信息
func ReadConfigure(filepath string) error {
file, err := os.Open(filepath)
if err != nil {
......@@ -64,6 +64,12 @@ func ReadConfigure(filepath string) error {
//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
......
......@@ -2,20 +2,23 @@ package database
import (
"database/sql"
"fmt"
"io/ioutil"
"strings"
log "github.com/eolinker/goku-api-gateway/goku-log"
// mysql包
_ "github.com/go-sql-driver/mysql"
)
const (
dbMysql = "mysql"
//mysql数据库驱动
_ "github.com/go-sql-driver/mysql"
//sqlite3数据库驱动
_ "github.com/mattn/go-sqlite3"
)
var (
defaultDB *sql.DB
)
//InitConnection 初始化连接
//InitConnection 初始化数据库连接
func InitConnection(config Config) error {
db, e := getConnection(config)
defaultDB = db
......@@ -23,12 +26,6 @@ func InitConnection(config Config) error {
}
func getConnection(config Config) (*sql.DB, error) {
//var dsn string
//dsn = conf.Value("db_user") + ":" + conf.Value("db_password")
//dsn = dsn + "@tcp(" + conf.Value("db_host") + ":" + conf.Value("db_port") + ")/" + conf.Value("db_name")
//dsn = dsn + "?charset=utf8"
db, e := sql.Open(config.GetDriver(), config.GetSource())
if e == nil {
......@@ -40,15 +37,32 @@ func getConnection(config Config) (*sql.DB, error) {
db.SetMaxIdleConns(100)
defaultDB = db
return db, nil
} else {
log.Info(e)
return nil, e
}
log.Info(e)
return nil, e
}
//GetConnection 获取连接
//GetConnection 获取数据库连接
func GetConnection() *sql.DB {
return defaultDB
}
//InitTable 初始化表
func InitTable() error {
content, err := ioutil.ReadFile("sql/goku_ce.sql")
sqls := strings.Split(string(content), ";")
Tx, _ := GetConnection().Begin()
for _, sql := range sqls {
_, err = Tx.Exec(sql)
if err != nil {
fmt.Println(sql)
Tx.Rollback()
panic(err)
return err
}
}
Tx.Commit()
return nil
}
package database
//Config 数据库配置结构体
type Config interface {
GetDriver() string
GetSource() string
......
......@@ -5,8 +5,6 @@ import (
"errors"
"fmt"
log "github.com/eolinker/goku-api-gateway/goku-log"
cmd2 "github.com/eolinker/goku-api-gateway/goku-node/cmd"
"net"
"net/http"
"os"
......@@ -20,19 +18,12 @@ 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
)
......@@ -43,14 +34,10 @@ var (
socketPtrOffsetMap map[string]uint
runningServersForked bool
//DefaultReadTimeOut 默认读超时时间
DefaultReadTimeOut time.Duration
//DefaultWriteTimeOut 默认写超时时间
DefaultWriteTimeOut time.Duration
//DefaultMaxHeaderBytes 默认请求头最大字节数
DefaultReadTimeOut time.Duration
DefaultWriteTimeOut time.Duration
DefaultMaxHeaderBytes int
//DefaultHammerTime default hammer time
DefaultHammerTime time.Duration
DefaultHammerTime time.Duration
isChild bool
socketOrder string
......@@ -58,7 +45,7 @@ var (
hookableSignals []os.Signal
)
var isStop = true
var isStop bool = true
func init() {
runningServerReg = sync.RWMutex{}
......@@ -431,7 +418,7 @@ func (srv *endlessServer) hammerTime(d time.Duration) {
func (srv *endlessServer) fork() (err error) {
cmd2.StopNode()
runningServerReg.Lock()
defer runningServerReg.Unlock()
// only one server instance should fork!
......
package general
//InitFunc init func
//InitFunc 初始化函数
type InitFunc func() error
var (
......@@ -8,7 +8,7 @@ var (
_laterFunc []InitFunc
)
//RegeditInit 初始化注册
//RegeditInit 注册初始化
func RegeditInit(fn InitFunc) {
_initFunc = append(_initFunc, fn)
......@@ -29,7 +29,7 @@ func General() error {
return nil
}
//RegeditLater regedit later
//RegeditLater regeditlater
func RegeditLater(fn InitFunc) {
_laterFunc = append(_laterFunc, fn)
}
package listener
import "sync"
//CallbackFunc 回调函数
type CallbackFunc func(event interface{})
//Listener
type Listener struct {
callbacks []CallbackFunc
callbacksOnce []CallbackFunc
locker sync.Mutex
}
//New 创建监听
func New() *Listener {
return &Listener{
callbacks: nil,
callbacksOnce: nil,
locker: sync.Mutex{},
}
}
//ListenOnce listenOnce
func (l *Listener) ListenOnce(callbackFunc CallbackFunc) {
l.locker.Lock()
l.callbacksOnce = append(l.callbacksOnce, callbackFunc)
l.locker.Unlock()
}
//Listen listen
func (l *Listener) Listen(callbackFunc CallbackFunc) {
l.locker.Lock()
l.callbacks = append(l.callbacks, callbackFunc)
l.locker.Unlock()
}
//Call call
func (l *Listener) Call(event interface{}) {
l.locker.Lock()
cbs := l.callbacks
cbsO := l.callbacksOnce
l.callbacksOnce = nil
l.locker.Unlock()
for _, cb := range cbs {
cb(event)
}
for _, cb := range cbsO {
cb(event)
}
}
package redismanager
package redis_manager
import (
"fmt"
"github.com/go-redis/redis"
"sort"
......
package redismanager
package redis_manager
//
//func GetKeys(r Redis, pattern string) ([]string, error) {
......
package redismanager
package redis_manager
import (
"sync"
......@@ -11,7 +11,7 @@ var (
locker sync.RWMutex
)
//InitRedisOfCluster 初始化集群redis
//InitRedisOfCluster 初始化集群redis
func InitRedisOfCluster(rs map[string]RedisConfig) {
locker.Lock()
defer locker.Unlock()
......@@ -29,7 +29,7 @@ func get(name string) (Redis, bool) {
return r, h
}
//Get 获取redis
//Get 获取配置
func Get(name string) (Redis, bool) {
r, has := get(name)
......
package redismanager
package redis_manager
import (
"github.com/go-redis/redis"
......
package redismanager
package redis_manager
import "github.com/go-redis/redis"
......@@ -9,7 +9,7 @@ const (
RedisModeStand = "stand"
)
//Redis redis
//Redis redis接口
type Redis interface {
redis.Cmdable
GetConfig() RedisConfig
......@@ -17,7 +17,7 @@ type Redis interface {
Nodes() []string
}
//RedisConfig redis config
//RedisConfig redis配置
type RedisConfig interface {
GetMode() string
GetAddrs() []string
......
package redismanager
package redis_manager
import (
"sync"
......
package telegraph
import (
"context"
"sync"
)
//Telegraph telegraph
type Telegraph struct {
value interface{}
version string
locker sync.RWMutex
c chan struct{}
}
//NewTelegraph 创建telegraph
func NewTelegraph(version string, value interface{}) *Telegraph {
return &Telegraph{
value: value,
version: version,
locker: sync.RWMutex{},
c: make(chan struct{}),
}
}
//Set set
func (t *Telegraph) Set(version string, value interface{}) {
t.locker.Lock()
close(t.c)
t.version = version
t.value = value
t.c = make(chan struct{})
t.locker.Unlock()
}
func (t *Telegraph) get() (string, <-chan struct{}, interface{}) {
t.locker.RLock()
version, c, value := t.version, t.c, t.value
t.locker.RUnlock()
return version, c, value
}
//Get get
func (t *Telegraph) Get(version string) interface{} {
return t.GetWidthContext(context.Background(), version)
}
//Close close
func (t *Telegraph) Close() {
t.locker.Lock()
close(t.c)
t.version = ""
t.locker.Unlock()
}
//GetWidthContext 获取上下文
func (t *Telegraph) GetWidthContext(ctx context.Context, version string) interface{} {
v, c, value := t.get()
if v == "" {
// closed
return nil
}
if version != v {
return value
}
select {
case <-c:
return t.GetWidthContext(ctx, version)
case <-ctx.Done():
return nil
}
}
package version
//Version 版本号
const Version = "3.0.0"
const Version = "3.1.0"
package config
//GokuConfig goku根配置
type GokuConfig struct {
Version string `json:"version"`
Cluster string `json:"cluster"`
//Port int `json:"port"`
DiscoverConfig map[string]*DiscoverConfig `json:"discover,omitempty"`
Balance map[string]*BalanceConfig `json:"balance,omitempty"`
Plugins *GatewayPluginConfig `json:"plugins,omitempty"`
APIS []*APIContent `json:"apis,omitempty"`
Strategy []*StrategyConfig `json:"strategy,omitempty"`
AnonymousStrategyID string `json:"anonymousStrategyID,omitempty"`
AuthPlugin map[string]string `json:"authPlugin,omitempty"`
Log *LogConfig `json:"log,omitempty"`
AccessLog *AccessLogConfig `json:"access_log,omitempty"`
}
//AccessLogConfig access日志配置
type AccessLogConfig struct {
Name string `json:"name"`
Enable int `json:"enable"`
Dir string `json:"dir"`
File string `json:"file"`
Period string `json:"period"`
Expire int `json:"expire"`
Fields []string `json:"fields"`
}
//LogConfig log日志配置
type LogConfig struct {
Name string `json:"name"`
Enable int `json:"enable"`
Dir string `json:"dir"`
File string `json:"file"`
Level string `json:"level"`
Period string `json:"period"`
Expire int `json:"expire"`
}
//GatewayPluginConfig 网关插件配置
type GatewayPluginConfig struct {
BeforePlugins []*PluginConfig `json:"before"`
GlobalPlugins []*PluginConfig `json:"global"`
}
//DiscoverConfig 服务发现配置
type DiscoverConfig struct {
Name string `json:"name"`
Driver string `json:"driver"`
Config string `json:"config"`
HealthCheck *HealthCheckConfig `json:"healthCheck"` // nil 表示不启用,非nil表示启用
}
//HealthCheckConfig 健康检查配置
type HealthCheckConfig struct {
IsHealthCheck bool `json:"is_health_check"`
URL string `json:"url"`
Second int `json:"second"`
TimeOutMill int `json:"timeoutMill"`
StatusCode string `json:"statusCode"`
}
//BalanceConfig 负载配置
type BalanceConfig struct {
Name string `json:"name"`
DiscoverName string `json:"discover"`
Config string `json:"config"` // appName(for discovery) or address (for static)
}
//PluginConfig 插件配置
type PluginConfig struct {
Name string `json:"name"`
IsStop bool `json:"stop"`
Config string `json:"config"`
UpdateTag string `json:"updateTag"`
}
//APIContent api详情
type APIContent struct {
ID int `json:"id"`
Name string `json:"name"`
OutPutEncoder string `json:"output"`
RequestURL string `json:"requestUrl"`
Methods []string `json:"methods"`
TimeOutTotal int `json:"timeoutTotal"`
AlertThreshold int `json:"alert_threshold"`
Steps []*APIStepConfig `json:"steps"`
StaticResponseStrategy string `json:"static_respone_strategy"`
StaticResponse string `json:"staticResponse"`
}
//APIStepConfig 链路配置
type APIStepConfig struct {
Proto string `json:"proto"`
Balance string `json:"balance"`
Method string `json:"method"` // follow | get | post | put ...
Path string `json:"path"`
Body string `json:"body"`
Headers []string `json:"headers,omitempty"`
Decode string `json:"decode"` // origin | json
Encode string `json:"encode"` // origin | form | json
Actions []*ActionConfig `json:"actions"`
BlackList []string `json:"blackList"`
WhiteList []string `json:"whiteList"`
Target string `json:"target"`
Group string `json:"group"`
Retry int `json:"retry"`
TimeOut int `json:"timeout"`
}
//APIStepUIConfig 链路UI配置
type APIStepUIConfig struct {
Proto string `json:"proto"`
Balance string `json:"balance"`
Method string `json:"method"` // follow | get | post | put ...
Path string `json:"path"`
Body string `json:"body"`
Headers []string `json:"headers,omitempty"`
Decode string `json:"decode"` // origin | json
Encode string `json:"encode"` // origin | form | json
BlackList []string `json:"blackList"`
WhiteList []string `json:"whiteList"`
Move []MoveConfig `json:"move"`
Delete []DeleteConfig `json:"delete"`
Rename []RenameConfig `json:"rename"`
Target string `json:"target"`
Group string `json:"group"`
Retry int `json:"retry"`
TimeOut int `json:"timeout"`
}
//MoveConfig move配置
type MoveConfig struct {
Origin string `json:"origin"`
Target string `json:"target"`
}
//DeleteConfig delete配置
type DeleteConfig struct {
Origin string `json:"origin"`
}
//RenameConfig rename配置
type RenameConfig struct {
Origin string `json:"origin"`
Target string `json:"target"`
}
//ActionConfig action配置
type ActionConfig struct {
ActionType string `json:"type"`
Original string `json:"original"`
Target string `json:"target"`
}
//StrategyConfig 策略配置
type StrategyConfig struct {
ID string `json:"id"`
Name string `json:"name"`
Enable bool `json:"enable"`
APIS []*APIOfStrategy `json:"apis"`
AUTH map[string]string `json:"auth"`
Plugins []*PluginConfig `json:"plugins"`
}
//APIOfStrategy 策略接口配置
type APIOfStrategy struct {
ID int `json:"id"`
Balance string `json:"balance"` // 单step有效
Plugins []*PluginConfig `json:"plugins"`
}
//VersionConfig 版本配置
type VersionConfig struct {
VersionID int `json:"versionID"`
Name string `json:"name"`
Version string `json:"version"`
Remark string `json:"remark"`
CreateTime string `json:"createTime"`
PublishStatus int `json:"publishStatus"`
PublishTime string `json:"publishTime"`
}
//Project 项目
type Project struct {
ID int `json:"id"`
Name string `json:"name"`
CreateTime string `json:"createTime"`
}
package config
import (
"encoding/json"
"io/ioutil"
"path/filepath"
)
//ReadConfig 读取文件配置
func ReadConfig(file string) (*GokuConfig, error) {
fp, err := filepath.Abs(file)
if err != nil {
return nil, err
}
data, err := ioutil.ReadFile(fp)
if err != nil {
return nil, err
}
c := &GokuConfig{}
e := json.Unmarshal(data, c)
return c, e
}
package config
import "strings"
//StaticResponseStrategy 静态响应策略
type StaticResponseStrategy int
const (
//Always always
Always StaticResponseStrategy = iota
//Success success
Success
//Errored errored
Errored
//Incomplete incomplete
Incomplete
)
func (s StaticResponseStrategy) String() string {
switch s {
case Always:
return "always"
case Success:
return "success"
case Errored:
return "errored"
case Incomplete:
return "incomplete"
}
return "unknown"
}
//Parse parse
func Parse(v string) StaticResponseStrategy {
switch strings.ToLower(v) {
case "always":
return Always
case "success":
return Success
case "errored":
return Errored
case "incomplete":
return Incomplete
}
return Always
}
//Title title
func (s StaticResponseStrategy) Title() string {
switch s {
case Always:
return "Always - Present in every response"
case Success:
return "Success - Present in every non-failed response "
case Errored:
return "Errored - Present in every failed response (error not nil)"
case Incomplete:
return "Incomplete - Present in incomplete responses"
}
return "unknown"
}
package admin
import (
"net/http"
"strconv"
"strings"
"github.com/eolinker/goku-api-gateway/console/controller"
alert_module "github.com/eolinker/goku-api-gateway/console/module/alert"
"github.com/eolinker/goku-api-gateway/utils"
)
// AddAlertMsg 新增告警信息
func AddAlertMsg(httpResponse http.ResponseWriter, httpRequest *http.Request) {
nodeIP := httpRequest.RemoteAddr
requestID := httpRequest.PostFormValue("requestID")
apiName := httpRequest.PostFormValue("apiName")
requestURL := httpRequest.PostFormValue("requestURL")
targetServer := httpRequest.PostFormValue("targetServer")
targetURL := httpRequest.PostFormValue("targetURL")
requestMethod := httpRequest.PostFormValue("requestMethod")
proxyMethod := httpRequest.PostFormValue("proxyMethod")
alertPeriodType := httpRequest.PostFormValue("alertPeriodType")
alertCount := httpRequest.PostFormValue("alertCount")
headerList := httpRequest.PostFormValue("headerList")
queryParamList := httpRequest.PostFormValue("queryParamList")
formParamList := httpRequest.PostFormValue("formParamList")
responseHeaderList := httpRequest.PostFormValue("responseHeaderList")
responseStatus := httpRequest.PostFormValue("responseStatus")
isAlert := httpRequest.PostFormValue("isAlert")
clusterName := httpRequest.PostFormValue("clusterName")
nodePort := httpRequest.PostFormValue("nodePort")
apiID := httpRequest.PostFormValue("apiID")
strategyID := httpRequest.PostFormValue("strategyID")
strategyName := httpRequest.PostFormValue("strategyName")
ip := utils.InterceptIP(nodeIP, ":") + ":" + nodePort
if realIP := strings.TrimSpace(httpRequest.Header.Get("X-Real-Ip")); realIP != "" {
ip = realIP + ":" + nodePort
}
period, err := strconv.Atoi(alertPeriodType)
if err != nil {
controller.WriteError(httpResponse,
"330002",
"alert",
"[ERROR]Illegal alertPeriodType!",
err)
return
}
count, err := strconv.Atoi(alertCount)
if err != nil {
controller.WriteError(httpResponse,
"330003",
"alert",
"[ERROR]Illegal alertCount!",
err)
return
}
status, err := strconv.Atoi(responseStatus)
if err != nil {
controller.WriteError(httpResponse,
"330004",
"alert",
"[ERROR]Illegal responseStatus!",
err)
return
}
alert := false
if isAlert == "true" {
alert = true
}
flag, result, err := alert_module.AddAlertMsg(apiID, apiName, requestURL, targetServer, targetURL, requestMethod, proxyMethod, headerList, queryParamList, formParamList, responseHeaderList, strategyID, strategyName, requestID, period, count, status, alert, ip, clusterName)
if !flag {
controller.WriteError(httpResponse,
"330000",
"alert",
result,
err)
return
}
controller.WriteResultInfo(httpResponse, "alert", "", nil)
}
......@@ -6,8 +6,8 @@ import (
"strings"
)
//GetIpPort 获取IP端口
func GetIpPort(r *http.Request) (string, int, error) {
//GetIPPort 获取客户端IP和端口
func GetIPPort(r *http.Request) (string, int, error) {
ip := r.RemoteAddr
ip = ip[:strings.Index(ip, ":")]
if realIP := strings.TrimSpace(r.Header.Get("X-Real-Ip")); realIP != "" {
......
package admin
import (
"fmt"
"github.com/eolinker/goku-api-gateway/console/controller"
"github.com/eolinker/goku-api-gateway/console/module/node"
cluster2 "github.com/eolinker/goku-api-gateway/server/cluster"
"github.com/eolinker/goku-api-gateway/server/entity"
"net/http"
"strconv"
)
//Register 注册
func Register(w http.ResponseWriter, r *http.Request) {
ip, port, err := GetIpPort(r)
if err != nil {
controller.WriteError(w, "700000", "cluster", err.Error(), err)
return
}
cluster, err := regedister(ip, port)
if err != nil {
controller.WriteError(w, "700001", "cluster", err.Error()+ip, err)
return
}
node.Refresh(ip, strconv.Itoa(port))
controller.WriteResultInfo(w, "cluster", "cluster", cluster)
}
func regedister(ip string, port int) (*entity.ClusterInfo, error) {
func getCluster(ip string, port int) (string, error) {
has, node, err := node.GetNodeInfoByIPPort(ip, port)
if err != nil {
return nil, err
return "", err
}
if !has {
return nil, err
}
cName := node.Cluster
info, has := cluster2.Get(cName)
if has {
return info, nil
return "", err
}
return nil, fmt.Errorf("not has that node[%s:%d]", ip, port)
return node.Cluster, nil
}
......@@ -5,9 +5,7 @@ import "net/http"
//noinspection GoTypesCompatibility
func router() http.Handler {
serverHandler := http.NewServeMux()
serverHandler.HandleFunc("/register", Register)
serverHandler.HandleFunc("/node/heartbeat", heartbead)
serverHandler.HandleFunc("/node/stop", stopNode)
serverHandler.HandleFunc("/alert/msg/add", AddAlertMsg)
serverHandler.HandleFunc("/version/config/get", GetVersionConfig)
return serverHandler
}
......@@ -2,10 +2,13 @@ package admin
import (
"net/http"
"github.com/eolinker/goku-api-gateway/console/module/versionConfig"
)
//StartServer 开启admin服务
func StartServer(bind string) error {
handler := router()
versionConfig.InitVersionConfig()
return http.ListenAndServe(bind, handler)
}
package admin
import (
"github.com/eolinker/goku-api-gateway/console/controller"
"github.com/eolinker/goku-api-gateway/console/module/node"
"net/http"
"strconv"
)
func heartbead(w http.ResponseWriter, r *http.Request) {
"github.com/eolinker/goku-api-gateway/console/module/node"
"github.com/eolinker/goku-api-gateway/console/module/versionConfig"
ip, port, err := GetIpPort(r)
if err != nil {
"github.com/eolinker/goku-api-gateway/console/controller"
)
controller.WriteError(w, "700000", "node", err.Error(), err)
//GetVersionConfig 获取版本配置
func GetVersionConfig(httpResponse http.ResponseWriter, httpRequest *http.Request) {
httpRequest.ParseForm()
version := httpRequest.Form.Get("version")
ip, port, err := GetIPPort(httpRequest)
if err != nil {
controller.WriteError(httpResponse, "700000", "cluster", err.Error(), err)
return
}
node.Refresh(ip, strconv.Itoa(port))
controller.WriteResultInfo(w, "node", "node", nil)
}
func stopNode(w http.ResponseWriter, r *http.Request) {
ip, port, err := GetIpPort(r)
cluster, err := getCluster(ip, port)
if err != nil {
controller.WriteError(w, "700000", "node", err.Error(), err)
controller.WriteError(httpResponse, "700001", "cluster", err.Error()+ip, err)
return
}
node.NodeStop(ip, strconv.Itoa(port))
controller.WriteResultInfo(w, "node", "node", nil)
result := versionConfig.GetVersionConfig(cluster, version)
httpResponse.Write(result)
}
package console
import (
"io/ioutil"
"strconv"
"github.com/pkg/errors"
"github.com/eolinker/goku-api-gateway/common/conf"
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"
"gopkg.in/yaml.v2"
)
func loadCluster(file string) ([]*entity.ClusterInfo, error) {
body, err := ioutil.ReadFile(file)
if err != nil {
return nil, err
}
tv := struct {
Cluster []*entity.ClusterInfo `yaml:cluster`
}{}
err = yaml.Unmarshal(body, &tv)
if err != nil {
return nil, err
}
cs := make([]*entity.ClusterInfo, 0, len(tv.Cluster)+1)
for _, v := range tv.Cluster {
cs = append(cs, v)
}
return cs, nil
}
func getDefaultDatabase() (*entity.ClusterDB, error) {
dbPort, err := strconv.Atoi(conf.MastValue("db_port", "3306"))
if err != nil {
return nil, err
dbType := conf.MastValue("db_type", "sqlite3")
switch dbType {
case mysqlDriver:
{
dbPort, err := strconv.Atoi(conf.MastValue("db_port", "3306"))
if err != nil {
return nil, err
}
return &entity.ClusterDB{
Driver: dbType,
Host: conf.Value("db_host"),
Port: dbPort,
UserName: conf.Value("db_user"),
Password: conf.Value("db_password"),
Database: conf.Value("db_name"),
}, nil
}
case sqlite3Driver:
{
return &entity.ClusterDB{
Driver: dbType,
Path: conf.MastValue("db_path", "./work/goku.db"),
}, nil
}
default:
{
return nil, errors.New("unsupported database type")
}
}
return &entity.ClusterDB{
Driver: conf.MastValue("db_type", "mysql"),
Host: conf.Value("db_host"),
Port: dbPort,
UserName: conf.Value("db_user"),
Password: conf.Value("db_password"),
Database: conf.Value("db_name"),
}, nil
}
//InitClusters 初始化集群
func InitClusters() {
infos, err := loadCluster(conf.MastValue("cluster_config", "config/cluster.yaml"))
if err != nil {
panic(err)
}
all := infos
err = console_mysql.InsertClusters(all)
if err != nil {
panic(err)
}
cs, err := console_mysql.LoadClusters()
if err != nil {
panic(err)
}
currentClusters := make([]*entity.ClusterInfo, 0, len(infos))
redisOfCluster := make(map[string]redis_manager.RedisConfig)
for _, info := range infos {
c := cs[info.Name]
currentClusters = append(currentClusters, c)
redisOfCluster[c.Name] = c.Redis
}
redis_manager.InitRedisOfCluster(redisOfCluster)
cluster2.Init(currentClusters)
}
......@@ -2,18 +2,17 @@ package account
import (
"errors"
"net/http"
"strconv"
"github.com/eolinker/goku-api-gateway/console/controller"
"github.com/eolinker/goku-api-gateway/console/module/account"
"github.com/eolinker/goku-api-gateway/utils"
"net/http"
"strconv"
)
//Login 用户登录
func Login(httpResponse http.ResponseWriter, httpRequest *http.Request) {
//resultInfo := entity2.ResultInfo{}
loginCall := httpRequest.PostFormValue("loginCall")
loginPassword := httpRequest.PostFormValue("loginPassword")
......
......@@ -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)
......
package alert
import (
"net/http"
"strconv"
log "github.com/eolinker/goku-api-gateway/goku-log"
"github.com/eolinker/goku-api-gateway/console/controller"
alert_module "github.com/eolinker/goku-api-gateway/console/module/alert"
)
// GetAlertMsgList 获取告警信息列表
func GetAlertMsgList(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAlert, controller.OperationREAD)
if e != nil {
return
}
page := httpRequest.PostFormValue("page")
pageSize := httpRequest.PostFormValue("pageSize")
p, err := strconv.Atoi(page)
if err != nil {
p = 1
}
pSize, err := strconv.Atoi(pageSize)
if err != nil {
pSize = 15
}
_, result, count, err := alert_module.GetAlertMsgList(p, pSize)
controller.WriteResultInfoWithPage(httpResponse, "alert", "alertMessageList", result, &controller.PageInfo{
ItemNum: len(result),
TotalNum: count,
Page: p,
PageSize: pSize,
})
return
}
//ClearAlertMsg 清空告警信息列表
func ClearAlertMsg(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAlert, controller.OperationEDIT)
if e != nil {
return
}
flag, result, err := alert_module.ClearAlertMsg()
if !flag {
controller.WriteError(httpResponse,
"330000",
"alert",
result,
err)
return
}
controller.WriteResultInfo(httpResponse, "alert", "", nil)
return
}
//DeleteAlertMsg 删除告警信息
func DeleteAlertMsg(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAlert, controller.OperationEDIT)
if e != nil {
return
}
alertID := httpRequest.PostFormValue("alertID")
id, err := strconv.Atoi(alertID)
if err != nil {
log.Debug(err)
controller.WriteError(httpResponse,
"330001",
"alert",
"[ERROR]Illegal alertID!",
err)
return
}
flag, result, err := alert_module.DeleteAlertMsg(id)
if !flag {
controller.WriteError(httpResponse,
"330000",
"alert",
result,
err)
return
}
controller.WriteResultInfo(httpResponse, "alert", "", nil)
return
}
//GetAlertConfig 获取告警配置
func GetAlertConfig(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAlert, controller.OperationREAD)
if e != nil {
return
}
flag, result, err := alert_module.GetAlertConfig()
if !flag {
controller.WriteError(httpResponse,
"320000",
"gateway",
"[ERROR]The gateway config does not exist",
err)
return
}
controller.WriteResultInfo(httpResponse, "alert", "gatewayConfig", result)
return
}
......@@ -21,20 +21,21 @@ func AddAPI(httpResponse http.ResponseWriter, httpRequest *http.Request) {
apiName := httpRequest.PostFormValue("apiName")
requestURL := httpRequest.PostFormValue("requestURL")
requestMethod := httpRequest.PostFormValue("requestMethod")
// targetServer := httpRequest.PostFormValue("targetServer")
stripSlash := httpRequest.PostFormValue("stripSlash")
protocol := httpRequest.PostFormValue("protocol")
balanceName := httpRequest.PostFormValue("balanceName")
targetURL := httpRequest.PostFormValue("targetURL")
targetMethod := httpRequest.PostFormValue("targetMethod")
isFollow := httpRequest.PostFormValue("isFollow")
stripPrefix := httpRequest.PostFormValue("stripPrefix")
timeout := httpRequest.PostFormValue("timeout")
retryCount := httpRequest.PostFormValue("retryCount")
groupID := httpRequest.PostFormValue("groupID")
projectID := httpRequest.PostFormValue("projectID")
alertValve := httpRequest.PostFormValue("alertValve")
managerID := httpRequest.PostFormValue("managerID")
apiType := httpRequest.PostFormValue("apiType")
linkApis := httpRequest.PostFormValue("linkApis")
staticResponse := httpRequest.PostFormValue("staticResponse")
responseDataType := httpRequest.PostFormValue("responseDataType")
if apiName == "" {
controller.WriteError(httpResponse, "190002", "api", "[ERROR]Illegal apiName!", nil)
......@@ -48,22 +49,22 @@ func AddAPI(httpResponse http.ResponseWriter, httpRequest *http.Request) {
if isFollow == "" {
isFollow = "false"
}
if stripPrefix != "true" && stripPrefix != "false" {
controller.WriteError(httpResponse, "190009", "api", "[ERROR]Illegal stripPrefix!", nil)
return
aType, err := strconv.Atoi(apiType)
if err != nil && apiType == "" {
controller.WriteError(httpResponse, "190012", "api", "[ERROR]Illegal apiType!", err)
return
}
if stripPrefix != "true" && stripPrefix != "false" {
controller.WriteError(httpResponse, "190009", "api", "[ERROR]Illegal stripPrefix!", nil)
if responseDataType != "origin" && responseDataType != "json" && responseDataType != "xml" {
controller.WriteError(httpResponse, "190013", "api", "[ERROR]Illegal responseDataType!", err)
return
}
t, err := strconv.Atoi(timeout)
if err != nil && timeout != "" {
controller.WriteError(httpResponse, "190010", "api", "[ERROR]Illegal timeout!", err)
return
}
count, err := strconv.Atoi(retryCount)
if err != nil && retryCount != "" {
controller.WriteError(httpResponse, "190011", "api", "[ERROR]Illegal retryCount!", err)
......@@ -101,13 +102,8 @@ func AddAPI(httpResponse http.ResponseWriter, httpRequest *http.Request) {
if managerID == "" {
mgID = userID
}
// exist := api.CheckURLIsExist(requestURL, requestMethod, pjID, 0)
// if exist {
// controller.WriteError(httpResponse, "190005", "api", "[ERROR]URL Repeat!", nil)
// 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, linkApis, staticResponse, responseDataType, balanceName, protocol, pjID, gID, t, count, apiValve, mgID, userID, aType)
if !flag {
controller.WriteError(httpResponse,
......@@ -131,19 +127,19 @@ func EditAPI(httpResponse http.ResponseWriter, httpRequest *http.Request) {
requestURL := httpRequest.PostFormValue("requestURL")
targetURL := httpRequest.PostFormValue("targetURL")
requestMethod := httpRequest.PostFormValue("requestMethod")
// targetServer := httpRequest.PostFormValue("targetServer")
stripSlash := httpRequest.PostFormValue("stripSlash")
protocol := httpRequest.PostFormValue("protocol")
balanceName := httpRequest.PostFormValue("balanceName")
targetMethod := httpRequest.PostFormValue("targetMethod")
isFollow := httpRequest.PostFormValue("isFollow")
stripPrefix := httpRequest.PostFormValue("stripPrefix")
timeout := httpRequest.PostFormValue("timeout")
retryCount := httpRequest.PostFormValue("retryCount")
groupID := httpRequest.PostFormValue("groupID")
projectID := httpRequest.PostFormValue("projectID")
alertValve := httpRequest.PostFormValue("alertValve")
managerID := httpRequest.PostFormValue("managerID")
linkApis := httpRequest.PostFormValue("linkApis")
staticResponse := httpRequest.PostFormValue("staticResponse")
responseDataType := httpRequest.PostFormValue("responseDataType")
if apiName == "" {
controller.WriteError(httpResponse, "190002", "api", "[ERROR]Illegal apiName!", nil)
return
......@@ -154,6 +150,10 @@ func EditAPI(httpResponse http.ResponseWriter, httpRequest *http.Request) {
controller.WriteError(httpResponse, "190001", "api", "[ERROR]Illegal apiID!", nil)
return
}
if responseDataType != "origin" && responseDataType != "json" && responseDataType != "xml" {
controller.WriteError(httpResponse, "190013", "api", "[ERROR]Illegal responseDataType!", err)
return
}
if isFollow != "true" && isFollow != "false" && isFollow != "" {
controller.WriteError(httpResponse, "190008", "api", "[ERROR]Illegal isFollow!", nil)
......@@ -163,11 +163,6 @@ func EditAPI(httpResponse http.ResponseWriter, httpRequest *http.Request) {
if isFollow == "" {
isFollow = "false"
}
if stripPrefix != "true" && stripPrefix != "false" {
controller.WriteError(httpResponse, "190009", "api", "[ERROR]Illegal stripPrefix!", nil)
return
}
t, err := strconv.Atoi(timeout)
if err != nil && timeout != "" {
controller.WriteError(httpResponse, "190010", "api", "[ERROR]Illegal timeout!", nil)
......@@ -212,13 +207,8 @@ func EditAPI(httpResponse http.ResponseWriter, httpRequest *http.Request) {
if managerID == "" {
mgID = userID
}
// exist := api.CheckURLIsExist(requestURL, requestMethod, pjID, aID)
// if exist {
// controller.WriteError(httpResponse, "190005", "api", "[ERROR]URL Repeat!", nil)
// 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, linkApis, staticResponse, responseDataType, balanceName, protocol, pjID, gID, t, count, apiValve, aID, mgID, userID)
if !flag {
controller.WriteError(httpResponse, "190000", "api", "[ERROR]apiID does not exist!", err)
......@@ -426,7 +416,7 @@ func GetAPIManagerList(httpResponse http.ResponseWriter, httpRequest *http.Reque
return
}
//CopyAPI 接口复制
//CopyAPI 复制接口
func CopyAPI(httpResponse http.ResponseWriter, httpRequest *http.Request) {
userID, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAPI, controller.OperationEDIT)
if e != nil {
......@@ -480,7 +470,8 @@ func CopyAPI(httpResponse http.ResponseWriter, httpRequest *http.Request) {
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)
linkApis, _ := json.Marshal(apiInfo.LinkAPIs)
flag, id, err := api.AddAPI(apiName, requestURL, targetURL, requestMethod, targetMethod, isFollow, string(linkApis), apiInfo.StaticResponse, apiInfo.ResponseDataType, balanceName, protocol, pjID, gID, apiInfo.Timeout, apiInfo.RetryConut, apiInfo.Valve, apiInfo.ManagerID, userID, apiInfo.APIType)
if !flag {
controller.WriteError(httpResponse, "190000", "api", "[ERROR]Fail to add api!", err)
return
......
......@@ -185,8 +185,3 @@ func GetAPIGroupList(httpResponse http.ResponseWriter, httpRequest *http.Request
controller.WriteResultInfo(httpResponse, "apiGroup", "groupList", result)
return
}
//UpdateAPIGroupScript 更新接口分组脚本
func UpdateAPIGroupScript(httpResponse http.ResponseWriter, httpRequest *http.Request) {
api.UpdateAPIGroupScript()
}
......@@ -399,7 +399,7 @@ func BatchDeleteAPIPlugin(httpResponse http.ResponseWriter, httpRequest *http.Re
controller.WriteResultInfo(httpResponse, "apiPlugin", "", nil)
}
//GetAPIPluginListWithNotAssignAPIList 获取没有绑定接口插件的接口列表
//GetAPIPluginListWithNotAssignAPIList 获取没有分配接口插件的接口列表
func GetAPIPluginListWithNotAssignAPIList(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationAPI, controller.OperationREAD)
if e != nil {
......@@ -428,8 +428,3 @@ func GetAPIPluginListWithNotAssignAPIList(httpResponse http.ResponseWriter, http
controller.WriteResultInfo(httpResponse, "apiPlugin", "pluginList", result)
}
//UpdateAllAPIPluginUpdateTag 更新所有标识
func UpdateAllAPIPluginUpdateTag() error {
return api.UpdateAllAPIPluginUpdateTag()
}
......@@ -2,9 +2,12 @@ package cluster
import (
"net/http"
"regexp"
"github.com/pkg/errors"
"github.com/eolinker/goku-api-gateway/console/controller"
cluster2 "github.com/eolinker/goku-api-gateway/server/cluster"
"github.com/eolinker/goku-api-gateway/console/module/cluster"
)
//GetClusterList 获取集群列表
......@@ -13,26 +16,133 @@ func GetClusterList(httpResponse http.ResponseWriter, httpRequest *http.Request)
if e != nil {
return
}
list := cluster2.GetList()
list, _ := cluster.GetClusters()
controller.WriteResultInfo(httpResponse,
"cluster",
"clusters",
list)
}
//GetCluster 获取集群信息
func GetCluster(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationNone, controller.OperationREAD)
if e != nil {
return
}
httpRequest.ParseForm()
name := httpRequest.Form.Get("name")
result, err := cluster.GetCluster(name)
if err != nil {
controller.WriteError(httpResponse, "370000", "cluster", "[ERROR]The cluster does not exist", err)
return
}
controller.WriteResultInfo(httpResponse,
"cluster",
"clusterInfo",
result)
}
//AddCluster 新增集群
func AddCluster(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationNone, controller.OperationREAD)
if e != nil {
return
}
httpRequest.ParseForm()
name := httpRequest.Form.Get("name")
title := httpRequest.Form.Get("title")
note := httpRequest.Form.Get("note")
match, err := regexp.MatchString(`^[a-zA-Z][a-zA-z0-9_]*$`, name)
if err != nil || !match {
controller.WriteError(httpResponse, "370001", "cluster", "[ERROR]Illegal cluster name", err)
return
}
if cluster.CheckClusterNameIsExist(name) {
controller.WriteError(httpResponse, "370003", "cluster", "[ERROR]Cluster name already exists", errors.New("[error]cluster name already exists"))
return
}
err = cluster.AddCluster(name, title, note)
if err != nil {
controller.WriteError(httpResponse, "370000", "cluster", err.Error(), err)
return
}
controller.WriteResultInfo(httpResponse,
"cluster",
"",
nil)
}
//EditCluster 新增集群
func EditCluster(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationNone, controller.OperationREAD)
if e != nil {
return
}
httpRequest.ParseForm()
name := httpRequest.Form.Get("name")
title := httpRequest.Form.Get("title")
note := httpRequest.Form.Get("note")
match, err := regexp.MatchString(`^[a-zA-Z][a-zA-z0-9_]*$`, name)
if err != nil || !match {
controller.WriteError(httpResponse, "370001", "cluster", "[ERROR]Illegal cluster name", err)
return
}
err = cluster.EditCluster(name, title, note)
if err != nil {
controller.WriteError(httpResponse, "370000", "cluster", err.Error(), err)
return
}
controller.WriteResultInfo(httpResponse,
"cluster",
"",
nil)
}
//DeleteCluster 新增集群
func DeleteCluster(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationNone, controller.OperationREAD)
if e != nil {
return
}
httpRequest.ParseForm()
name := httpRequest.Form.Get("name")
match, err := regexp.MatchString(`^[a-zA-Z][a-zA-z0-9_]*$`, name)
if err != nil || !match {
controller.WriteError(httpResponse, "370001", "cluster", "[ERROR]Illegal cluster name", err)
return
}
nodeCount := cluster.GetClusterNodeCount(name)
if nodeCount > 0 {
controller.WriteError(httpResponse, "370002", "cluster", "[ERROR]There are nodes in the cluster", errors.New("[error]there are nodes in the cluster"))
return
}
err = cluster.DeleteCluster(name)
if err != nil {
controller.WriteError(httpResponse, "370000", "cluster", err.Error(), err)
return
}
controller.WriteResultInfo(httpResponse,
"cluster",
"",
nil)
}
//GetClusterInfoList 获取集群信息列表
func GetClusterInfoList(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationNone, controller.OperationREAD)
if e != nil {
return
}
all := cluster2.GetAll()
result, _ := cluster.GetClusters()
controller.WriteResultInfo(httpResponse,
"cluster",
"clusters",
all)
result)
}
package cluster
import (
"encoding/json"
"net/http"
"strconv"
"time"
"github.com/eolinker/goku-api-gateway/console/module/versionConfig"
"github.com/eolinker/goku-api-gateway/console/controller"
)
//GetVersionList 获取版本列表
func GetVersionList(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationNone, controller.OperationREAD)
if e != nil {
return
}
httpRequest.ParseForm()
keyword := httpRequest.Form.Get("keyword")
result, _ := versionConfig.GetVersionList(keyword)
controller.WriteResultInfo(httpResponse,
"versionConfig",
"configList",
result)
}
//AddVersionConfig 新增版本配置
func AddVersionConfig(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationNone, controller.OperationREAD)
if e != nil {
return
}
httpRequest.ParseForm()
name := httpRequest.Form.Get("name")
version := httpRequest.Form.Get("version")
remark := httpRequest.Form.Get("remark")
publish := httpRequest.Form.Get("publish")
p, err := strconv.Atoi(publish)
if err != nil && publish != "" {
controller.WriteError(httpResponse, "380003", "versionConfig", "[ERROR]Illegal publish", err)
return
}
//count := cluster.GetVersionConfigCount()
now := time.Now().Format("2006-01-02 15:04:05")
id, err := versionConfig.AddVersionConfig(name, version, remark, now)
if err != nil {
controller.WriteError(httpResponse, "380000", "versionConfig", err.Error(), err)
return
}
if p == 1 {
versionConfig.PublishVersion(id, now)
}
controller.WriteResultInfo(httpResponse,
"versionConfig",
"",
nil)
return
}
//BatchDeleteVersionConfig 批量删除版本配置
func BatchDeleteVersionConfig(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationNone, controller.OperationREAD)
if e != nil {
return
}
httpRequest.ParseForm()
ids := httpRequest.Form.Get("ids")
idList := make([]int, 0, 10)
err := json.Unmarshal([]byte(ids), &idList)
if err != nil {
controller.WriteError(httpResponse, "380001", "versionConfig", "[ERROR]Illegal ids", err)
return
}
if len(idList) > 0 {
err = versionConfig.BatchDeleteVersionConfig(idList)
if err != nil {
controller.WriteError(httpResponse, "380000", "versionConfig", err.Error(), err)
return
}
}
controller.WriteResultInfo(httpResponse,
"versionConfig",
"",
nil)
return
}
//PublishVersion 发布版本
func PublishVersion(httpResponse http.ResponseWriter, httpRequest *http.Request) {
httpRequest.ParseForm()
versionID := httpRequest.Form.Get("versionID")
id, err := strconv.Atoi(versionID)
if err != nil {
controller.WriteError(httpResponse, "380002", "versionConfig", "[ERROR]Illegal versionID", err)
return
}
now := time.Now().Format("2006-01-02 15:04:05")
err = versionConfig.PublishVersion(id, now)
if err != nil {
controller.WriteError(httpResponse, "380000", "versionConfig", err.Error(), err)
return
}
controller.WriteResultInfo(httpResponse,
"versionConfig",
"",
nil)
return
}
package configlog
package config_log
import (
"fmt"
......
package configlog
package config_log
import (
"fmt"
module "github.com/eolinker/goku-api-gateway/console/module/config-log"
"net/http"
"strings"
module "github.com/eolinker/goku-api-gateway/console/module/config-log"
)
//Handle 处理器
//Handle handle
func Handle(prefix string) http.Handler {
pre := strings.TrimSuffix(prefix, "/")
......
package configlog
package config_log
import (
"fmt"
......
......@@ -5,9 +5,10 @@ import (
"net/http"
"strings"
dao_service2 "github.com/eolinker/goku-api-gateway/server/dao/console-sqlite3/dao-service"
"github.com/eolinker/goku-api-gateway/console/controller"
"github.com/eolinker/goku-api-gateway/console/module/service"
dao_service "github.com/eolinker/goku-api-gateway/server/dao/console-mysql/dao-service"
)
func delete(w http.ResponseWriter, r *http.Request) {
......@@ -26,7 +27,7 @@ func delete(w http.ResponseWriter, r *http.Request) {
err = service.Delete(names)
if err != nil {
if en, ok := err.(dao_service.DeleteError); ok {
if en, ok := err.(dao_service2.DeleteError); ok {
controller.WriteError(w, "260000", "", fmt.Sprintf("删除[%s]失败,请先从负载中移除对该服务的引用", string(en)), err)
} else {
controller.WriteError(w, "260000", "serviceDiscovery", fmt.Sprintf("[error] %s", err.Error()), err)
......
......@@ -4,7 +4,7 @@ import (
"net/http"
)
//Handle 处理器
//Handle 服务发现处理器
func Handle(prefix string) http.Handler {
serveMux := http.NewServeMux()
......
package gateway
import (
"encoding/json"
"net/http"
"strconv"
"github.com/eolinker/goku-api-gateway/console/controller"
"github.com/eolinker/goku-api-gateway/console/module/gateway"
monitor_read "github.com/eolinker/goku-api-gateway/server/monitor/monitor-read"
)
//GetGatewayConfig 获取网关配置
......@@ -31,7 +31,7 @@ func GetGatewayConfig(httpResponse http.ResponseWriter, httpRequest *http.Reques
return
}
//EditGatewayBaseConfig 获取网关基本配置
//EditGatewayBaseConfig 编辑网关基本配置
func EditGatewayBaseConfig(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationGatewayConfig, controller.OperationEDIT)
if e != nil {
......@@ -81,8 +81,6 @@ func EditGatewayBaseConfig(httpResponse http.ResponseWriter, httpRequest *http.R
}
flag, result, err := gateway.EditGatewayBaseConfig(successCode, nodePeriod, monitorPeriod, timeout)
if !flag {
monitor_read.SetPeriod(monitorPeriod)
controller.WriteError(httpResponse,
"320000",
"gateway",
......@@ -154,3 +152,32 @@ func EditGatewayAlarmConfig(httpResponse http.ResponseWriter, httpRequest *http.
return
}
//GetGatewayBasicInfo 获取网关基本信息
func GetGatewayBasicInfo(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationNone, controller.OperationREAD)
if e != nil {
return
}
flag, result, err := gateway.GetGatewayMonitorSummaryByPeriod()
if !flag {
controller.WriteError(httpResponse,
"340000",
"monitor",
"[ERROR]The gateway basic information does not exist!",
err)
return
}
monitorInfo := map[string]interface{}{
"statusCode": "000000",
"type": "monitor",
"baseInfo": result.BaseInfo,
}
info, _ := json.Marshal(monitorInfo)
httpResponse.Write(info)
return
}
package monitor
import (
"encoding/json"
"net/http"
"strconv"
"time"
"github.com/eolinker/goku-api-gateway/console/controller"
"github.com/eolinker/goku-api-gateway/console/module/monitor"
"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 {
return
}
clusterName := httpRequest.PostFormValue("cluster")
clusterID, has := cluster.GetID(clusterName)
if !has && clusterName != "" {
controller.WriteError(httpResponse, "340003", "", "[ERROR]Illegal cluster!", nil)
return
}
beginTime := httpRequest.PostFormValue("beginTime")
endTime := httpRequest.PostFormValue("endTime")
period := httpRequest.PostFormValue("period")
p, err := strconv.Atoi(period)
if err != nil {
p = 0
}
bt, err := time.ParseInLocation("2006-01-02", beginTime, time.Local)
if err != nil && p == 3 {
controller.WriteError(httpResponse,
"340001",
"monitor",
"[ERROR]Illegal beginTime!",
err)
return
}
et, err := time.ParseInLocation("2006-01-02", endTime, time.Local)
if err != nil && p == 3 {
controller.WriteError(httpResponse,
"340002",
"monitor",
"[ERROR]Illegal endTime!",
err)
return
}
if bt.After(et) && p == 3 {
controller.WriteError(httpResponse,
"340003",
"monitor",
"[ERROR]beginTime should be before the endTime!",
nil)
return
}
flag, result, err := monitor.GetGatewayMonitorSummaryByPeriod(clusterID, beginTime, endTime, p)
if !flag {
controller.WriteError(httpResponse,
"340000",
"monitor",
"[ERROR]The gateway monitor information does not exist!",
err)
return
}
monitorInfo := map[string]interface{}{
"statusCode": "000000",
"type": "monitor",
"baseInfo": result.BaseInfo,
"gatewayRequestInfo": result.GatewayRequestInfo,
"proxyRequestInfo": result.ProxyInfo,
}
info, _ := json.Marshal(monitorInfo)
httpResponse.Write(info)
return
}
......@@ -4,6 +4,8 @@ import (
"encoding/json"
"errors"
"github.com/eolinker/goku-api-gateway/console/module/cluster"
log "github.com/eolinker/goku-api-gateway/goku-log"
"net/http"
......@@ -11,7 +13,6 @@ import (
"github.com/eolinker/goku-api-gateway/console/controller"
"github.com/eolinker/goku-api-gateway/console/module/node"
cluster2 "github.com/eolinker/goku-api-gateway/server/cluster"
"github.com/eolinker/goku-api-gateway/utils"
)
......@@ -25,8 +26,8 @@ func AddNode(httpResponse http.ResponseWriter, httpRequest *http.Request) {
cluserName := httpRequest.PostFormValue("cluster")
clusterID, has := cluster2.GetID(cluserName)
if !has {
clusterID := cluster.GetClusterIDByName(cluserName)
if clusterID == 0 {
controller.WriteError(httpResponse, "340003", "", "[ERROR]Illegal cluster!", nil)
return
}
......@@ -122,7 +123,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
}
......@@ -228,8 +229,8 @@ func GetNodeList(httpResponse http.ResponseWriter, httpRequest *http.Request) {
gID = -1
}
clusterID, has := cluster2.GetID(cluserName)
if !has {
clusterID := cluster.GetClusterIDByName(cluserName)
if clusterID == 0 {
controller.WriteError(httpResponse, "330003", "node", "[ERROR]The cluster dosen't exist!", nil)
return
}
......
......@@ -5,8 +5,8 @@ import (
"strconv"
"github.com/eolinker/goku-api-gateway/console/controller"
"github.com/eolinker/goku-api-gateway/console/module/cluster"
"github.com/eolinker/goku-api-gateway/console/module/node"
cluster2 "github.com/eolinker/goku-api-gateway/server/cluster"
)
//AddNodeGroup 新增节点分组
......@@ -19,9 +19,8 @@ func AddNodeGroup(httpResponse http.ResponseWriter, httpRequest *http.Request) {
cluserName := httpRequest.PostFormValue("cluster")
clusterID, has := cluster2.GetID(cluserName)
if !has {
clusterID := cluster.GetClusterIDByName(cluserName)
if clusterID == 0 {
controller.WriteError(httpResponse, "340003", "", "[ERROR]Illegal cluster!", nil)
return
}
......@@ -189,8 +188,8 @@ func GetNodeGroupList(httpResponse http.ResponseWriter, httpRequest *http.Reques
}
cluserName := httpRequest.FormValue("cluster")
clusterID, has := cluster2.GetID(cluserName)
if !has {
clusterID := cluster.GetClusterIDByName(cluserName)
if clusterID == 0 {
controller.WriteError(httpResponse,
"280001",
"nodeGroup",
......
......@@ -435,7 +435,7 @@ func BatchStartPlugin(httpResponse http.ResponseWriter, httpRequest *http.Reques
}
//CheckPluginIsAvailable 判断插件是否可用
//CheckPluginIsAvailable 检测插件
func CheckPluginIsAvailable(httpResponse http.ResponseWriter, httpRequest *http.Request) {
_, e := controller.CheckLogin(httpResponse, httpRequest, controller.OperationPlugin, controller.OperationEDIT)
if e != nil {
......
package script
import (
"net/http"
"github.com/eolinker/goku-api-gateway/console/controller"
"github.com/eolinker/goku-api-gateway/console/module/script"
)
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"}
//RefreshAPIInfo 新建项目
func RefreshAPIInfo(httpResponse http.ResponseWriter, httpRequest *http.Request) {
hashCode := httpRequest.PostFormValue("hashCode")
if hashCode != "cf70df9de35d556cb5eea88e422ec6cb" {
controller.WriteError(httpResponse, "800000", "script", "[Error] Illegal hashCode", nil)
return
}
if !script.RefreshAPIInfo() {
controller.WriteError(httpResponse, "800000", "script", "[Error] Fail to refresh!", nil)
}
controller.WriteResultInfo(httpResponse, "script", "", nil)
}
//RefreshGatewayAlertConfig 刷新网关告警信息
func RefreshGatewayAlertConfig(httpResponse http.ResponseWriter, httpRequest *http.Request) {
hashCode := httpRequest.PostFormValue("hashCode")
if hashCode != "cf70df9de35d556cb5eea88e422ec6cb" {
controller.WriteError(httpResponse, "800000", "script", "[Error] Illegal hashCode", nil)
} else {
if !script.RefreshGatewayAlertConfig() {
controller.WriteError(httpResponse, "800000", "script", "[Error] Fail to refresh!", nil)
}
}
controller.WriteResultInfo(httpResponse, "script", "", nil)
}
//UpdateTables 更新表
func UpdateTables() {
script.UpdateTables(initTables)
}
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册