From 4714be0ac9ee8890017bfa8848efdc1ea84199c3 Mon Sep 17 00:00:00 2001 From: Elara 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() }