Skip to content

Commit 8182ba6

Browse files
committed
use type switch with var assignment
This makes it possible to avoid redundant type assertions. Found with https://go-critic.github.io/overview#typeswitchvar
1 parent 0dae4fe commit 8182ba6

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

sqlx.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,15 +149,15 @@ func isUnsafe(i interface{}) bool {
149149
}
150150

151151
func mapperFor(i interface{}) *reflectx.Mapper {
152-
switch i.(type) {
152+
switch i := i.(type) {
153153
case DB:
154-
return i.(DB).Mapper
154+
return i.Mapper
155155
case *DB:
156-
return i.(*DB).Mapper
156+
return i.Mapper
157157
case Tx:
158-
return i.(Tx).Mapper
158+
return i.Mapper
159159
case *Tx:
160-
return i.(*Tx).Mapper
160+
return i.Mapper
161161
default:
162162
return mapper()
163163
}

types/types.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ func (g GzippedText) Value() (driver.Value, error) {
3030
// the wire and storing the raw result in the GzippedText.
3131
func (g *GzippedText) Scan(src interface{}) error {
3232
var source []byte
33-
switch src.(type) {
33+
switch src := src.(type) {
3434
case string:
35-
source = []byte(src.(string))
35+
source = []byte(src)
3636
case []byte:
37-
source = src.([]byte)
37+
source = src
3838
default:
3939
return errors.New("Incompatible type for GzippedText")
4040
}

0 commit comments

Comments
 (0)