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