convert.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package systemlog
  2. import (
  3. udeModel "udeServer/internal/model"
  4. "udeServer/internal/types"
  5. )
  6. // ConvertToSystemLog maps the model row to the API response type.
  7. func ConvertToSystemLog(v *udeModel.TSystemLog) types.SystemLog {
  8. return types.SystemLog{
  9. Id: v.Id,
  10. Iden: v.Iden,
  11. TraceId: v.TraceId,
  12. SpanId: v.SpanId,
  13. ParentSpanId: v.ParentSpanId.String,
  14. Type: int(v.Type),
  15. ServiceName: v.ServiceName,
  16. UriPath: v.UriPath.String,
  17. HttpMethod: v.HttpMethod.String,
  18. Method: v.Method,
  19. Level: v.Level,
  20. AppKey: v.AppKey.String,
  21. UserId: v.UserId.String,
  22. UserName: v.UserName.String,
  23. ClientIp: v.ClientIp.String,
  24. RequestHeader: v.RequestHeader.String,
  25. RequestBodyDigest: v.RequestBodyDigest,
  26. RequestBodyFileKey: v.RequestBodyFileKey,
  27. ResponseCode: v.ResponseCode,
  28. ResponseBodyDigest: v.ResponseBodyDigest,
  29. ResponseBodyFileKey: v.ResponseBodyFileKey,
  30. ErrorMsg: v.ErrorMessage.String,
  31. DurationMs: v.DurationMs,
  32. CreatedAt: v.CreatedAt.Format("2006-01-02 15:04:05"),
  33. Hmac: v.HMac,
  34. AuditStatus: int(v.AuditStatus),
  35. }
  36. }
  37. // ConvertToLogArchive maps the model row to the API response type.
  38. func ConvertToLogArchive(v *udeModel.TLogArchiveRecord) types.LogArchive {
  39. return types.LogArchive{
  40. Id: v.Id,
  41. ArchiveName: v.ArchiveName,
  42. RecordCount: v.RecordCount,
  43. ArchiveFileKey: v.ArchiveFileKey,
  44. ArchiveMode: int(v.ArchiveMode),
  45. BatchSize: int(v.BatchSize),
  46. ArchivedBy: v.ArchivedBy,
  47. ArchivedAt: v.ArchivedAt.Format("2006-01-02 15:04:05"),
  48. }
  49. }
  50. // ConvertToLogRestore maps the model row to the API response type.
  51. func ConvertToLogRestore(v *udeModel.TLogRestoreRecord) types.LogRestore {
  52. return types.LogRestore{
  53. Id: v.Id,
  54. ArchiveId: v.ArchiveId,
  55. RestoreStatus: int(v.RestoreStatus),
  56. RestoreMessage: v.RestoreMessage.String,
  57. RestoredBy: v.RestoredBy,
  58. RestoredAt: v.RestoredAt.Format("2006-01-02 15:04:05"),
  59. }
  60. }
  61. // normalizePage clamps the paging parameters (default 1/10, max 100).
  62. func normalizePage(page, pageSize int64) (int64, int64) {
  63. if page < 1 {
  64. page = 1
  65. }
  66. if pageSize < 10 {
  67. pageSize = 10
  68. }
  69. if pageSize > 100 {
  70. pageSize = 100
  71. }
  72. return page, pageSize
  73. }