Fix setAuth() when field is of type Optional[string]
This commit is contained in:
parent
fa357b4bff
commit
4714be0ac9
14
lemmy.go
14
lemmy.go
@ -153,7 +153,7 @@ func (c *Client) setAuth(data any) any {
|
|||||||
if data == nil {
|
if data == nil {
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
val := reflect.New(reflect.TypeOf(data))
|
val := reflect.New(reflect.TypeOf(data))
|
||||||
val.Elem().Set(reflect.ValueOf(data))
|
val.Elem().Set(reflect.ValueOf(data))
|
||||||
|
|
||||||
@ -162,12 +162,16 @@ func (c *Client) setAuth(data any) any {
|
|||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
authType := authField.Kind()
|
switch authField.Type().String() {
|
||||||
if authType != reflect.String {
|
case "string":
|
||||||
|
authField.SetString(c.token)
|
||||||
|
case "types.Optional[string]":
|
||||||
|
setMtd := authField.MethodByName("Set")
|
||||||
|
out := setMtd.Call([]reflect.Value{reflect.ValueOf(c.token)})
|
||||||
|
authField.Set(out[0])
|
||||||
|
default:
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
authField.SetString(c.token)
|
|
||||||
|
|
||||||
return val.Elem().Interface()
|
return val.Elem().Interface()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user