orig.diff 825 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. 1a2,3
  2. > //
  3. > // based on https://github.com/shurcooL/play/tree/master/42
  4. 19c21,38
  5. < type Arith struct{}
  6. ---
  7. > type Arith struct {
  8. > req *http.Request
  9. > connClose func() error
  10. > callCounter int
  11. > }
  12. >
  13. > func (a *Arith) Multiply(args *Args, reply *int) error {
  14. > fmt.Println(a.callCounter, "from", a.req.RemoteAddr)
  15. > c, err := a.req.Cookie("JSESSIONID")
  16. > if err != nil {
  17. > return err
  18. > }
  19. > fmt.Println("cookie:", c)
  20. >
  21. > if a.callCounter > 5 {
  22. > return a.connClose()
  23. > }
  24. > a.callCounter++
  25. 21d39
  26. < func (_ *Arith) Multiply(args *Args, reply *int) error {
  27. 28d45
  28. < rpc.Register(&Arith{})
  29. 30c47,53
  30. < jsonrpc.ServeConn(conn)
  31. ---
  32. > s := rpc.NewServer()
  33. > a := &Arith{
  34. > req: conn.Request(),
  35. > connClose: conn.Close,
  36. > }
  37. > s.Register(a)
  38. > s.ServeCodec(jsonrpc.NewServerCodec(conn))