Working with import "google.golang.org/api/admin/directory/v1"

87 views
Skip to first unread message

John More

unread,
Aug 25, 2018, 11:20:09 PM8/25/18
to golang-nuts
I am using the "google.golang.org/api/admin/directory/v1" to access a G Suite account and everything seems to work EXCEPT:
The import defines a User structure that includes the following element among many others
Suspended bool `json:"suspended,omitempty"`

When set to false the json.Marshal treats this as an empty field which will not allow me to reactivate a user. 
Calling the API directly without using the library is not an option as I am using a service account which means I have to use a JWT and I really have no idea how to get the Bearer token.
Copying the user struct from the library generates a lot of compiler dependency errors

If anyone has run into this before.. workarounds or clues are appreciated

Thanks

silviu...@gmail.com

unread,
Aug 26, 2018, 9:17:42 AM8/26/18
to golang-nuts
Hi John

If you look at the source code, you will notice that the User struct they have makes use of a custom MarshallJSON method, which accepts ForceSendFields (as defined inside the User type)

So what you might need to do, is add that "Suspended" into that slice and it will marshall it to JSON


Silviu

John More

unread,
Aug 26, 2018, 10:05:38 AM8/26/18
to silviu...@gmail.com, golang-nuts
Silviu,
Thank You.
It was my birthday yesterday and I spent all day trying to follow the source code trail and you provided a great birthday present.
It worked as you advised and I am sure I will have many more occasions to use this.
One side effect of my day going through the library source code was increased go knowledge.

Thanks Again

John


--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Reply all
Reply to author
Forward
0 new messages