From ba705b25f7ab8da271333e4b24701ba3cc8ec6af Mon Sep 17 00:00:00 2001 From: Arsen Musayelyan Date: Sat, 10 Dec 2022 15:17:18 -0800 Subject: [PATCH] Fix setAuth() when field is of type Optional[string] --- lemmy.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lemmy.go b/lemmy.go index b2cc03f..a0eab58 100644 --- a/lemmy.go +++ b/lemmy.go @@ -153,7 +153,7 @@ func (c *Client) setAuth(data any) any { if data == nil { return data } - + val := reflect.New(reflect.TypeOf(data)) val.Elem().Set(reflect.ValueOf(data)) @@ -162,12 +162,16 @@ func (c *Client) setAuth(data any) any { return data } - authType := authField.Kind() - if authType != reflect.String { + switch authField.Type().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 } - authField.SetString(c.token) - return val.Elem().Interface() }