package models import ( "fmt" "strings" "time" ) type TimeRange struct { StartTime int64 `uri:"start_time" form:"start_time" json:"start_time"` EndTime int64 `uri:"end_time" form:"end_time" json:"end_time"` } // 检查 StartTime 或 EndTime是否为0,如果为0, 将基填充默认值 func (t *TimeRange) CheckFilling(d time.Duration) { if t.EndTime == 0 { t.EndTime = time.Now().Unix() } secs := int64(d.Seconds()) if t.StartTime == 0 || t.StartTime > t.EndTime { t.StartTime = t.EndTime - secs } if t.StartTime == t.EndTime { // 当start == end时,取前后10分钟的数据,通常一个trace不会这么长时间,这是为了加速查询 t.StartTime -= 600 t.EndTime += 600 } } type AppPercentileRange struct { Percentile float32 `uri:"percentile" form:"percentile" json:"percentile"` } type HourRange struct { HourNum int64 `uri:"hour_num" form:"hour_num" json:"hour_num"` } type AppIntervalRange struct { Interval int64 `uri:"interval" form:"interval" json:"interval"` } type DurationRange struct { MinDuration float64 `form:"min_duration" json:"min_duration"` MaxDuration float64 `form:"max_duration" json:"max_duration"` } type SortInfo struct { Field string `form:"sort_field" json:"sort_field"` Type string `form:"sort_type" json:"sort_type"` } func (s SortInfo) OrderBy(supports []string, field string, sort string) string { s.Type = strings.ToUpper(s.Type) if s.Type != "ASC" && s.Type != "DESC" { s.Type = sort } for _, support := range supports { if strings.EqualFold(support, s.Field) { return fmt.Sprintf("%s %s", support, s.Type) } } return fmt.Sprintf("%s %s", field, sort) } type WatchLive struct { Live bool `uri:"live" form:"live" json:"live"` }