context.go 886 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package context
  2. import (
  3. ctx "context"
  4. "time"
  5. )
  6. // Context web context interface
  7. type Context interface {
  8. ctx.Context
  9. // Now get current time.
  10. Now() time.Time
  11. // Seq implement Context method Seq.
  12. Seq() uint64
  13. // ServiceMethod implement Context method ServiceMethod.
  14. ServiceMethod() string
  15. // User get caller user.
  16. User() string
  17. }
  18. type rpcCtx struct {
  19. ctx.Context
  20. now time.Time
  21. seq uint64
  22. serviceMethod string
  23. user string
  24. }
  25. // NewContext new a rpc context.
  26. func NewContext(c ctx.Context, m, u string, s uint64) Context {
  27. rc := &rpcCtx{Context: c, now: time.Now(), seq: s, serviceMethod: m, user: u}
  28. return rc
  29. }
  30. func (c *rpcCtx) Seq() uint64 {
  31. return c.seq
  32. }
  33. func (c *rpcCtx) ServiceMethod() string {
  34. return c.serviceMethod
  35. }
  36. func (c *rpcCtx) Now() time.Time {
  37. return c.now
  38. }
  39. func (c *rpcCtx) User() string {
  40. return c.user
  41. }