request.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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) ParseToken(tokenString string) (json.Map, error) {
  21. return s.owner.appConf.tokenParser(tokenString)
  22. }
  23. func (s *RequestIn) ROwner() rest.IOwner {
  24. return s.owner
  25. }
  26. func (s *RequestIn) RCore() any {
  27. return s.core
  28. }
  29. func (s *RequestIn) ClientData(key string) (any, bool) {
  30. res, check := s.owner.clientData[key]
  31. return res, check
  32. }
  33. func (s *RequestIn) SetClientData(key string, data any) {
  34. s.owner.clientData[key] = data
  35. }
  36. func (s *RequestIn) OutSuccess(data json.Map, files rest.RequestFiles) rest.IRequestOut {
  37. return &rest.RequestStream{
  38. ID: s.ID,
  39. Request: &rest.Request{
  40. Type: rest.RequestTypeOut,
  41. Command: s.Command,
  42. Data: data,
  43. Files: files,
  44. },
  45. }
  46. }
  47. func (s *RequestIn) OutError(err rest.IErrorArgs) rest.IRequestOut {
  48. return &rest.RequestStream{
  49. ID: s.ID,
  50. Request: &rest.Request{
  51. Type: rest.RequestTypeOut,
  52. Command: s.Command,
  53. Data: err.Map(),
  54. },
  55. }
  56. }