Skip to content

Commit

Permalink
Add String method to group.Permissions.
Browse files Browse the repository at this point in the history
  • Loading branch information
jech committed Oct 30, 2024
1 parent f0b26c6 commit cd224ff
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion group/description.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,20 @@ func (p Permissions) Permissions(desc *Description) []string {
return perms
}

func (p Permissions) String() string {
if p.name != "" {
if p.permissions != nil {
return fmt.Sprintf("(ERROR=overconstrained %v)", p.name)
}
return p.name
}
v, err := json.Marshal(p)
if err == nil {
return fmt.Sprintf("(ERROR=%v)", err)
}
return string(v)
}

func (p *Permissions) UnmarshalJSON(b []byte) error {
var a []string
err := json.Unmarshal(b, &a)
Expand Down Expand Up @@ -119,7 +133,7 @@ type UserDescription struct {
Permissions Permissions `json:"permissions"`
}

// Custom MarshalJSON in order to omit ompty fields
// Custom MarshalJSON in order to omit empty fields
func (u UserDescription) MarshalJSON() ([]byte, error) {
uu := make(map[string]any, 2)
if u.Password.Type != "" {
Expand Down

0 comments on commit cd224ff

Please sign in to comment.