style: 合入后修 gofmt/govet 与 RegistrationView 类型检查
This commit is contained in:
@@ -302,9 +302,9 @@ func (a *App) ReceiptAck(ctx context.Context, endpointID string, req *protocol.R
|
||||
}
|
||||
var acked bool
|
||||
err = a.db.Queue.Do(ctx, func(tx *sql.Tx) error {
|
||||
res, err := tx.Exec(`UPDATE receipts SET acked = 1 WHERE receipt_id = ? AND sender_id = ? AND acked = 0`, rid, endpointID)
|
||||
if err != nil {
|
||||
return err
|
||||
res, execErr := tx.Exec(`UPDATE receipts SET acked = 1 WHERE receipt_id = ? AND sender_id = ? AND acked = 0`, rid, endpointID)
|
||||
if execErr != nil {
|
||||
return execErr
|
||||
}
|
||||
aff, _ := res.RowsAffected()
|
||||
acked = aff > 0
|
||||
|
||||
@@ -191,15 +191,15 @@ LIMIT ?`, endpointID, room)
|
||||
var items []pushItem
|
||||
for rows.Next() {
|
||||
var it pushItem
|
||||
if err := rows.Scan(&it.seq, &it.sendAt, &it.keep, &it.expireAt, &it.msgID, &it.senderID, &it.destKind, &it.destID, &it.meta, &it.contentType, &it.bodyEnc, &it.body); err != nil {
|
||||
if scanErr := rows.Scan(&it.seq, &it.sendAt, &it.keep, &it.expireAt, &it.msgID, &it.senderID, &it.destKind, &it.destID, &it.meta, &it.contentType, &it.bodyEnc, &it.body); scanErr != nil {
|
||||
_ = rows.Close()
|
||||
return err
|
||||
return scanErr
|
||||
}
|
||||
items = append(items, it)
|
||||
}
|
||||
_ = rows.Close()
|
||||
if err := rows.Err(); err != nil {
|
||||
return err
|
||||
if rowsErr := rows.Err(); rowsErr != nil {
|
||||
return rowsErr
|
||||
}
|
||||
|
||||
var toClaim []pushItem
|
||||
@@ -217,9 +217,9 @@ LIMIT ?`, endpointID, room)
|
||||
Meta: decodeMetaJSON(it.meta),
|
||||
SendAtMs: it.sendAt,
|
||||
}
|
||||
payload, err := protocol.Marshal(msg)
|
||||
if err != nil {
|
||||
return err
|
||||
payload, marshErr := protocol.Marshal(msg)
|
||||
if marshErr != nil {
|
||||
return marshErr
|
||||
}
|
||||
limit := effectivePayloadLimit(live.MaxPacketSize, live.MaxReceiveBytes)
|
||||
if limit > 0 && len(payload) > limit {
|
||||
|
||||
@@ -198,14 +198,14 @@ func TestC03WALShrinksAfterPurge(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
nowMs := int64(1_700_000_000_000)
|
||||
err = db.Queue.Do(ctx, func(tx *sql.Tx) error {
|
||||
if _, err := tx.Exec(`INSERT INTO endpoints(id,name,login_hash,enabled,created_at) VALUES('alice','a','x',1,?)`, nowMs); err != nil {
|
||||
return err
|
||||
if _, insErr := tx.Exec(`INSERT INTO endpoints(id,name,login_hash,enabled,created_at) VALUES('alice','a','x',1,?)`, nowMs); insErr != nil {
|
||||
return insErr
|
||||
}
|
||||
for i := 0; i < 200; i++ {
|
||||
if _, err := tx.Exec(`INSERT INTO messages(id, sender_id, dest_kind, dest_id, meta, content_type, body_enc, send_at, keep, ttl_seconds, receipt, state, reason, created_at)
|
||||
if _, insErr := tx.Exec(`INSERT INTO messages(id, sender_id, dest_kind, dest_id, meta, content_type, body_enc, send_at, keep, ttl_seconds, receipt, state, reason, created_at)
|
||||
VALUES(?,?, 'endpoint','bob','{}','text/plain','utf8',?,0,0,0,'completed','',?)`,
|
||||
"m"+itoa(i), "alice", nowMs-10*24*3600*1000, nowMs-10*24*3600*1000); err != nil {
|
||||
return err
|
||||
"m"+itoa(i), "alice", nowMs-10*24*3600*1000, nowMs-10*24*3600*1000); insErr != nil {
|
||||
return insErr
|
||||
}
|
||||
}
|
||||
return nil
|
||||
@@ -217,8 +217,8 @@ VALUES(?,?, 'endpoint','bob','{}','text/plain','utf8',?,0,0,0,'completed','',?)`
|
||||
before, _ := os.Stat(walPath)
|
||||
app := New(db, Limits{RecordRetentionDays: 1, ReceiptRetentionDays: 1, IdempotencyHours: 1}, nil)
|
||||
app.nowFn = func() time.Time { return time.UnixMilli(nowMs) }
|
||||
if err := app.PurgeOnce(ctx, nowMs); err != nil {
|
||||
t.Fatal(err)
|
||||
if purgeErr := app.PurgeOnce(ctx, nowMs); purgeErr != nil {
|
||||
t.Fatal(purgeErr)
|
||||
}
|
||||
after, err := os.Stat(walPath)
|
||||
if err == nil && before != nil && after.Size() > before.Size() {
|
||||
|
||||
@@ -508,7 +508,9 @@ WHERE m.id='late-1' AND d.endpoint_id='bob'`).Scan(&bobN); err != nil {
|
||||
app, db := openTestApp(t, lim)
|
||||
insertEndpoint(t, db, "alice", "", 1, 0)
|
||||
insertEndpoint(t, db, "bob", "", 1, 0)
|
||||
if !app.AllowRequest("alice") || !app.AllowRequest("alice") {
|
||||
first := app.AllowRequest("alice")
|
||||
second := app.AllowRequest("alice")
|
||||
if !first || !second {
|
||||
t.Fatal("burst should allow first two")
|
||||
}
|
||||
if app.AllowRequest("alice") {
|
||||
@@ -544,9 +546,9 @@ func TestU03SubmitTalkLockNoIP(t *testing.T) {
|
||||
for i := 0; i < 10; i++ {
|
||||
bad := baseSend(fmt.Sprintf("w%d", i), "bob")
|
||||
bad.TalkPassword = "wrong"
|
||||
_, err := app.Submit(ctx, "alice", port.ConnInfo{RemoteIP: fmt.Sprintf("10.0.0.%d", i+1)}, bad)
|
||||
if protoCode(err) != protocol.CodeTalkPasswordInvalid {
|
||||
t.Fatalf("i=%d got %v", i, err)
|
||||
_, subErr := app.Submit(ctx, "alice", port.ConnInfo{RemoteIP: fmt.Sprintf("10.0.0.%d", i+1)}, bad)
|
||||
if protoCode(subErr) != protocol.CodeTalkPasswordInvalid {
|
||||
t.Fatalf("i=%d got %v", i, subErr)
|
||||
}
|
||||
}
|
||||
empty := baseSend("empty", "bob")
|
||||
|
||||
@@ -142,4 +142,4 @@ VALUES(?,?,?,0,'accepted','',?)`, seq, "bob", nowMs, nowMs)
|
||||
if n != 1 {
|
||||
t.Fatalf("recently completed message should remain, n=%d", n)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user