utils.go 449 B

123456789101112131415161718192021222324252627
  1. package tool
  2. import (
  3. "github.com/cnlh/nps/lib/common"
  4. "github.com/cnlh/nps/vender/github.com/astaxie/beego"
  5. )
  6. var ports []int
  7. func init() {
  8. p := beego.AppConfig.String("allowPorts")
  9. ports = common.GetPorts(p)
  10. }
  11. func TestServerPort(p int, m string) (b bool) {
  12. if len(ports) != 0 {
  13. if !common.InIntArr(ports, p) {
  14. return false
  15. }
  16. }
  17. if m == "udpServer" {
  18. b = common.TestUdpPort(p)
  19. } else {
  20. b = common.TestTcpPort(p)
  21. }
  22. return
  23. }