#Very much new to go. Have a somewhat confusing question about structs and objects.

12 messages · Page 1 of 1 (latest)

celest canopy
#

So, I have 2 structs below and I'm wondering how to return data from one in another where there's no specific/available point to return it from

type Workspace struct {
  Channels []string `json:"channel_ID"`

  Permissions []PermissionData `json:"available_permissions"`
}

type PermissionData struct {
    ID             int64  `json:"id,string"`
    Name           string `json:"name"`
    PermissionID   int64  `json:"permission_id,omitempty"`
    Moderated      bool   `json:"moderated"`
}

Data looks something like;
Channels returns several IDs such as [1 2 3 4]
Whereas Permissions returns data about the permissions [{1 Access 1 False} {1 Write 2 False} {3 Edit 7 True}]
To note. The channel_ID and id from each struct matches. So it's not random.

The data has to be structured this way.

Would it be possible to return the object data for PermissionData within the Channels at all?

wanton fiber
#

i am unsure what your last question means
what do you mean when it has to be structured this way?
for what exactly? just for json?
you can do whatever you want as long as you json marshaller method to turn it into whatever json format you want to comply with the api
(so it's totally possible for JSON marshal result and internal struct representation to differ, if that's preferred)

celest canopy
wanton fiber
#

so it means you have to accept the data in this format(specified by whatever cursed upstream you have no control over)
it does not mean you have to work with this specific format(your code can do whatever you want with that received data, including mutating the structure)

#

these are 2 things that shouldnt be confused

#

i am not saying you should or shouldnt, i want to establish this is indeed an option

celest canopy
#

Yeah, completely understand that

wanton fiber
#

how to return data from one in another
Would it be possible to return the object data for PermissionData within the Channels at all?
you cant put permission data inside a channel which is a string if i am understanding this correctly
but if you want you can just return 2 values, golang can do this, or create a struct which contains both values and return the struct instead

#

i hope i understood your questions correctly if that's what you mean by returning

celest canopy
#

In this case I'm using return as a synonym for retrieve so from a glance I believe so

wanton fiber
#

still do not follow

wispy fulcrum
#

Also don't really understand what you're asking