In the Go SDK, it would be nice with a way to acce...
# help
In the Go SDK, it would be nice with a way to access the getters of the, for instance, underlying engine.Resource in client.Resource, so that you could do resource.GetId(). I'm trying to wrap IsAllowed in a dataloader which ultimately calls CheckResourceBatch; I'm combining it with gqlgen directives. Right now the underlying 'enginev1' struct methods is not exported, making it immutable (which is nice), but leaves instances of client.Resource, client.Principal etc. a black box. My current workaround is really ugly, improvement suggestions are very welcome 😅
Copy code
type IDWrapper[T any] struct{
	Inner T
	ID    string

type Key struct {
	Principal IDWrapper[*client.Principal]
	Resource  IDWrapper[*client.Resource]
	Action    string
Looks like a reasonable implementation to me. I have raised a PR to add methods to get the ID and some of the other useful fields from the builders. Thanks for reporting.
I ended up realizing I also needed the "kind", etc, so now I'm using enginev1.Principal for my arguments, and then converting them to client.Principal by hand when needed. And hey, insanely fast PR. Even before I could consider opening a PR myself 😄 once again great work from you guys, thanks!
(I also JSON encode it to generate a unique string key for dataloader)
I included
in the PR. You could get access to the underlying protobuf as well if you have other requirements.
What do you JSON encode? The kind?
Yeah I saw that you also did the Proto() method, which would be quite useful for me. I actually JSON Encode the entire proto struct, but I'll probably refactor to only do the ID and kind
Right, I see. I am sure you know this already: protobuf objects should be encoded using the
package. BUT, they intentionally add random spaces to the output so if you're using the output as a key, it might not work as you expect.
It might include a ton of weird protobuf fields too
interesting, didn't know about that one! I don't trust json encoding to be deterministic anyway, this is just a temporary quick'n'dirty for the proof of concept