fix: harden custom QR login output

This commit is contained in:
2026-07-20 11:20:39 +08:00
parent 88df3149be
commit 74486ebf08
3 changed files with 66 additions and 13 deletions
+10 -1
View File
@@ -10,6 +10,7 @@ import (
"net/url"
"os"
"path/filepath"
"reflect"
"strconv"
"strings"
"sync"
@@ -39,7 +40,15 @@ func WithHTTPClient(httpClient *http.Client) Option {
// WithQRWriter configures where QR login output is written.
func WithQRWriter(writer io.Writer) Option {
return func(client *Client) error {
if writer == nil {
isNil := writer == nil
if !isNil {
value := reflect.ValueOf(writer)
switch value.Kind() {
case reflect.Chan, reflect.Func, reflect.Interface, reflect.Map, reflect.Ptr, reflect.Slice:
isNil = value.IsNil()
}
}
if isNil {
return fmt.Errorf("QR writer must not be nil")
}
client.qrWriter = writer