mirror of
https://github.com/grafana/grafana.git
synced 2025-08-02 12:43:50 +08:00
Use opportunities to unindent code (unindent)
This commit fixes the following unindent findings: pkg/api/common.go:102:2: "if x { if y" should be "if x && y" pkg/components/dynmap/dynmap.go:642:2: invert condition and early return pkg/components/dynmap/dynmap.go:681:2: invert condition and early return pkg/components/simplejson/simplejson.go:171:2: "if x { if y" should be "if x && y" pkg/middleware/dashboard_redirect.go:42:3: invert condition and early return pkg/tsdb/mssql/mssql.go:301:3: invert condition and early break pkg/tsdb/mysql/mysql.go:312:3: invert condition and early break pkg/tsdb/postgres/postgres.go:292:3: invert condition and early break pkg/tsdb/sql_engine.go:144:2: invert condition and early return
This commit is contained in:
@ -99,10 +99,8 @@ func Error(status int, message string, err error) *NormalResponse {
|
|||||||
data["message"] = message
|
data["message"] = message
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil && setting.Env != setting.PROD {
|
||||||
if setting.Env != setting.PROD {
|
data["error"] = err.Error()
|
||||||
data["error"] = err.Error()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resp := JSON(status, data)
|
resp := JSON(status, data)
|
||||||
|
@ -639,26 +639,24 @@ func (v *Value) Object() (*Object, error) {
|
|||||||
valid = true
|
valid = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !valid {
|
||||||
|
return nil, ErrNotObject
|
||||||
|
}
|
||||||
|
obj := new(Object)
|
||||||
|
obj.valid = valid
|
||||||
|
|
||||||
|
m := make(map[string]*Value)
|
||||||
|
|
||||||
if valid {
|
if valid {
|
||||||
obj := new(Object)
|
for key, element := range v.data.(map[string]interface{}) {
|
||||||
obj.valid = valid
|
m[key] = &Value{element, true}
|
||||||
|
|
||||||
m := make(map[string]*Value)
|
|
||||||
|
|
||||||
if valid {
|
|
||||||
for key, element := range v.data.(map[string]interface{}) {
|
|
||||||
m[key] = &Value{element, true}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
obj.data = v.data
|
|
||||||
obj.m = m
|
|
||||||
|
|
||||||
return obj, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, ErrNotObject
|
obj.data = v.data
|
||||||
|
obj.m = m
|
||||||
|
|
||||||
|
return obj, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attempts to typecast the current value into an object arrau.
|
// Attempts to typecast the current value into an object arrau.
|
||||||
@ -678,23 +676,19 @@ func (v *Value) ObjectArray() ([]*Object, error) {
|
|||||||
// Unsure if this is a good way to use slices, it's probably not
|
// Unsure if this is a good way to use slices, it's probably not
|
||||||
var slice []*Object
|
var slice []*Object
|
||||||
|
|
||||||
if valid {
|
if !valid {
|
||||||
|
return nil, ErrNotObjectArray
|
||||||
for _, element := range v.data.([]interface{}) {
|
|
||||||
childValue := Value{element, true}
|
|
||||||
childObject, err := childValue.Object()
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, ErrNotObjectArray
|
|
||||||
}
|
|
||||||
slice = append(slice, childObject)
|
|
||||||
}
|
|
||||||
|
|
||||||
return slice, nil
|
|
||||||
}
|
}
|
||||||
|
for _, element := range v.data.([]interface{}) {
|
||||||
|
childValue := Value{element, true}
|
||||||
|
childObject, err := childValue.Object()
|
||||||
|
|
||||||
return nil, ErrNotObjectArray
|
if err != nil {
|
||||||
|
return nil, ErrNotObjectArray
|
||||||
|
}
|
||||||
|
slice = append(slice, childObject)
|
||||||
|
}
|
||||||
|
return slice, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attempts to typecast the current value into a string.
|
// Attempts to typecast the current value into a string.
|
||||||
|
@ -168,10 +168,8 @@ func (j *Json) GetPath(branch ...string) *Json {
|
|||||||
// js.Get("top_level").Get("array").GetIndex(1).Get("key").Int()
|
// js.Get("top_level").Get("array").GetIndex(1).Get("key").Int()
|
||||||
func (j *Json) GetIndex(index int) *Json {
|
func (j *Json) GetIndex(index int) *Json {
|
||||||
a, err := j.Array()
|
a, err := j.Array()
|
||||||
if err == nil {
|
if err == nil && len(a) > index {
|
||||||
if len(a) > index {
|
return &Json{a[index]}
|
||||||
return &Json{a[index]}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return &Json{nil}
|
return &Json{nil}
|
||||||
}
|
}
|
||||||
|
@ -24,12 +24,12 @@ func RedirectFromLegacyDashboardURL() macaron.Handler {
|
|||||||
return func(c *m.ReqContext) {
|
return func(c *m.ReqContext) {
|
||||||
slug := c.Params("slug")
|
slug := c.Params("slug")
|
||||||
|
|
||||||
if slug != "" {
|
if slug == "" {
|
||||||
if url, err := getDashboardURLBySlug(c.OrgId, slug); err == nil {
|
return
|
||||||
url = fmt.Sprintf("%s?%s", url, c.Req.URL.RawQuery)
|
}
|
||||||
c.Redirect(url, 301)
|
if url, err := getDashboardURLBySlug(c.OrgId, slug); err == nil {
|
||||||
return
|
url = fmt.Sprintf("%s?%s", url, c.Req.URL.RawQuery)
|
||||||
}
|
c.Redirect(url, 301)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -39,17 +39,16 @@ func RedirectFromLegacyDashboardSoloURL() macaron.Handler {
|
|||||||
slug := c.Params("slug")
|
slug := c.Params("slug")
|
||||||
renderRequest := c.QueryBool("render")
|
renderRequest := c.QueryBool("render")
|
||||||
|
|
||||||
if slug != "" {
|
if slug == "" {
|
||||||
if url, err := getDashboardURLBySlug(c.OrgId, slug); err == nil {
|
return
|
||||||
if renderRequest && strings.Contains(url, setting.AppSubUrl) {
|
}
|
||||||
url = strings.Replace(url, setting.AppSubUrl, "", 1)
|
if url, err := getDashboardURLBySlug(c.OrgId, slug); err == nil {
|
||||||
}
|
if renderRequest && strings.Contains(url, setting.AppSubUrl) {
|
||||||
|
url = strings.Replace(url, setting.AppSubUrl, "", 1)
|
||||||
url = strings.Replace(url, "/d/", "/d-solo/", 1)
|
|
||||||
url = fmt.Sprintf("%s?%s", url, c.Req.URL.RawQuery)
|
|
||||||
c.Redirect(url, 301)
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
url = strings.Replace(url, "/d/", "/d-solo/", 1)
|
||||||
|
url = fmt.Sprintf("%s?%s", url, c.Req.URL.RawQuery)
|
||||||
|
c.Redirect(url, 301)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -298,18 +298,19 @@ func (e MssqlQueryEndpoint) transformToTimeSeries(query *tsdb.Query, rows *core.
|
|||||||
key := elem.Value.(string)
|
key := elem.Value.(string)
|
||||||
result.Series = append(result.Series, pointsBySeries[key])
|
result.Series = append(result.Series, pointsBySeries[key])
|
||||||
|
|
||||||
if fillMissing {
|
if !fillMissing {
|
||||||
series := pointsBySeries[key]
|
break
|
||||||
// fill in values from last fetched value till interval end
|
}
|
||||||
intervalStart := series.Points[len(series.Points)-1][1].Float64
|
series := pointsBySeries[key]
|
||||||
intervalEnd := float64(tsdbQuery.TimeRange.MustGetTo().UnixNano() / 1e6)
|
// fill in values from last fetched value till interval end
|
||||||
|
intervalStart := series.Points[len(series.Points)-1][1].Float64
|
||||||
|
intervalEnd := float64(tsdbQuery.TimeRange.MustGetTo().UnixNano() / 1e6)
|
||||||
|
|
||||||
// align interval start
|
// align interval start
|
||||||
intervalStart = math.Floor(intervalStart/fillInterval) * fillInterval
|
intervalStart = math.Floor(intervalStart/fillInterval) * fillInterval
|
||||||
for i := intervalStart + fillInterval; i < intervalEnd; i += fillInterval {
|
for i := intervalStart + fillInterval; i < intervalEnd; i += fillInterval {
|
||||||
series.Points = append(series.Points, tsdb.TimePoint{fillValue, null.FloatFrom(i)})
|
series.Points = append(series.Points, tsdb.TimePoint{fillValue, null.FloatFrom(i)})
|
||||||
rowCount++
|
rowCount++
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -309,18 +309,19 @@ func (e MysqlQueryEndpoint) transformToTimeSeries(query *tsdb.Query, rows *core.
|
|||||||
key := elem.Value.(string)
|
key := elem.Value.(string)
|
||||||
result.Series = append(result.Series, pointsBySeries[key])
|
result.Series = append(result.Series, pointsBySeries[key])
|
||||||
|
|
||||||
if fillMissing {
|
if !fillMissing {
|
||||||
series := pointsBySeries[key]
|
break
|
||||||
// fill in values from last fetched value till interval end
|
}
|
||||||
intervalStart := series.Points[len(series.Points)-1][1].Float64
|
series := pointsBySeries[key]
|
||||||
intervalEnd := float64(tsdbQuery.TimeRange.MustGetTo().UnixNano() / 1e6)
|
// fill in values from last fetched value till interval end
|
||||||
|
intervalStart := series.Points[len(series.Points)-1][1].Float64
|
||||||
|
intervalEnd := float64(tsdbQuery.TimeRange.MustGetTo().UnixNano() / 1e6)
|
||||||
|
|
||||||
// align interval start
|
// align interval start
|
||||||
intervalStart = math.Floor(intervalStart/fillInterval) * fillInterval
|
intervalStart = math.Floor(intervalStart/fillInterval) * fillInterval
|
||||||
for i := intervalStart + fillInterval; i < intervalEnd; i += fillInterval {
|
for i := intervalStart + fillInterval; i < intervalEnd; i += fillInterval {
|
||||||
series.Points = append(series.Points, tsdb.TimePoint{fillValue, null.FloatFrom(i)})
|
series.Points = append(series.Points, tsdb.TimePoint{fillValue, null.FloatFrom(i)})
|
||||||
rowCount++
|
rowCount++
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -289,18 +289,19 @@ func (e PostgresQueryEndpoint) transformToTimeSeries(query *tsdb.Query, rows *co
|
|||||||
key := elem.Value.(string)
|
key := elem.Value.(string)
|
||||||
result.Series = append(result.Series, pointsBySeries[key])
|
result.Series = append(result.Series, pointsBySeries[key])
|
||||||
|
|
||||||
if fillMissing {
|
if !fillMissing {
|
||||||
series := pointsBySeries[key]
|
break
|
||||||
// fill in values from last fetched value till interval end
|
}
|
||||||
intervalStart := series.Points[len(series.Points)-1][1].Float64
|
series := pointsBySeries[key]
|
||||||
intervalEnd := float64(tsdbQuery.TimeRange.MustGetTo().UnixNano() / 1e6)
|
// fill in values from last fetched value till interval end
|
||||||
|
intervalStart := series.Points[len(series.Points)-1][1].Float64
|
||||||
|
intervalEnd := float64(tsdbQuery.TimeRange.MustGetTo().UnixNano() / 1e6)
|
||||||
|
|
||||||
// align interval start
|
// align interval start
|
||||||
intervalStart = math.Floor(intervalStart/fillInterval) * fillInterval
|
intervalStart = math.Floor(intervalStart/fillInterval) * fillInterval
|
||||||
for i := intervalStart + fillInterval; i < intervalEnd; i += fillInterval {
|
for i := intervalStart + fillInterval; i < intervalEnd; i += fillInterval {
|
||||||
series.Points = append(series.Points, tsdb.TimePoint{fillValue, null.FloatFrom(i)})
|
series.Points = append(series.Points, tsdb.TimePoint{fillValue, null.FloatFrom(i)})
|
||||||
rowCount++
|
rowCount++
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,50 +141,51 @@ func (e *DefaultSqlEngine) Query(
|
|||||||
// ConvertSqlTimeColumnToEpochMs converts column named time to unix timestamp in milliseconds
|
// ConvertSqlTimeColumnToEpochMs converts column named time to unix timestamp in milliseconds
|
||||||
// to make native datetime types and epoch dates work in annotation and table queries.
|
// to make native datetime types and epoch dates work in annotation and table queries.
|
||||||
func ConvertSqlTimeColumnToEpochMs(values RowValues, timeIndex int) {
|
func ConvertSqlTimeColumnToEpochMs(values RowValues, timeIndex int) {
|
||||||
if timeIndex >= 0 {
|
if timeIndex < 0 {
|
||||||
switch value := values[timeIndex].(type) {
|
return
|
||||||
case time.Time:
|
}
|
||||||
values[timeIndex] = EpochPrecisionToMs(float64(value.UnixNano()))
|
switch value := values[timeIndex].(type) {
|
||||||
case *time.Time:
|
case time.Time:
|
||||||
if value != nil {
|
values[timeIndex] = EpochPrecisionToMs(float64(value.UnixNano()))
|
||||||
values[timeIndex] = EpochPrecisionToMs(float64((*value).UnixNano()))
|
case *time.Time:
|
||||||
}
|
if value != nil {
|
||||||
case int64:
|
values[timeIndex] = EpochPrecisionToMs(float64((*value).UnixNano()))
|
||||||
values[timeIndex] = int64(EpochPrecisionToMs(float64(value)))
|
}
|
||||||
case *int64:
|
case int64:
|
||||||
if value != nil {
|
values[timeIndex] = int64(EpochPrecisionToMs(float64(value)))
|
||||||
values[timeIndex] = int64(EpochPrecisionToMs(float64(*value)))
|
case *int64:
|
||||||
}
|
if value != nil {
|
||||||
case uint64:
|
values[timeIndex] = int64(EpochPrecisionToMs(float64(*value)))
|
||||||
values[timeIndex] = int64(EpochPrecisionToMs(float64(value)))
|
}
|
||||||
case *uint64:
|
case uint64:
|
||||||
if value != nil {
|
values[timeIndex] = int64(EpochPrecisionToMs(float64(value)))
|
||||||
values[timeIndex] = int64(EpochPrecisionToMs(float64(*value)))
|
case *uint64:
|
||||||
}
|
if value != nil {
|
||||||
case int32:
|
values[timeIndex] = int64(EpochPrecisionToMs(float64(*value)))
|
||||||
values[timeIndex] = int64(EpochPrecisionToMs(float64(value)))
|
}
|
||||||
case *int32:
|
case int32:
|
||||||
if value != nil {
|
values[timeIndex] = int64(EpochPrecisionToMs(float64(value)))
|
||||||
values[timeIndex] = int64(EpochPrecisionToMs(float64(*value)))
|
case *int32:
|
||||||
}
|
if value != nil {
|
||||||
case uint32:
|
values[timeIndex] = int64(EpochPrecisionToMs(float64(*value)))
|
||||||
values[timeIndex] = int64(EpochPrecisionToMs(float64(value)))
|
}
|
||||||
case *uint32:
|
case uint32:
|
||||||
if value != nil {
|
values[timeIndex] = int64(EpochPrecisionToMs(float64(value)))
|
||||||
values[timeIndex] = int64(EpochPrecisionToMs(float64(*value)))
|
case *uint32:
|
||||||
}
|
if value != nil {
|
||||||
case float64:
|
values[timeIndex] = int64(EpochPrecisionToMs(float64(*value)))
|
||||||
values[timeIndex] = EpochPrecisionToMs(value)
|
}
|
||||||
case *float64:
|
case float64:
|
||||||
if value != nil {
|
values[timeIndex] = EpochPrecisionToMs(value)
|
||||||
values[timeIndex] = EpochPrecisionToMs(*value)
|
case *float64:
|
||||||
}
|
if value != nil {
|
||||||
case float32:
|
values[timeIndex] = EpochPrecisionToMs(*value)
|
||||||
values[timeIndex] = EpochPrecisionToMs(float64(value))
|
}
|
||||||
case *float32:
|
case float32:
|
||||||
if value != nil {
|
values[timeIndex] = EpochPrecisionToMs(float64(value))
|
||||||
values[timeIndex] = EpochPrecisionToMs(float64(*value))
|
case *float32:
|
||||||
}
|
if value != nil {
|
||||||
|
values[timeIndex] = EpochPrecisionToMs(float64(*value))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user