Skip to content

Conversation

@jyxjjj
Copy link
Member

@jyxjjj jyxjjj commented Nov 25, 2025

Description / 描述

Changed the Call methods in httpCaller and websocketCaller to use pointer receivers instead of value receivers. This ensures that any modifications to the receiver's state within the method are preserved and aligns with Go best practices for methods that may modify receiver state.

Motivation and Context

How Has This Been Tested?

Checklist

  • I have read the CONTRIBUTING document.

  • I have formatted my code with go fmt or prettier.

  • I have added appropriate labels to this PR (or mentioned needed labels in the description if lacking permissions).

  • I have requested review from relevant code authors using the "Request review" feature when applicable.

Changed the Call methods in httpCaller and websocketCaller to use pointer receivers instead of value receivers. This ensures that any modifications to the receiver's state within the method are preserved and aligns with Go best practices for methods that may modify receiver state.
@jyxjjj jyxjjj changed the title fix(caller): Use pointer receivers for Call methods fix(rpc/aria2): Use pointer receivers for Call methods Nov 25, 2025
@KirCute
Copy link
Member

KirCute commented Nov 25, 2025

这两个函数会改变接收器内部的值吗,或者说,如果它以前这么写一直都没有问题,为什么要改这个

@jyxjjj
Copy link
Member Author

jyxjjj commented Nov 25, 2025

这两个函数会改变接收器内部的值吗,或者说,如果它以前这么写一直都没有问题,为什么要改这个

其实不是改变的问题,是复制的问题,原来的写法应该属于1.20以前的语法,改的原因是vet对1.20后的代码检查更严格而已,其实属于chore,出问题的点在于sync.Once。但是复制变量与性能有关,所以用fix做title。

@ILoveScratch2
Copy link
Member

这两个函数会改变接收器内部的值吗,或者说,如果它以前这么写一直都没有问题,为什么要改这个

看起来不会改字段值,但是改指针也没问题……

@KirCute
Copy link
Member

KirCute commented Nov 25, 2025

我其实更担心一种很极端的情况,就是它故意用的非指针接收器,然后就是希望调用的时候把结构体复制一份,这样的事我在c++里干过。不过你们要是看了它没改里面的值的话那就没问题

@KirCute KirCute changed the title fix(rpc/aria2): Use pointer receivers for Call methods fix(pkg/aria2): use pointer receivers for Call methods Nov 25, 2025
@jyxjjj jyxjjj merged commit 62dedb2 into main Nov 25, 2025
14 checks passed
@jyxjjj jyxjjj deleted the fix-caller-pointer branch November 25, 2025 05:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants