Skip to content

Commit

Permalink
防止rabbitmq连接不通时,用户任然能下单
Browse files Browse the repository at this point in the history
  • Loading branch information
oldfritter committed Sep 8, 2019
1 parent be6149f commit a28ca8f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions config/interfaces.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,14 @@
method: POST
reloading_matching_check: true
market_can_trade: true
is_rabbitmq_connected: true
- path: /api/:platform/v1/orders/multi2
method: POST
auth: true
sign: true
reloading_matching_check: true
market_can_trade: true
is_rabbitmq_connected: true
- path: /api/:platform/v1/order/delete
auth: true
sign: true
Expand Down
4 changes: 4 additions & 0 deletions initializers/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type ApiInterface struct {
CheckTimestamp bool `yaml:"check_timestamp"`
LimitTrafficWithIp bool `yaml:"limit_traffic_with_ip"`
LimitTrafficWithEmail bool `yaml:"limit_traffic_with_email"`
IsRabbitMqConnected bool `yaml:"is_rabbitmq_connected"`
}

var GlobalApiInterfaces []ApiInterface
Expand Down Expand Up @@ -79,6 +80,9 @@ func Auth(next echo.HandlerFunc) echo.HandlerFunc {
if currentApiInterface.CheckTimestamp && checkTimestamp(context, &params) == false {
return utils.BuildError("3050")
}
if currentApiInterface.IsRabbitMqConnected && !IsRabbitMqConnected() {
return utils.BuildError("2046")
}

db := utils.MainDbBegin()
defer db.DbRollback()
Expand Down
17 changes: 17 additions & 0 deletions initializers/rabbitmq.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package initializers

import (
"fmt"

"github.com/oldfritter/goDCE/utils"
)

func IsRabbitMqConnected() bool {
c := utils.RabbitMqConnect
ok := true
if c.IsClosed() {
fmt.Println("Connection state: closed")
ok = false
}
return ok
}

0 comments on commit a28ca8f

Please sign in to comment.