Apply suggestions from code review

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Hua Audio 2026-03-22 06:16:25 +01:00 committed by GitHub
parent 7b65f1ca7a
commit 8fec5a75e9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 18 additions and 9 deletions

View file

@ -523,7 +523,7 @@ picoclaw onboard weixin
Scan the printed QR code with your WeChat mobile app. On success, the token is saved to your config. Scan the printed QR code with your WeChat mobile app. On success, the token is saved to your config.
**2. Configure** **2. Configure**
Optional) Update `allow_from` with your WeChat User ID to restrict who can message the bot: (Optional) Update `allow_from` with your WeChat User ID to restrict who can message the bot:
```json ```json
{ {
"channels": { "channels": {

View file

@ -78,7 +78,7 @@ func runWeixinOnboard(baseURL, proxy string, timeout time.Duration) error {
fmt.Println("✓ Config updated. Start the gateway with:") fmt.Println("✓ Config updated. Start the gateway with:")
fmt.Println() fmt.Println()
fmt.Println(" picoclaw gateway start") fmt.Println(" picoclaw gateway")
fmt.Println() fmt.Println()
fmt.Println("To restrict which WeChat users can send messages, add their user IDs") fmt.Println("To restrict which WeChat users can send messages, add their user IDs")
fmt.Println("to channels.weixin.allow_from in your config.") fmt.Println("to channels.weixin.allow_from in your config.")

View file

@ -18,7 +18,7 @@ This command will:
After onboarding, you can start the gateway: After onboarding, you can start the gateway:
```bash ```bash
picoclaw gateway start picoclaw gateway
``` ```
--- ---

View file

@ -18,7 +18,7 @@ picoclaw onboard weixin
配置完成后,即可启动网关: 配置完成后,即可启动网关:
```bash ```bash
picoclaw gateway start picoclaw gateway
``` ```
--- ---

View file

@ -183,7 +183,7 @@ picoclaw onboard weixin
Scan the printed QR code with your WeChat mobile app. On success, the token is saved to your config. Scan the printed QR code with your WeChat mobile app. On success, the token is saved to your config.
**2. Configure** **2. Configure**
Optional) Update `allow_from` with your WeChat User ID to restrict who can message the bot: (Optional) Update `allow_from` with your WeChat User ID to restrict who can message the bot:
```json ```json
{ {
"channels": { "channels": {

View file

@ -32,10 +32,19 @@ func NewApiClient(baseURL, token string, proxy string) (*ApiClient, error) {
if proxy != "" { if proxy != "" {
proxyURL, err := url.Parse(proxy) proxyURL, err := url.Parse(proxy)
if err != nil { if err != nil {
return nil, fmt.Errorf("invalid proxy URL %q: %v", proxy, err) return nil, fmt.Errorf("invalid proxy URL %q: %w", proxy, err)
} }
client.Transport = &http.Transport{
Proxy: http.ProxyURL(proxyURL), // Clone the default transport so we preserve all default settings (TLS, HTTP/2, timeouts, keep-alives)
if defaultTransport, ok := http.DefaultTransport.(*http.Transport); ok {
transport := defaultTransport.Clone()
transport.Proxy = http.ProxyURL(proxyURL)
client.Transport = transport
} else {
// Fallback: preserve previous behavior if DefaultTransport is not the expected type
client.Transport = &http.Transport{
Proxy: http.ProxyURL(proxyURL),
}
} }
} }

View file

@ -292,7 +292,7 @@ func (c *WeixinChannel) Send(ctx context.Context, msg bus.OutboundMessage) error
logger.ErrorCF("weixin", "Missing context token, cannot send message", map[string]any{ logger.ErrorCF("weixin", "Missing context token, cannot send message", map[string]any{
"to_user_id": toUserID, "to_user_id": toUserID,
}) })
return fmt.Errorf("weixin send: missing context token for chat %s", toUserID) return fmt.Errorf("weixin send: %w: missing context token for chat %s", channels.ErrSendFailed, toUserID)
} }
clientID := "picoclaw-" + uuid.New().String() clientID := "picoclaw-" + uuid.New().String()