Skip to content

Commit bbb32d6

Browse files
authored
Merge pull request #22 from bugout-dev/fix-holder-id-both
Support both cases for resource holder id
2 parents 01f060d + ed916e4 commit bbb32d6

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

pkg/brood/data.go

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package brood
22

3+
import (
4+
"encoding/json"
5+
)
6+
37
type User struct {
48
Id string `json:"id"`
59
Username string `json:"username"`
@@ -83,11 +87,37 @@ type resourceUpdateRequest struct {
8387
}
8488

8589
type 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+
91121
type ResourceHolders struct {
92122
ResourceId string `json:"resource_id"`
93123
Holders []ResourceHolder `json:"holders"`

pkg/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
package bugout
22

3-
const Version string = "0.4.5"
3+
const Version string = "0.4.6"

0 commit comments

Comments
 (0)