session.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package http
  2. import (
  3. "net/http"
  4. "rocommon"
  5. )
  6. type ResponseProc interface {
  7. WriteRespond(*httpSession) error
  8. }
  9. type RequestProc interface {
  10. Match(method, url string) bool
  11. }
  12. type httpSession struct {
  13. err error
  14. respond bool
  15. node rocommon.ServerNode
  16. req *http.Request
  17. resp http.ResponseWriter
  18. }
  19. func newHttpSession(node rocommon.ServerNode, req *http.Request, res http.ResponseWriter) *httpSession {
  20. sess := &httpSession{
  21. node: node,
  22. req: req,
  23. resp: res,
  24. }
  25. return sess
  26. }
  27. func (this *httpSession) Node() rocommon.ServerNode {
  28. return this.node
  29. }
  30. func (this *httpSession) Raw() interface{} {
  31. return nil
  32. }
  33. func (this *httpSession) ID() uint64 {
  34. return 0
  35. }
  36. func (this *httpSession) GetAES() *[]byte {
  37. return nil
  38. }
  39. func (this *httpSession) SetAES(aes string) {
  40. }
  41. func (this *httpSession) GetHandCode() string {
  42. return ""
  43. }
  44. func (this *httpSession) IncRecvPingNum(incNum int) {
  45. }
  46. func (this *httpSession) RecvPingNum() int {
  47. return 0
  48. }
  49. func (this *httpSession) SetHandCode(code string) {
  50. }
  51. func (this *httpSession) GetSessionOpt() interface{} {
  52. return nil
  53. }
  54. func (this *httpSession) GetSessionOptFlag() bool {
  55. return true
  56. }
  57. func (this *httpSession) SetSessionOptFlag(flag bool) {
  58. }
  59. func (this *httpSession) Close() {
  60. }
  61. func (this *httpSession) Match(method, url string) bool {
  62. return this.req.Method == method && this.req.URL.Path == url
  63. }
  64. func (this *httpSession) Request() *http.Request {
  65. return this.req
  66. }
  67. func (this *httpSession) Response() http.ResponseWriter {
  68. return this.resp
  69. }
  70. func (this *httpSession) Send(msg interface{}) {
  71. if proc, ok := msg.(ResponseProc); ok {
  72. this.err = proc.WriteRespond(this)
  73. this.respond = true
  74. } else {
  75. this.err = ErrUnknownOperation
  76. }
  77. }
  78. func (this *httpSession) HeartBeat(msg interface{}) {}