Use keyed fields for ‘go vet’

This commit is contained in:
Tobie Morgan Hitchcock 2016-12-08 22:03:42 +00:00
parent 9b8aec6549
commit 7728c5b398
8 changed files with 56 additions and 56 deletions

View file

@ -29,7 +29,7 @@ func (ds *DS) Txn(writable bool) (txn kvs.TX, err error) {
tx, err := ds.db.Begin(writable)
if err != nil {
err = &kvs.DSError{err}
err = &kvs.DSError{Err: err}
if tx != nil {
tx.Rollback()
}

View file

@ -150,22 +150,22 @@ func (tx *TX) RGet(beg, end []byte, max uint64) (kvs []kvs.KV, err error) {
func (tx *TX) Put(key, val []byte) (err error) {
if !tx.tx.Writable() {
err = &kvs.TXError{err}
err = &kvs.TXError{Err: err}
return
}
if val, err = snap.Encode(val); err != nil {
err = &kvs.DBError{err}
err = &kvs.DBError{Err: err}
return
}
if val, err = cryp.Encrypt(tx.ds.ck, val); err != nil {
err = &kvs.CKError{err}
err = &kvs.CKError{Err: err}
return
}
if err = tx.bu.Put(key, val); err != nil {
err = &kvs.DBError{err}
err = &kvs.DBError{Err: err}
return
}
@ -179,7 +179,7 @@ func (tx *TX) Put(key, val []byte) (err error) {
func (tx *TX) CPut(key, val, exp []byte) (err error) {
if !tx.tx.Writable() {
err = &kvs.TXError{err}
err = &kvs.TXError{Err: err}
return
}
@ -187,22 +187,22 @@ func (tx *TX) CPut(key, val, exp []byte) (err error) {
act := now.(*KV).val
if !bytes.Equal(act, exp) {
err = &kvs.KVError{err, key, act, exp}
err = &kvs.KVError{Err: err, Key: key, Val: act, Exp: exp}
return
}
if val, err = snap.Encode(val); err != nil {
err = &kvs.DBError{err}
err = &kvs.DBError{Err: err}
return
}
if val, err = cryp.Encrypt(tx.ds.ck, val); err != nil {
err = &kvs.CKError{err}
err = &kvs.CKError{Err: err}
return
}
if err = tx.bu.Put(key, val); err != nil {
err = &kvs.DBError{err}
err = &kvs.DBError{Err: err}
return
}
@ -214,12 +214,12 @@ func (tx *TX) CPut(key, val, exp []byte) (err error) {
func (tx *TX) Del(key []byte) (err error) {
if !tx.tx.Writable() {
err = &kvs.TXError{err}
err = &kvs.TXError{Err: err}
return
}
if err = tx.bu.Delete(key); err != nil {
err = &kvs.DBError{err}
err = &kvs.DBError{Err: err}
return
}
@ -232,7 +232,7 @@ func (tx *TX) Del(key []byte) (err error) {
func (tx *TX) CDel(key, exp []byte) (err error) {
if !tx.tx.Writable() {
err = &kvs.TXError{err}
err = &kvs.TXError{Err: err}
return
}
@ -240,12 +240,12 @@ func (tx *TX) CDel(key, exp []byte) (err error) {
act := now.(*KV).val
if !bytes.Equal(act, exp) {
err = &kvs.KVError{err, key, act, exp}
err = &kvs.KVError{Err: err, Key: key, Val: act, Exp: exp}
return
}
if err = tx.bu.Delete(key); err != nil {
err = &kvs.DBError{err}
err = &kvs.DBError{Err: err}
return
}
@ -257,14 +257,14 @@ func (tx *TX) CDel(key, exp []byte) (err error) {
func (tx *TX) MDel(keys ...[]byte) (err error) {
if !tx.tx.Writable() {
err = &kvs.TXError{err}
err = &kvs.TXError{Err: err}
return
}
for _, key := range keys {
if err = tx.bu.Delete(key); err != nil {
err = &kvs.DBError{err}
err = &kvs.DBError{Err: err}
return
}
@ -281,7 +281,7 @@ func (tx *TX) PDel(pre []byte) (err error) {
for key, _ := cu.Seek(pre); bytes.HasPrefix(key, pre); key, _ = cu.Seek(pre) {
if err = tx.bu.Delete(key); err != nil {
err = &kvs.DBError{err}
err = &kvs.DBError{Err: err}
return
}
}
@ -300,7 +300,7 @@ func (tx *TX) RDel(beg, end []byte, max uint64) (err error) {
}
if !tx.tx.Writable() {
err = &kvs.TXError{err}
err = &kvs.TXError{Err: err}
return
}
@ -309,7 +309,7 @@ func (tx *TX) RDel(beg, end []byte, max uint64) (err error) {
if bytes.Compare(beg, end) < 1 {
for key, _ := cu.Seek(beg); key != nil && max > 0 && bytes.Compare(key, end) < 0; key, _ = cu.Seek(beg) {
if err = tx.bu.Delete(key); err != nil {
err = &kvs.DBError{err}
err = &kvs.DBError{Err: err}
return
}
max--
@ -319,7 +319,7 @@ func (tx *TX) RDel(beg, end []byte, max uint64) (err error) {
if bytes.Compare(beg, end) > 1 {
for key, _ := cu.Seek(end); key != nil && max > 0 && bytes.Compare(beg, key) < 0; key, _ = cu.Seek(end) {
if err = tx.bu.Delete(key); err != nil {
err = &kvs.DBError{err}
err = &kvs.DBError{Err: err}
return
}
max--
@ -365,13 +365,13 @@ func get(tx *TX, key, val []byte) (kv *KV, err error) {
kv.val, err = cryp.Decrypt(tx.ds.ck, kv.val)
if err != nil {
err = &kvs.CKError{err}
err = &kvs.CKError{Err: err}
return
}
kv.val, err = snap.Decode(kv.val)
if err != nil {
err = &kvs.DBError{err}
err = &kvs.DBError{Err: err}
return
}

View file

@ -29,7 +29,7 @@ func (ds *DS) Txn(writable bool) (txn kvs.TX, err error) {
tx, err := ds.db.Begin()
if err != nil {
err = &kvs.DSError{err}
err = &kvs.DSError{Err: err}
if tx != nil {
tx.Rollback()
}

View file

@ -183,17 +183,17 @@ func (tx *TX) RGet(beg, end []byte, max uint64) (kvs []kvs.KV, err error) {
func (tx *TX) Put(key, val []byte) (err error) {
if val, err = snap.Encode(val); err != nil {
err = &kvs.DBError{err}
err = &kvs.DBError{Err: err}
return
}
if val, err = cryp.Encrypt(tx.ds.ck, val); err != nil {
err = &kvs.CKError{err}
err = &kvs.CKError{Err: err}
return
}
if _, err = tx.tx.Exec("INSERT INTO kv (`key`, `val`) VALUES (?, ?) ON DUPLICATE KEY UPDATE `val` = ?", key, val, val); err != nil {
err = &kvs.DBError{err}
err = &kvs.DBError{Err: err}
return
}
@ -210,22 +210,22 @@ func (tx *TX) CPut(key, val, exp []byte) (err error) {
act := now.(*KV).val
if !bytes.Equal(act, exp) {
err = &kvs.KVError{err, key, act, exp}
err = &kvs.KVError{Err: err, Key: key, Val: act, Exp: exp}
return
}
if val, err = snap.Encode(val); err != nil {
err = &kvs.DBError{err}
err = &kvs.DBError{Err: err}
return
}
if val, err = cryp.Encrypt(tx.ds.ck, val); err != nil {
err = &kvs.CKError{err}
err = &kvs.CKError{Err: err}
return
}
if _, err = tx.tx.Exec("INSERT INTO kv (`key`, `val`) VALUES (?, ?) ON DUPLICATE KEY UPDATE `val` = ?", key, val, val); err != nil {
err = &kvs.DBError{err}
err = &kvs.DBError{Err: err}
return
}
@ -237,7 +237,7 @@ func (tx *TX) CPut(key, val, exp []byte) (err error) {
func (tx *TX) Del(key []byte) (err error) {
if _, err = tx.tx.Exec("DELETE FROM kv WHERE `key` = ?", key); err != nil {
err = &kvs.DBError{err}
err = &kvs.DBError{Err: err}
return
}
@ -253,12 +253,12 @@ func (tx *TX) CDel(key, exp []byte) (err error) {
act := now.(*KV).val
if !bytes.Equal(act, exp) {
err = &kvs.KVError{err, key, act, exp}
err = &kvs.KVError{Err: err, Key: key, Val: act, Exp: exp}
return
}
if _, err = tx.tx.Exec("DELETE FROM kv WHERE `key` = ?", key); err != nil {
err = &kvs.DBError{err}
err = &kvs.DBError{Err: err}
return
}
@ -271,7 +271,7 @@ func (tx *TX) MDel(keys ...[]byte) (err error) {
/*
if _, err = tx.tx.Exec("DELETE FROM kv WHERE `key` IN (?)", keys); err != nil {
err = &kvs.DBError{err}
err = &kvs.DBError{Err:err}
return
}
*/
@ -303,7 +303,7 @@ func (tx *TX) RDel(beg, end []byte, max uint64) (err error) {
}
if _, err = tx.tx.Exec("DELETE FROM kv WHERE `key` BETWEEN ? AND ? ORDER BY `key` ASC LIMIT ?", beg, end, max); err != nil {
err = &kvs.DBError{err}
err = &kvs.DBError{Err: err}
return
}
@ -343,13 +343,13 @@ func get(tx *TX, key, val []byte) (kv *KV, err error) {
kv.val, err = cryp.Decrypt(tx.ds.ck, kv.val)
if err != nil {
err = &kvs.CKError{err}
err = &kvs.CKError{Err: err}
return
}
kv.val, err = snap.Decode(kv.val)
if err != nil {
err = &kvs.DBError{err}
err = &kvs.DBError{Err: err}
return
}

View file

@ -29,7 +29,7 @@ func (ds *DS) Txn(writable bool) (txn kvs.TX, err error) {
tx, err := ds.db.Begin()
if err != nil {
err = &kvs.DSError{err}
err = &kvs.DSError{Err: err}
if tx != nil {
tx.Rollback()
}

View file

@ -151,7 +151,7 @@ func (tx *TX) RGet(beg, end []byte, max uint64) (items []kvs.KV, err error) {
res, err := tx.tx.Query("SELECT key, val FROM kv WHERE key BETWEEN $1 AND $2 ORDER BY key ASC LIMIT $3", beg, end, max)
if err != nil {
err = &kvs.DBError{err}
err = &kvs.DBError{Err: err}
return nil, err
}
@ -188,17 +188,17 @@ func (tx *TX) RGet(beg, end []byte, max uint64) (items []kvs.KV, err error) {
func (tx *TX) Put(key, val []byte) (err error) {
if val, err = snap.Encode(val); err != nil {
err = &kvs.DBError{err}
err = &kvs.DBError{Err: err}
return
}
if val, err = cryp.Encrypt(tx.ds.ck, val); err != nil {
err = &kvs.CKError{err}
err = &kvs.CKError{Err: err}
return
}
if _, err = tx.tx.Exec("INSERT INTO kv (key, val) VALUES ($1, $2) ON CONFLICT (key) DO UPDATE SET val = $2", key, val); err != nil {
err = &kvs.DBError{err}
err = &kvs.DBError{Err: err}
return
}
@ -215,22 +215,22 @@ func (tx *TX) CPut(key, val, exp []byte) (err error) {
act := now.(*KV).val
if !bytes.Equal(act, exp) {
err = &kvs.KVError{err, key, act, exp}
err = &kvs.KVError{Err: err, Key: key, Val: act, Exp: exp}
return
}
if val, err = snap.Encode(val); err != nil {
err = &kvs.DBError{err}
err = &kvs.DBError{Err: err}
return
}
if val, err = cryp.Encrypt(tx.ds.ck, val); err != nil {
err = &kvs.CKError{err}
err = &kvs.CKError{Err: err}
return
}
if _, err = tx.tx.Exec("INSERT INTO kv (key, val) VALUES ($1, $2) ON CONFLICT (key) DO UPDATE SET val = $2", key, val); err != nil {
err = &kvs.DBError{err}
err = &kvs.DBError{Err: err}
return
}
@ -242,7 +242,7 @@ func (tx *TX) CPut(key, val, exp []byte) (err error) {
func (tx *TX) Del(key []byte) (err error) {
if _, err = tx.tx.Exec("DELETE FROM kv WHERE key = $1", key); err != nil {
err = &kvs.DBError{err}
err = &kvs.DBError{Err: err}
return
}
@ -258,12 +258,12 @@ func (tx *TX) CDel(key, exp []byte) (err error) {
act := now.(*KV).val
if !bytes.Equal(act, exp) {
err = &kvs.KVError{err, key, act, exp}
err = &kvs.KVError{Err: err, Key: key, Val: act, Exp: exp}
return
}
if _, err = tx.tx.Exec("DELETE FROM kv WHERE key = $1", key); err != nil {
err = &kvs.DBError{err}
err = &kvs.DBError{Err: err}
return
}
@ -276,7 +276,7 @@ func (tx *TX) MDel(keys ...[]byte) (err error) {
/*
if _, err = tx.tx.Exec("DELETE FROM kv WHERE key IN ($1)", keys); err != nil {
err = &kvs.DBError{err}
err = &kvs.DBError{Err:err}
return
}
*/
@ -312,7 +312,7 @@ func (tx *TX) RDel(beg, end []byte, max uint64) (err error) {
}
if _, err = tx.tx.Exec("DELETE FROM kv WHERE key BETWEEN $1 AND $2 ORDER BY key ASC LIMIT $3", beg, end, max); err != nil {
err = &kvs.DBError{err}
err = &kvs.DBError{Err: err}
return
}
@ -352,13 +352,13 @@ func get(tx *TX, key, val []byte) (kv *KV, err error) {
kv.val, err = cryp.Decrypt(tx.ds.ck, kv.val)
if err != nil {
err = &kvs.CKError{err}
err = &kvs.CKError{Err: err}
return
}
kv.val, err = snap.Decode(kv.val)
if err != nil {
err = &kvs.DBError{err}
err = &kvs.DBError{Err: err}
return
}

View file

@ -60,7 +60,7 @@ func signin(c *fibre.Context) (err error) {
// Process the scope signin statement.
res, err = db.Process(c, &sql.Query{[]sql.Statement{scp.Signin}}, vars)
res, err = db.Process(c, &sql.Query{Statements: []sql.Statement{scp.Signin}}, vars)
if err != nil {
return fibre.NewHTTPError(403)
}

View file

@ -54,7 +54,7 @@ func signup(c *fibre.Context) (err error) {
// Process the scope signup statement.
res, err = db.Process(c, &sql.Query{[]sql.Statement{scp.Signup}}, vars)
res, err = db.Process(c, &sql.Query{Statements: []sql.Statement{scp.Signup}}, vars)
if err != nil {
return fibre.NewHTTPError(403)
}