ot_public_models.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package models
  2. import (
  3. "fmt"
  4. "strings"
  5. "time"
  6. )
  7. type TimeRange struct {
  8. StartTime int64 `uri:"start_time" form:"start_time" json:"start_time"`
  9. EndTime int64 `uri:"end_time" form:"end_time" json:"end_time"`
  10. }
  11. // 检查 StartTime 或 EndTime是否为0,如果为0, 将基填充默认值
  12. func (t *TimeRange) CheckFilling(d time.Duration) {
  13. if t.EndTime == 0 {
  14. t.EndTime = time.Now().Unix()
  15. }
  16. secs := int64(d.Seconds())
  17. if t.StartTime == 0 || t.StartTime > t.EndTime {
  18. t.StartTime = t.EndTime - secs
  19. }
  20. if t.StartTime == t.EndTime { // 当start == end时,取前后10分钟的数据,通常一个trace不会这么长时间,这是为了加速查询
  21. t.StartTime -= 600
  22. t.EndTime += 600
  23. }
  24. }
  25. type AppPercentileRange struct {
  26. Percentile float32 `uri:"percentile" form:"percentile" json:"percentile"`
  27. }
  28. type HourRange struct {
  29. HourNum int64 `uri:"hour_num" form:"hour_num" json:"hour_num"`
  30. }
  31. type AppIntervalRange struct {
  32. Interval int64 `uri:"interval" form:"interval" json:"interval"`
  33. }
  34. type DurationRange struct {
  35. MinDuration float64 `form:"min_duration" json:"min_duration"`
  36. MaxDuration float64 `form:"max_duration" json:"max_duration"`
  37. }
  38. type SortInfo struct {
  39. Field string `form:"sort_field" json:"sort_field"`
  40. Type string `form:"sort_type" json:"sort_type"`
  41. }
  42. func (s SortInfo) OrderBy(supports []string, field string, sort string) string {
  43. s.Type = strings.ToUpper(s.Type)
  44. if s.Type != "ASC" && s.Type != "DESC" {
  45. s.Type = sort
  46. }
  47. for _, support := range supports {
  48. if strings.EqualFold(support, s.Field) {
  49. return fmt.Sprintf("%s %s", support, s.Type)
  50. }
  51. }
  52. return fmt.Sprintf("%s %s", field, sort)
  53. }
  54. type WatchLive struct {
  55. Live bool `uri:"live" form:"live" json:"live"`
  56. }