package utils import ( "time" "github.com/go-admin-team/go-admin-core/sdk/config" ) func MetricTableName(prefix string, startTime, endTime int64) (string, time.Time, time.Time) { diff := endTime - startTime suffix := "_15s" start, end := time.Unix(startTime, 0), time.Unix(endTime, 0) if diff == 300 { suffix = "_5m" start = time.Unix(startTime, 0).Truncate(5 * time.Minute) end = start.Add(time.Duration(diff) * time.Second) } else if diff == 1200 { suffix = "_20m" start = time.Unix(startTime, 0).Truncate(20 * time.Minute) end = start.Add(time.Duration(diff) * time.Second) } else if diff >= 3600 { suffix = "_1h" start = time.Unix(startTime, 0).Truncate(time.Hour) end = start.Add(time.Duration(diff) * time.Second) } if config.ApplicationConfig.Mode == "dev" { // 由于当前只有_15s的有数据 suffix = "_15s" start, end = time.Unix(startTime, 0), time.Unix(endTime, 0) } return prefix + suffix, start, end }