main.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package main
  2. import (
  3. "bufio"
  4. "net"
  5. "net/http"
  6. "devel.mephi.ru/dyokunev/xml2jsond/stream"
  7. xj "github.com/basgys/goxml2json"
  8. )
  9. func main() {
  10. http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
  11. json, err := xj.Convert(req.Body)
  12. if err != nil {
  13. return
  14. }
  15. w.Write([]byte(json.String()))
  16. })
  17. go func() {http.ListenAndServe(":60080", nil)}()
  18. go func() {
  19. ln, err := net.Listen("tcp", ":60081")
  20. if err != nil {
  21. panic(err)
  22. }
  23. for {
  24. conn, err := ln.Accept()
  25. if err != nil {
  26. panic(err)
  27. }
  28. go func(conn net.Conn) {
  29. defer func() {conn.Close()} ()
  30. connReader := bufio.NewReader(conn)
  31. json, err := xj.Convert(connReader)
  32. if err != nil {
  33. return
  34. }
  35. conn.Write([]byte(json.String()))
  36. }(conn)
  37. }
  38. }()
  39. {
  40. ln, err := net.Listen("tcp", ":60082")
  41. if err != nil {
  42. panic(err)
  43. }
  44. for {
  45. conn, err := ln.Accept()
  46. if err != nil {
  47. panic(err)
  48. }
  49. go func(conn net.Conn) {
  50. defer func() {conn.Close()} ()
  51. stream.Run(conn, conn)
  52. }(conn)
  53. }
  54. }
  55. }