main.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package main
  2. import (
  3. "encoding/json"
  4. "flag"
  5. "log"
  6. mu "mfw/util"
  7. "net"
  8. qu "qfw/util"
  9. "time"
  10. "gopkg.in/mgo.v2/bson"
  11. )
  12. var udpclient mu.UdpClient //udp对象
  13. var nextNodes []map[string]interface{}
  14. var startDate, endDate, ip, port, stype string
  15. func main() {
  16. //2015-11-03,2017-04-01
  17. //2017-04-01,2017-06-01
  18. //2017-06-01,2018-06-01
  19. //2018-06-01,2019-02-20
  20. flag.StringVar(&startDate, "start", "", "开始日期2006-01-02")
  21. flag.StringVar(&endDate, "end", "", "结束日期2006-01-02")
  22. flag.StringVar(&ip, "ip", "127.0.0.1", "ip")
  23. flag.StringVar(&port, "port", "", "dup端口")
  24. flag.StringVar(&stype, "stype", "", "stype")
  25. flag.Parse()
  26. log.Println(startDate, endDate, ip, port, stype)
  27. start, _ := time.ParseInLocation(qu.Date_Short_Layout, startDate, time.Local)
  28. end, _ := time.ParseInLocation(qu.Date_Short_Layout, endDate, time.Local)
  29. sid := bson.NewObjectIdWithTime(start)
  30. eid := bson.NewObjectIdWithTime(end)
  31. udpclient = mu.UdpClient{Local: ":1470", BufSize: 1024}
  32. udpclient.Listen(processUdpMsg)
  33. by, _ := json.Marshal(map[string]interface{}{
  34. "gtid": sid,
  35. "lteid": eid,
  36. "stype": stype,
  37. })
  38. udpclient.WriteUdp(by, mu.OP_TYPE_DATA, &net.UDPAddr{
  39. IP: net.ParseIP(ip),
  40. Port: qu.IntAll(port),
  41. })
  42. b := make(chan bool, 1)
  43. <-b
  44. }
  45. func processUdpMsg(act byte, data []byte, ra *net.UDPAddr) {
  46. switch act {
  47. case mu.OP_TYPE_DATA:
  48. var mapInfo map[string]interface{}
  49. err := json.Unmarshal(data, &mapInfo)
  50. if err != nil {
  51. log.Println(err)
  52. } else {
  53. log.Println(mapInfo)
  54. }
  55. case mu.OP_NOOP: //下个节点回应
  56. log.Println("发送成功", string(data))
  57. }
  58. }