Commit 0a936a55 by Torkel Ödegaard

Fixed new gometalinter issues

parent cfa3e05e
...@@ -206,10 +206,9 @@ func (f *JSONFormatter) processObject(object map[string]interface{}, deltas []di ...@@ -206,10 +206,9 @@ func (f *JSONFormatter) processObject(object map[string]interface{}, deltas []di
// Added // Added
for _, delta := range deltas { for _, delta := range deltas {
switch delta.(type) { switch delta := delta.(type) {
case *diff.Added: case *diff.Added:
d := delta.(*diff.Added) f.printRecursive(delta.Position.String(), delta.Value, ChangeAdded)
f.printRecursive(d.Position.String(), d.Value, ChangeAdded)
} }
} }
...@@ -222,9 +221,8 @@ func (f *JSONFormatter) processItem(value interface{}, deltas []diff.Delta, posi ...@@ -222,9 +221,8 @@ func (f *JSONFormatter) processItem(value interface{}, deltas []diff.Delta, posi
if len(matchedDeltas) > 0 { if len(matchedDeltas) > 0 {
for _, matchedDelta := range matchedDeltas { for _, matchedDelta := range matchedDeltas {
switch matchedDelta.(type) { switch matchedDelta := matchedDelta.(type) {
case *diff.Object: case *diff.Object:
d := matchedDelta.(*diff.Object)
switch value.(type) { switch value.(type) {
case map[string]interface{}: case map[string]interface{}:
//ok //ok
...@@ -238,7 +236,7 @@ func (f *JSONFormatter) processItem(value interface{}, deltas []diff.Delta, posi ...@@ -238,7 +236,7 @@ func (f *JSONFormatter) processItem(value interface{}, deltas []diff.Delta, posi
f.print("{") f.print("{")
f.closeLine() f.closeLine()
f.push(positionStr, len(o), false) f.push(positionStr, len(o), false)
f.processObject(o, d.Deltas) f.processObject(o, matchedDelta.Deltas)
f.pop() f.pop()
f.newLine(ChangeNil) f.newLine(ChangeNil)
f.print("}") f.print("}")
...@@ -246,7 +244,6 @@ func (f *JSONFormatter) processItem(value interface{}, deltas []diff.Delta, posi ...@@ -246,7 +244,6 @@ func (f *JSONFormatter) processItem(value interface{}, deltas []diff.Delta, posi
f.closeLine() f.closeLine()
case *diff.Array: case *diff.Array:
d := matchedDelta.(*diff.Array)
switch value.(type) { switch value.(type) {
case []interface{}: case []interface{}:
//ok //ok
...@@ -260,7 +257,7 @@ func (f *JSONFormatter) processItem(value interface{}, deltas []diff.Delta, posi ...@@ -260,7 +257,7 @@ func (f *JSONFormatter) processItem(value interface{}, deltas []diff.Delta, posi
f.print("[") f.print("[")
f.closeLine() f.closeLine()
f.push(positionStr, len(a), true) f.push(positionStr, len(a), true)
f.processArray(a, d.Deltas) f.processArray(a, matchedDelta.Deltas)
f.pop() f.pop()
f.newLine(ChangeNil) f.newLine(ChangeNil)
f.print("]") f.print("]")
...@@ -268,27 +265,23 @@ func (f *JSONFormatter) processItem(value interface{}, deltas []diff.Delta, posi ...@@ -268,27 +265,23 @@ func (f *JSONFormatter) processItem(value interface{}, deltas []diff.Delta, posi
f.closeLine() f.closeLine()
case *diff.Added: case *diff.Added:
d := matchedDelta.(*diff.Added) f.printRecursive(positionStr, matchedDelta.Value, ChangeAdded)
f.printRecursive(positionStr, d.Value, ChangeAdded)
f.size[len(f.size)-1]++ f.size[len(f.size)-1]++
case *diff.Modified: case *diff.Modified:
d := matchedDelta.(*diff.Modified)
savedSize := f.size[len(f.size)-1] savedSize := f.size[len(f.size)-1]
f.printRecursive(positionStr, d.OldValue, ChangeOld) f.printRecursive(positionStr, matchedDelta.OldValue, ChangeOld)
f.size[len(f.size)-1] = savedSize f.size[len(f.size)-1] = savedSize
f.printRecursive(positionStr, d.NewValue, ChangeNew) f.printRecursive(positionStr, matchedDelta.NewValue, ChangeNew)
case *diff.TextDiff: case *diff.TextDiff:
savedSize := f.size[len(f.size)-1] savedSize := f.size[len(f.size)-1]
d := matchedDelta.(*diff.TextDiff) f.printRecursive(positionStr, matchedDelta.OldValue, ChangeOld)
f.printRecursive(positionStr, d.OldValue, ChangeOld)
f.size[len(f.size)-1] = savedSize f.size[len(f.size)-1] = savedSize
f.printRecursive(positionStr, d.NewValue, ChangeNew) f.printRecursive(positionStr, matchedDelta.NewValue, ChangeNew)
case *diff.Deleted: case *diff.Deleted:
d := matchedDelta.(*diff.Deleted) f.printRecursive(positionStr, matchedDelta.Value, ChangeDeleted)
f.printRecursive(positionStr, d.Value, ChangeDeleted)
default: default:
return errors.New("Unknown Delta type detected") return errors.New("Unknown Delta type detected")
...@@ -305,13 +298,13 @@ func (f *JSONFormatter) processItem(value interface{}, deltas []diff.Delta, posi ...@@ -305,13 +298,13 @@ func (f *JSONFormatter) processItem(value interface{}, deltas []diff.Delta, posi
func (f *JSONFormatter) searchDeltas(deltas []diff.Delta, position diff.Position) (results []diff.Delta) { func (f *JSONFormatter) searchDeltas(deltas []diff.Delta, position diff.Position) (results []diff.Delta) {
results = make([]diff.Delta, 0) results = make([]diff.Delta, 0)
for _, delta := range deltas { for _, delta := range deltas {
switch delta.(type) { switch typedDelta := delta.(type) {
case diff.PostDelta: case diff.PostDelta:
if delta.(diff.PostDelta).PostPosition() == position { if typedDelta.PostPosition() == position {
results = append(results, delta) results = append(results, delta)
} }
case diff.PreDelta: case diff.PreDelta:
if delta.(diff.PreDelta).PrePosition() == position { if typedDelta.PrePosition() == position {
results = append(results, delta) results = append(results, delta)
} }
default: default:
...@@ -417,20 +410,19 @@ func (f *JSONFormatter) print(a string) { ...@@ -417,20 +410,19 @@ func (f *JSONFormatter) print(a string) {
} }
func (f *JSONFormatter) printRecursive(name string, value interface{}, change ChangeType) { func (f *JSONFormatter) printRecursive(name string, value interface{}, change ChangeType) {
switch value.(type) { switch value := value.(type) {
case map[string]interface{}: case map[string]interface{}:
f.newLine(change) f.newLine(change)
f.printKey(name) f.printKey(name)
f.print("{") f.print("{")
f.closeLine() f.closeLine()
m := value.(map[string]interface{}) size := len(value)
size := len(m)
f.push(name, size, false) f.push(name, size, false)
keys := sortKeys(m) keys := sortKeys(value)
for _, key := range keys { for _, key := range keys {
f.printRecursive(key, m[key], change) f.printRecursive(key, value[key], change)
} }
f.pop() f.pop()
...@@ -445,10 +437,9 @@ func (f *JSONFormatter) printRecursive(name string, value interface{}, change Ch ...@@ -445,10 +437,9 @@ func (f *JSONFormatter) printRecursive(name string, value interface{}, change Ch
f.print("[") f.print("[")
f.closeLine() f.closeLine()
s := value.([]interface{}) size := len(value)
size := len(s)
f.push("", size, true) f.push("", size, true)
for _, item := range s { for _, item := range value {
f.printRecursive("", item, change) f.printRecursive("", item, change)
} }
f.pop() f.pop()
......
...@@ -78,14 +78,14 @@ func GetUserLoginAttemptCount(query *m.GetUserLoginAttemptCountQuery) error { ...@@ -78,14 +78,14 @@ func GetUserLoginAttemptCount(query *m.GetUserLoginAttemptCountQuery) error {
} }
func toInt64(i interface{}) int64 { func toInt64(i interface{}) int64 {
switch i.(type) { switch i := i.(type) {
case []byte: case []byte:
n, _ := strconv.ParseInt(string(i.([]byte)), 10, 64) n, _ := strconv.ParseInt(string(i), 10, 64)
return n return n
case int: case int:
return int64(i.(int)) return int64(i)
case int64: case int64:
return i.(int64) return i
} }
return 0 return 0
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment