request.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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) Fields() rest.FieldList {
  37. return rest.FieldListFromSlice(s.RData().Slice("Fields", nil))
  38. }
  39. func (s *RequestIn) OutSuccess(data json.Map, files rest.RequestFiles) rest.IRequestOut {
  40. return &rest.RequestStream{
  41. ID: s.ID,
  42. Request: &rest.Request{
  43. Type: rest.RequestTypeOut,
  44. Command: s.Command,
  45. Data: data,
  46. Files: files,
  47. },
  48. }
  49. }
  50. func (s *RequestIn) OutError(err rest.IErrorArgs) rest.IRequestOut {
  51. return &rest.RequestStream{
  52. ID: s.ID,
  53. Request: &rest.Request{
  54. Type: rest.RequestTypeOut,
  55. Command: s.Command,
  56. Data: err.Map(),
  57. },
  58. }
  59. }