option.go 929 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package liverpc
  2. import (
  3. "time"
  4. )
  5. // CallOption ...
  6. type CallOption interface {
  7. before(*callInfo)
  8. after(*callInfo)
  9. }
  10. type callInfo struct {
  11. Header *Header
  12. HTTP *HTTP
  13. DialTimeout time.Duration
  14. Timeout time.Duration
  15. }
  16. // TimeoutOption is timeout for a specific call
  17. type TimeoutOption struct {
  18. DialTimeout time.Duration
  19. Timeout time.Duration
  20. }
  21. func (t TimeoutOption) before(info *callInfo) {
  22. info.DialTimeout = t.DialTimeout
  23. info.Timeout = t.Timeout
  24. }
  25. func (t TimeoutOption) after(*callInfo) {
  26. }
  27. // HeaderOption contains Header for liverpc
  28. type HeaderOption struct {
  29. Header *Header
  30. }
  31. func (h HeaderOption) before(info *callInfo) {
  32. info.Header = h.Header
  33. }
  34. func (h HeaderOption) after(*callInfo) {
  35. }
  36. // HTTPOption contains HTTP for liverpc
  37. type HTTPOption struct {
  38. HTTP *HTTP
  39. }
  40. func (h HTTPOption) before(info *callInfo) {
  41. info.HTTP = h.HTTP
  42. }
  43. func (h HTTPOption) after(*callInfo) {
  44. }