1
This commit is contained in:
parent
a91b23c0b1
commit
a82677e4df
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"gamesapi_url": "https://game2006sapi-test.kingsome.cn",
|
"gamesapi_url": "https://game2006sapi-test.kingsome.cn",
|
||||||
"redirect_url": "https://game2006api-test.kingsome.cn",
|
"redirect_url": "https://game2006api-test.kingsome.cn",
|
||||||
"max_request_cache": 10,
|
"max_concurrent_num": 10,
|
||||||
"request_over_time": 30
|
"request_over_time": 30
|
||||||
}
|
}
|
||||||
|
@ -32,10 +32,11 @@ func RegModule(idx int32, m q5.Module) {
|
|||||||
{
|
{
|
||||||
app = m.(common.App)
|
app = m.(common.App)
|
||||||
}
|
}
|
||||||
case constant.ROUTER_MODULE_IDX:
|
case constant.SERVICE_MGR_MODULE_IDX:
|
||||||
{
|
{
|
||||||
serviceMgr = m.(common.ServiceMgr)
|
serviceMgr = m.(common.ServiceMgr)
|
||||||
}
|
}
|
||||||
|
case constant.ROUTER_MODULE_IDX:
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
panic("unknow module")
|
panic("unknow module")
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
_ "main/controller"
|
_ "main/controller"
|
||||||
. "main/global"
|
. "main/global"
|
||||||
_ "main/router"
|
_ "main/router"
|
||||||
|
_ "main/service"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Init() {
|
func Init() {
|
||||||
|
@ -48,12 +48,14 @@ func CaForward(c *gin.Context) {
|
|||||||
var createErr error
|
var createErr error
|
||||||
switch strings.ToUpper(c.Request.Method) {
|
switch strings.ToUpper(c.Request.Method) {
|
||||||
case "GET": {
|
case "GET": {
|
||||||
|
service.SApiForward.IncGetTimes()
|
||||||
httpRequest, createErr = http.NewRequest("GET", newUrl, nil)
|
httpRequest, createErr = http.NewRequest("GET", newUrl, nil)
|
||||||
if !f5.IsOnlineEnv() {
|
if !f5.IsOnlineEnv() {
|
||||||
f5.GetSysLog().Info("CaForward method:%s newUrl:%s ", c.Request.Method, newUrl)
|
f5.GetSysLog().Info("CaForward method:%s newUrl:%s ", c.Request.Method, newUrl)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case "POST": {
|
case "POST": {
|
||||||
|
service.SApiForward.IncPostTimes()
|
||||||
if postData, err := c.GetRawData(); err == nil {
|
if postData, err := c.GetRawData(); err == nil {
|
||||||
httpRequest, createErr = http.NewRequest("POST", newUrl, bytes.NewBuffer(postData))
|
httpRequest, createErr = http.NewRequest("POST", newUrl, bytes.NewBuffer(postData))
|
||||||
contentType := c.GetHeader("Content-Type")
|
contentType := c.GetHeader("Content-Type")
|
||||||
@ -76,6 +78,7 @@ func CaForward(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if createErr != nil {
|
if createErr != nil {
|
||||||
|
service.SApiForward.IncCreateErrTimes()
|
||||||
f5.RspErr(c, 500, "create request error")
|
f5.RspErr(c, 500, "create request error")
|
||||||
c.Abort()
|
c.Abort()
|
||||||
f5.GetSysLog().Info("CaForward create request url:%s error:%s", newUrl, createErr)
|
f5.GetSysLog().Info("CaForward create request url:%s error:%s", newUrl, createErr)
|
||||||
@ -85,16 +88,19 @@ func CaForward(c *gin.Context) {
|
|||||||
if resp, err := client.Do(httpRequest); err == nil {
|
if resp, err := client.Do(httpRequest); err == nil {
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
if bytes, err := ioutil.ReadAll(resp.Body); err == nil {
|
if bytes, err := ioutil.ReadAll(resp.Body); err == nil {
|
||||||
|
service.SApiForward.IncOkTimes()
|
||||||
c.String(200, string(bytes))
|
c.String(200, string(bytes))
|
||||||
c.Abort()
|
c.Abort()
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
|
service.SApiForward.IncReadRspErrTimes()
|
||||||
f5.RspErr(c, 500, "read response error")
|
f5.RspErr(c, 500, "read response error")
|
||||||
c.Abort()
|
c.Abort()
|
||||||
f5.GetSysLog().Info("CaForward read response url:%s eror:%s", newUrl, err)
|
f5.GetSysLog().Info("CaForward read response url:%s eror:%s", newUrl, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
service.SApiForward.IncDoErrTimes()
|
||||||
f5.RspErr(c, 500, "client.Do error")
|
f5.RspErr(c, 500, "client.Do error")
|
||||||
c.Abort()
|
c.Abort()
|
||||||
f5.GetSysLog().Info("CaForward client.Do url:%s error:%s", newUrl, err)
|
f5.GetSysLog().Info("CaForward client.Do url:%s error:%s", newUrl, err)
|
||||||
|
@ -13,7 +13,7 @@ type routerMgr struct {
|
|||||||
|
|
||||||
func (this *routerMgr) Init() {
|
func (this *routerMgr) Init() {
|
||||||
redirectGroup := f5.GetApp().GetGinEngine().Group("/sapi")
|
redirectGroup := f5.GetApp().GetGinEngine().Group("/sapi")
|
||||||
redirectGroup.Any("webapp/index.php?", middleware.CaForward)
|
redirectGroup.Any("webapp/index.php", middleware.CaForward)
|
||||||
|
|
||||||
f5.GetSysLog().Info("routerMgr.init")
|
f5.GetSysLog().Info("routerMgr.init")
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,7 @@ func (this *sApiForward) AcquireLock(accountId string) *SApiForwardLock {
|
|||||||
c := this.userCache[int64(crc32) % int64(len(this.userCache))]
|
c := this.userCache[int64(crc32) % int64(len(this.userCache))]
|
||||||
u := this.getOrCreate(c, accountId)
|
u := this.getOrCreate(c, accountId)
|
||||||
if atomic.AddInt32(&u.lockTimes, 1) > mt.Table.Config.GetMaxConcurrentNum() {
|
if atomic.AddInt32(&u.lockTimes, 1) > mt.Table.Config.GetMaxConcurrentNum() {
|
||||||
|
atomic.AddInt32(&u.lockTimes, -1)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
u.lock.Lock()
|
u.lock.Lock()
|
||||||
@ -75,6 +76,10 @@ func (this *sApiForward) IncDoErrTimes() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *sApiForward) IncOkTimes() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func (this *sApiForward) IncReadRspErrTimes() {
|
func (this *sApiForward) IncReadRspErrTimes() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user