File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package brood
22
3+ import (
4+ "encoding/json"
5+ )
6+
37type User struct {
48 Id string `json:"id"`
59 Username string `json:"username"`
@@ -83,11 +87,37 @@ type resourceUpdateRequest struct {
8387}
8488
8589type ResourceHolder struct {
86- Id string `json:"id "`
90+ Id string `json:"holder_id "`
8791 HolderType string `json:"holder_type"`
8892 Permissions []string `json:"permissions"`
8993}
9094
95+ func (r * ResourceHolder ) UnmarshalJSON (data []byte ) error {
96+ // Define an alias to avoid recursion in custom unmarshaling
97+ type Alias ResourceHolder
98+ aux := & struct {
99+ Id string `json:"id"`
100+ HolderId string `json:"holder_id"`
101+ * Alias
102+ }{
103+ Alias : (* Alias )(r ),
104+ }
105+
106+ // Unmarshal into the auxiliary struct
107+ if err := json .Unmarshal (data , & aux ); err != nil {
108+ return err
109+ }
110+
111+ // Populate the Id field based on available data
112+ if aux .Id != "" {
113+ r .Id = aux .Id
114+ } else {
115+ r .Id = aux .HolderId
116+ }
117+
118+ return nil
119+ }
120+
91121type ResourceHolders struct {
92122 ResourceId string `json:"resource_id"`
93123 Holders []ResourceHolder `json:"holders"`
Original file line number Diff line number Diff line change 11package bugout
22
3- const Version string = "0.4.5 "
3+ const Version string = "0.4.6 "
You can’t perform that action at this time.
0 commit comments