fix: harden custom QR login output
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user