Skip to content

Commit e26e628

Browse files
use withtx2 correctly
1 parent 1d9e98c commit e26e628

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

models/repo/mirror_ssh_keypair.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,16 +157,13 @@ func DeleteUserSSHKeypair(ctx context.Context, ownerID int64) error {
157157

158158
// RegenerateUserSSHKeypair regenerates an SSH keypair for the given owner
159159
func RegenerateUserSSHKeypair(ctx context.Context, ownerID int64) (*UserSSHKeypair, error) {
160-
var keypair *UserSSHKeypair
161-
err := db.WithTx2(ctx, func(ctx context.Context) error {
160+
return db.WithTx2(ctx, func(ctx context.Context) (*UserSSHKeypair, error) {
162161
_ = DeleteUserSSHKeypair(ctx, ownerID)
163162

164163
newKeypair, err := CreateUserSSHKeypair(ctx, ownerID)
165164
if err != nil {
166-
return err
165+
return nil, err
167166
}
168-
keypair = newKeypair
169-
return nil
167+
return newKeypair, nil
170168
})
171-
return keypair, err
172169
}

0 commit comments

Comments
 (0)