调整
This commit is contained in:
parent
11482111db
commit
75100ea988
@ -76,9 +76,12 @@ func (bpa *WorkerToolApi) AddGameApi(c *gin.Context) {
|
|||||||
nowDaySeconds := int32(f5.GetApp().GetRealSeconds())
|
nowDaySeconds := int32(f5.GetApp().GetRealSeconds())
|
||||||
|
|
||||||
var count int64 = 0
|
var count int64 = 0
|
||||||
db := f5.GetApp().GetOrmDb(constant.CONF_DB).Table(info.TableName()).Where("gameapi_host = ?", req.Host).Where("gameapi_port = ?", req.Port)
|
db := f5.GetApp().GetOrmDb(constant.CONF_DB).Table(info.TableName()).Where("gameapi_host = ?", req.Host)
|
||||||
if err := db.Count(&count).Error; err == nil && count > 0 {
|
if err := db.Count(&count).Error; err != nil {
|
||||||
f5.RspErr2(c, 1, "数据存在")
|
f5.RspErr2(c, 500, "sever internal error:"+err.Error())
|
||||||
|
return
|
||||||
|
} else if count > 0 {
|
||||||
|
f5.RspErr2(c, 2, "host(ip)已存在")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,6 +99,7 @@ func (bpa *WorkerToolApi) AddGameApi(c *gin.Context) {
|
|||||||
|
|
||||||
func (bpa *WorkerToolApi) EditGameApi(c *gin.Context) {
|
func (bpa *WorkerToolApi) EditGameApi(c *gin.Context) {
|
||||||
req := struct {
|
req := struct {
|
||||||
|
Idx int64 `binding:"required" json:"idx"`
|
||||||
Host string `binding:"required" json:"gameapi_host"`
|
Host string `binding:"required" json:"gameapi_host"`
|
||||||
Port int32 `binding:"required" json:"gameapi_port"`
|
Port int32 `binding:"required" json:"gameapi_port"`
|
||||||
Enable int32 `json:"enable"`
|
Enable int32 `json:"enable"`
|
||||||
@ -111,7 +115,7 @@ func (bpa *WorkerToolApi) EditGameApi(c *gin.Context) {
|
|||||||
|
|
||||||
item := new(system.GameApiHostItem)
|
item := new(system.GameApiHostItem)
|
||||||
db := f5.GetApp().GetOrmDb(constant.CONF_DB).Table(item.TableName())
|
db := f5.GetApp().GetOrmDb(constant.CONF_DB).Table(item.TableName())
|
||||||
if err := db.Take(item, "gameapi_host = ? AND gameapi_port = ?", req.Host, req.Port).Error; err != nil {
|
if err := db.Take(item, "idx = ?", req.Idx).Error; err != nil {
|
||||||
if !f5.IsOrmErrRecordNotFound(err) {
|
if !f5.IsOrmErrRecordNotFound(err) {
|
||||||
f5.RspErr2(c, 500, "sever internal error:"+err.Error())
|
f5.RspErr2(c, 500, "sever internal error:"+err.Error())
|
||||||
return
|
return
|
||||||
@ -121,11 +125,25 @@ func (bpa *WorkerToolApi) EditGameApi(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if item.Enable != req.Enable {
|
var count int64 = 0
|
||||||
|
db = f5.GetApp().GetOrmDb(constant.CONF_DB).Table(item.TableName()).Where("gameapi_host = ?", req.Host).Where("idx != ?", req.Idx)
|
||||||
|
if err := db.Count(&count).Error; err != nil {
|
||||||
|
f5.RspErr2(c, 500, "sever internal error:"+err.Error())
|
||||||
|
return
|
||||||
|
} else if count > 0 {
|
||||||
|
f5.RspErr2(c, 2, "host(ip)已存在")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if item.Host != req.Host ||
|
||||||
|
item.Port != req.Port ||
|
||||||
|
item.Enable != req.Enable {
|
||||||
nowDaySeconds := int32(f5.GetApp().GetRealSeconds())
|
nowDaySeconds := int32(f5.GetApp().GetRealSeconds())
|
||||||
|
item.Host = req.Host
|
||||||
|
item.Port = req.Port
|
||||||
item.Enable = req.Enable
|
item.Enable = req.Enable
|
||||||
item.ModifyTime = nowDaySeconds
|
item.ModifyTime = nowDaySeconds
|
||||||
if err := db.Where("gameapi_host = ?", req.Host).Where("gameapi_port = ?", req.Port).Save(item).Error; err != nil {
|
if err := f5.GetApp().GetOrmDb(constant.CONF_DB).Table(item.TableName()).Where("idx = ?", req.Idx).Omit("idx", "createtime").Save(item).Error; err != nil {
|
||||||
f5.RspErr2(c, 500, "sever internal error:"+err.Error())
|
f5.RspErr2(c, 500, "sever internal error:"+err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -193,9 +211,12 @@ func (bpa *WorkerToolApi) AddApiGate(c *gin.Context) {
|
|||||||
nowDaySeconds := int32(f5.GetApp().GetRealSeconds())
|
nowDaySeconds := int32(f5.GetApp().GetRealSeconds())
|
||||||
|
|
||||||
var count int64 = 0
|
var count int64 = 0
|
||||||
db := f5.GetApp().GetOrmDb(constant.CONF_DB).Table(info.TableName()).Where("apigate_host = ?", req.Host).Where("apigate_port = ?", req.Port)
|
db := f5.GetApp().GetOrmDb(constant.CONF_DB).Table(info.TableName()).Where("apigate_host = ?", req.Host)
|
||||||
if err := db.Count(&count).Error; err == nil && count > 0 {
|
if err := db.Count(&count).Error; err != nil {
|
||||||
f5.RspErr2(c, 1, "数据存在")
|
f5.RspErr2(c, 500, "sever internal error:"+err.Error())
|
||||||
|
return
|
||||||
|
} else if count > 0 {
|
||||||
|
f5.RspErr2(c, 2, "host(ip)已存在")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -213,6 +234,7 @@ func (bpa *WorkerToolApi) AddApiGate(c *gin.Context) {
|
|||||||
|
|
||||||
func (bpa *WorkerToolApi) EditApiGate(c *gin.Context) {
|
func (bpa *WorkerToolApi) EditApiGate(c *gin.Context) {
|
||||||
req := struct {
|
req := struct {
|
||||||
|
Idx int64 `binding:"required" json:"idx"`
|
||||||
Host string `binding:"required" json:"apigate_host"`
|
Host string `binding:"required" json:"apigate_host"`
|
||||||
Port int32 `binding:"required" json:"apigate_port"`
|
Port int32 `binding:"required" json:"apigate_port"`
|
||||||
Enable int32 `json:"enable"`
|
Enable int32 `json:"enable"`
|
||||||
@ -228,7 +250,7 @@ func (bpa *WorkerToolApi) EditApiGate(c *gin.Context) {
|
|||||||
|
|
||||||
item := new(system.ApiGateHostItem)
|
item := new(system.ApiGateHostItem)
|
||||||
db := f5.GetApp().GetOrmDb(constant.CONF_DB).Table(item.TableName())
|
db := f5.GetApp().GetOrmDb(constant.CONF_DB).Table(item.TableName())
|
||||||
if err := db.Take(item, "apigate_host = ? AND apigate_port = ?", req.Host, req.Port).Error; err != nil {
|
if err := db.Take(item, "idx = ?", req.Idx).Error; err != nil {
|
||||||
if !f5.IsOrmErrRecordNotFound(err) {
|
if !f5.IsOrmErrRecordNotFound(err) {
|
||||||
f5.RspErr2(c, 500, "sever internal error:"+err.Error())
|
f5.RspErr2(c, 500, "sever internal error:"+err.Error())
|
||||||
return
|
return
|
||||||
@ -238,11 +260,25 @@ func (bpa *WorkerToolApi) EditApiGate(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if item.Enable != req.Enable {
|
var count int64 = 0
|
||||||
|
db = f5.GetApp().GetOrmDb(constant.CONF_DB).Table(item.TableName()).Where("apigate_host = ?", req.Host).Where("idx != ?", req.Idx)
|
||||||
|
if err := db.Count(&count).Error; err != nil {
|
||||||
|
f5.RspErr2(c, 500, "sever internal error:"+err.Error())
|
||||||
|
return
|
||||||
|
} else if count > 0 {
|
||||||
|
f5.RspErr2(c, 2, "host(ip)已存在")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if item.Host != req.Host ||
|
||||||
|
item.Port != req.Port ||
|
||||||
|
item.Enable != req.Enable {
|
||||||
nowDaySeconds := int32(f5.GetApp().GetRealSeconds())
|
nowDaySeconds := int32(f5.GetApp().GetRealSeconds())
|
||||||
|
item.Host = req.Host
|
||||||
|
item.Port = req.Port
|
||||||
item.Enable = req.Enable
|
item.Enable = req.Enable
|
||||||
item.ModifyTime = nowDaySeconds
|
item.ModifyTime = nowDaySeconds
|
||||||
if err := db.Where("apigate_host = ?", req.Host).Where("apigate_port = ?", req.Port).Save(item).Error; err != nil {
|
if err := f5.GetApp().GetOrmDb(constant.CONF_DB).Table(item.TableName()).Where("idx = ?", req.Idx).Omit("idx", "createtime").Save(item).Error; err != nil {
|
||||||
f5.RspErr2(c, 500, "sever internal error:"+err.Error())
|
f5.RspErr2(c, 500, "sever internal error:"+err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -254,10 +290,10 @@ func (bpa *WorkerToolApi) testHostport(c *gin.Context, host string, port int32)
|
|||||||
addrAndPort := fmt.Sprintf("%s:%d", host, port)
|
addrAndPort := fmt.Sprintf("%s:%d", host, port)
|
||||||
conn, err := net.DialTimeout("tcp", addrAndPort, time.Second)
|
conn, err := net.DialTimeout("tcp", addrAndPort, time.Second)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
f5.RspErr2(c, 2, "host port 连不上")
|
f5.RspErr2(c, 2, "host(ip) port 连不上")
|
||||||
return false
|
return false
|
||||||
} else {
|
} else {
|
||||||
conn.Close()
|
conn.Close()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package system
|
package system
|
||||||
|
|
||||||
type GameApiHostItem struct {
|
type GameApiHostItem struct {
|
||||||
|
Idx int64 `gorm:"column:idx" json:"idx"`
|
||||||
Host string `gorm:"column:gameapi_host" json:"gameapi_host"`
|
Host string `gorm:"column:gameapi_host" json:"gameapi_host"`
|
||||||
Port int32 `gorm:"column:gameapi_port" json:"gameapi_port"`
|
Port int32 `gorm:"column:gameapi_port" json:"gameapi_port"`
|
||||||
Enable int32 `gorm:"column:enable" json:"enable"`
|
Enable int32 `gorm:"column:enable" json:"enable"`
|
||||||
@ -13,6 +14,7 @@ func (GameApiHostItem) TableName() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ApiGateHostItem struct {
|
type ApiGateHostItem struct {
|
||||||
|
Idx int64 `gorm:"column:idx" json:"idx"`
|
||||||
Host string `gorm:"column:apigate_host" json:"apigate_host"`
|
Host string `gorm:"column:apigate_host" json:"apigate_host"`
|
||||||
Port int32 `gorm:"column:apigate_port" json:"apigate_port"`
|
Port int32 `gorm:"column:apigate_port" json:"apigate_port"`
|
||||||
Enable int32 `gorm:"column:enable" json:"enable"`
|
Enable int32 `gorm:"column:enable" json:"enable"`
|
||||||
|
Loading…
x
Reference in New Issue
Block a user