mirror of
https://github.com/grafana/grafana.git
synced 2025-07-30 19:13:07 +08:00
Revert "Opportunities to unindent code (unindent)"
This commit is contained in:

committed by
GitHub

parent
6dcb9e696d
commit
de0d409a23
@ -99,9 +99,11 @@ func Error(status int, message string, err error) *NormalResponse {
|
||||
data["message"] = message
|
||||
}
|
||||
|
||||
if err != nil && setting.Env != setting.PROD {
|
||||
if err != nil {
|
||||
if setting.Env != setting.PROD {
|
||||
data["error"] = err.Error()
|
||||
}
|
||||
}
|
||||
|
||||
resp := JSON(status, data)
|
||||
|
||||
|
@ -639,9 +639,7 @@ func (v *Value) Object() (*Object, error) {
|
||||
valid = true
|
||||
}
|
||||
|
||||
if !valid {
|
||||
return nil, ErrNotObject
|
||||
}
|
||||
if valid {
|
||||
obj := new(Object)
|
||||
obj.valid = valid
|
||||
|
||||
@ -650,6 +648,7 @@ func (v *Value) Object() (*Object, error) {
|
||||
if valid {
|
||||
for key, element := range v.data.(map[string]interface{}) {
|
||||
m[key] = &Value{element, true}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -659,6 +658,9 @@ func (v *Value) Object() (*Object, error) {
|
||||
return obj, nil
|
||||
}
|
||||
|
||||
return nil, ErrNotObject
|
||||
}
|
||||
|
||||
// Attempts to typecast the current value into an object arrau.
|
||||
// Returns error if the current value is not an array of json objects
|
||||
// Example:
|
||||
@ -676,9 +678,8 @@ 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 {
|
||||
return nil, ErrNotObjectArray
|
||||
}
|
||||
if valid {
|
||||
|
||||
for _, element := range v.data.([]interface{}) {
|
||||
childValue := Value{element, true}
|
||||
childObject, err := childValue.Object()
|
||||
@ -688,9 +689,14 @@ 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.
|
||||
// Returns error if the current value is not a json string
|
||||
// Example:
|
||||
|
@ -168,9 +168,11 @@ 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 && len(a) > index {
|
||||
if err == nil {
|
||||
if len(a) > index {
|
||||
return &Json{a[index]}
|
||||
}
|
||||
}
|
||||
return &Json{nil}
|
||||
}
|
||||
|
||||
|
@ -24,12 +24,12 @@ func RedirectFromLegacyDashboardURL() macaron.Handler {
|
||||
return func(c *m.ReqContext) {
|
||||
slug := c.Params("slug")
|
||||
|
||||
if slug == "" {
|
||||
return
|
||||
}
|
||||
if slug != "" {
|
||||
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,16 +39,17 @@ func RedirectFromLegacyDashboardSoloURL() macaron.Handler {
|
||||
slug := c.Params("slug")
|
||||
renderRequest := c.QueryBool("render")
|
||||
|
||||
if slug == "" {
|
||||
return
|
||||
}
|
||||
if slug != "" {
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -298,9 +298,7 @@ func (e MssqlQueryEndpoint) transformToTimeSeries(query *tsdb.Query, rows *core.
|
||||
key := elem.Value.(string)
|
||||
result.Series = append(result.Series, pointsBySeries[key])
|
||||
|
||||
if !fillMissing {
|
||||
break
|
||||
}
|
||||
if fillMissing {
|
||||
series := pointsBySeries[key]
|
||||
// fill in values from last fetched value till interval end
|
||||
intervalStart := series.Points[len(series.Points)-1][1].Float64
|
||||
@ -313,6 +311,7 @@ func (e MssqlQueryEndpoint) transformToTimeSeries(query *tsdb.Query, rows *core.
|
||||
rowCount++
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result.Meta.Set("rowCount", rowCount)
|
||||
return nil
|
||||
|
@ -309,9 +309,7 @@ func (e MysqlQueryEndpoint) transformToTimeSeries(query *tsdb.Query, rows *core.
|
||||
key := elem.Value.(string)
|
||||
result.Series = append(result.Series, pointsBySeries[key])
|
||||
|
||||
if !fillMissing {
|
||||
break
|
||||
}
|
||||
if fillMissing {
|
||||
series := pointsBySeries[key]
|
||||
// fill in values from last fetched value till interval end
|
||||
intervalStart := series.Points[len(series.Points)-1][1].Float64
|
||||
@ -324,6 +322,7 @@ func (e MysqlQueryEndpoint) transformToTimeSeries(query *tsdb.Query, rows *core.
|
||||
rowCount++
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result.Meta.Set("rowCount", rowCount)
|
||||
return nil
|
||||
|
@ -289,9 +289,7 @@ func (e PostgresQueryEndpoint) transformToTimeSeries(query *tsdb.Query, rows *co
|
||||
key := elem.Value.(string)
|
||||
result.Series = append(result.Series, pointsBySeries[key])
|
||||
|
||||
if !fillMissing {
|
||||
break
|
||||
}
|
||||
if fillMissing {
|
||||
series := pointsBySeries[key]
|
||||
// fill in values from last fetched value till interval end
|
||||
intervalStart := series.Points[len(series.Points)-1][1].Float64
|
||||
@ -304,6 +302,7 @@ func (e PostgresQueryEndpoint) transformToTimeSeries(query *tsdb.Query, rows *co
|
||||
rowCount++
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result.Meta.Set("rowCount", rowCount)
|
||||
return nil
|
||||
|
@ -141,9 +141,7 @@ 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 {
|
||||
return
|
||||
}
|
||||
if timeIndex >= 0 {
|
||||
switch value := values[timeIndex].(type) {
|
||||
case time.Time:
|
||||
values[timeIndex] = EpochPrecisionToMs(float64(value.UnixNano()))
|
||||
@ -189,6 +187,7 @@ func ConvertSqlTimeColumnToEpochMs(values RowValues, timeIndex int) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ConvertSqlValueColumnToFloat converts timeseries value column to float.
|
||||
func ConvertSqlValueColumnToFloat(columnName string, columnValue interface{}) (null.Float, error) {
|
||||
|
Reference in New Issue
Block a user