From cd224ffed2a4f5ae80d3a4e95c4fb5419649bf8f Mon Sep 17 00:00:00 2001 From: Juliusz Chroboczek Date: Wed, 30 Oct 2024 14:10:28 +0100 Subject: [PATCH] Add String method to group.Permissions. --- group/description.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/group/description.go b/group/description.go index 043c682..32c240f 100644 --- a/group/description.go +++ b/group/description.go @@ -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) @@ -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 != "" {