main.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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", "dup端口")
  23. flag.StringVar(&port, "port", "", "dup端口")
  24. flag.StringVar(&stype, "stype", "", "stype")
  25. flag.Parse()
  26. log.Println(startDate, endDate, ip, port)
  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. log.Println(sid, eid)
  32. udpclient = mu.UdpClient{Local: ":1470", BufSize: 1024}
  33. udpclient.Listen(processUdpMsg)
  34. by, _ := json.Marshal(map[string]interface{}{
  35. "gtid": sid,
  36. "lteid": eid,
  37. "stype": stype,
  38. })
  39. udpclient.WriteUdp(by, mu.OP_TYPE_DATA, &net.UDPAddr{
  40. IP: net.ParseIP(ip),
  41. Port: qu.IntAll(port),
  42. })
  43. b := make(chan bool, 1)
  44. <-b
  45. }
  46. func processUdpMsg(act byte, data []byte, ra *net.UDPAddr) {
  47. switch act {
  48. case mu.OP_TYPE_DATA:
  49. var mapInfo map[string]interface{}
  50. err := json.Unmarshal(data, &mapInfo)
  51. if err != nil {
  52. log.Println(err)
  53. } else {
  54. log.Println(mapInfo)
  55. }
  56. case mu.OP_NOOP: //下个节点回应
  57. log.Println("发送成功", string(data))
  58. }
  59. }