request.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package rest_websocket
  2. import (
  3. "git.ali33.ru/fcg-xvii/go-tools/json"
  4. "git.ali33.ru/fcg-xvii/rest"
  5. )
  6. type RequestIn struct {
  7. *rest.RequestStream
  8. owner *SocketServer
  9. core any
  10. }
  11. func (s *RequestIn) Auth() json.Map {
  12. return s.owner.auth
  13. }
  14. func (s *RequestIn) SetAuth(auth json.Map) {
  15. s.owner.auth = auth
  16. }
  17. func (s *RequestIn) GenerateToken(data json.Map, expire int64) (string, error) {
  18. return s.owner.appConf.tokenGenerator(data, expire)
  19. }
  20. func (s *RequestIn) ROwner() rest.IOwner {
  21. return s.owner
  22. }
  23. func (s *RequestIn) RCore() any {
  24. return s.core
  25. }
  26. func (s *RequestIn) ClientData(key string) (any, bool) {
  27. res, check := s.owner.clientData[key]
  28. return res, check
  29. }
  30. func (s *RequestIn) SetClientData(key string, data any) {
  31. s.owner.clientData[key] = data
  32. }
  33. func (s *RequestIn) OutSuccess(data json.Map, files rest.RequestFiles) rest.IRequestOut {
  34. return &rest.RequestStream{
  35. ID: s.ID,
  36. Request: &rest.Request{
  37. Type: rest.RequestTypeOut,
  38. Command: s.Command,
  39. Data: data,
  40. Files: files,
  41. },
  42. }
  43. }
  44. func (s *RequestIn) OutError(err rest.IErrorArgs) rest.IRequestOut {
  45. return &rest.RequestStream{
  46. ID: s.ID,
  47. Request: &rest.Request{
  48. Type: rest.RequestTypeOut,
  49. Command: s.Command,
  50. Data: err.Map(),
  51. },
  52. }
  53. }