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:
Karsten Weiss 2018-04-28 10:45:45 +02:00
parent c5419ba885
commit 893a91af3a
8 changed files with 125 additions and 132 deletions

View File

@ -99,11 +99,9 @@ func Error(status int, message string, err error) *NormalResponse {
data["message"] = message
}
if err != nil {
if setting.Env != setting.PROD {
if err != nil && setting.Env != setting.PROD {
data["error"] = err.Error()
}
}
resp := JSON(status, data)

View File

@ -639,7 +639,9 @@ func (v *Value) Object() (*Object, error) {
valid = true
}
if valid {
if !valid {
return nil, ErrNotObject
}
obj := new(Object)
obj.valid = valid
@ -648,7 +650,6 @@ func (v *Value) Object() (*Object, error) {
if valid {
for key, element := range v.data.(map[string]interface{}) {
m[key] = &Value{element, true}
}
}
@ -656,9 +657,6 @@ func (v *Value) Object() (*Object, error) {
obj.m = m
return obj, nil
}
return nil, ErrNotObject
}
// Attempts to typecast the current value into an object arrau.
@ -678,8 +676,9 @@ func (v *Value) ObjectArray() ([]*Object, error) {
// Unsure if this is a good way to use slices, it's probably not
var slice []*Object
if valid {
if !valid {
return nil, ErrNotObjectArray
}
for _, element := range v.data.([]interface{}) {
childValue := Value{element, true}
childObject, err := childValue.Object()
@ -689,12 +688,7 @@ func (v *Value) ObjectArray() ([]*Object, error) {
}
slice = append(slice, childObject)
}
return slice, nil
}
return nil, ErrNotObjectArray
}
// Attempts to typecast the current value into a string.

View File

@ -168,11 +168,9 @@ func (j *Json) GetPath(branch ...string) *Json {
// js.Get("top_level").Get("array").GetIndex(1).Get("key").Int()
func (j *Json) GetIndex(index int) *Json {
a, err := j.Array()
if err == nil {
if len(a) > index {
if err == nil && len(a) > index {
return &Json{a[index]}
}
}
return &Json{nil}
}

View File

@ -24,12 +24,12 @@ func RedirectFromLegacyDashboardURL() macaron.Handler {
return func(c *m.ReqContext) {
slug := c.Params("slug")
if slug != "" {
if slug == "" {
return
}
if url, err := getDashboardURLBySlug(c.OrgId, slug); err == nil {
url = fmt.Sprintf("%s?%s", url, c.Req.URL.RawQuery)
c.Redirect(url, 301)
return
}
}
}
}
@ -39,17 +39,16 @@ func RedirectFromLegacyDashboardSoloURL() macaron.Handler {
slug := c.Params("slug")
renderRequest := c.QueryBool("render")
if slug != "" {
if slug == "" {
return
}
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
}
}
}
}

View File

@ -298,7 +298,9 @@ func (e MssqlQueryEndpoint) transformToTimeSeries(query *tsdb.Query, rows *core.
key := elem.Value.(string)
result.Series = append(result.Series, pointsBySeries[key])
if fillMissing {
if !fillMissing {
break
}
series := pointsBySeries[key]
// fill in values from last fetched value till interval end
intervalStart := series.Points[len(series.Points)-1][1].Float64
@ -311,7 +313,6 @@ func (e MssqlQueryEndpoint) transformToTimeSeries(query *tsdb.Query, rows *core.
rowCount++
}
}
}
result.Meta.Set("rowCount", rowCount)
return nil

View File

@ -309,7 +309,9 @@ func (e MysqlQueryEndpoint) transformToTimeSeries(query *tsdb.Query, rows *core.
key := elem.Value.(string)
result.Series = append(result.Series, pointsBySeries[key])
if fillMissing {
if !fillMissing {
break
}
series := pointsBySeries[key]
// fill in values from last fetched value till interval end
intervalStart := series.Points[len(series.Points)-1][1].Float64
@ -322,7 +324,6 @@ func (e MysqlQueryEndpoint) transformToTimeSeries(query *tsdb.Query, rows *core.
rowCount++
}
}
}
result.Meta.Set("rowCount", rowCount)
return nil

View File

@ -289,7 +289,9 @@ func (e PostgresQueryEndpoint) transformToTimeSeries(query *tsdb.Query, rows *co
key := elem.Value.(string)
result.Series = append(result.Series, pointsBySeries[key])
if fillMissing {
if !fillMissing {
break
}
series := pointsBySeries[key]
// fill in values from last fetched value till interval end
intervalStart := series.Points[len(series.Points)-1][1].Float64
@ -302,7 +304,6 @@ func (e PostgresQueryEndpoint) transformToTimeSeries(query *tsdb.Query, rows *co
rowCount++
}
}
}
result.Meta.Set("rowCount", rowCount)
return nil

View File

@ -141,7 +141,9 @@ func (e *DefaultSqlEngine) Query(
// ConvertSqlTimeColumnToEpochMs converts column named time to unix timestamp in milliseconds
// to make native datetime types and epoch dates work in annotation and table queries.
func ConvertSqlTimeColumnToEpochMs(values RowValues, timeIndex int) {
if timeIndex >= 0 {
if timeIndex < 0 {
return
}
switch value := values[timeIndex].(type) {
case time.Time:
values[timeIndex] = EpochPrecisionToMs(float64(value.UnixNano()))
@ -186,7 +188,6 @@ func ConvertSqlTimeColumnToEpochMs(values RowValues, timeIndex int) {
values[timeIndex] = EpochPrecisionToMs(float64(*value))
}
}
}
}
// ConvertSqlValueColumnToFloat converts timeseries value column to float.