Skip to content
This repository was archived by the owner on Feb 3, 2026. It is now read-only.

Commit a5b6143

Browse files
authored
feat: Implement the fmt.Stringer interface for User, Group, and Mapping structs (#167)
This will make it easier to have more human friendly identifiers in logs. Signed-off-by: James Alseth <jalseth@google.com>
1 parent c5d5a68 commit a5b6143

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

pkg/groupsync/groups.go

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,21 @@ type OneToOneGroupMapper interface {
7979

8080
// Mapping is a group ID with the group system and other combinable metadata.
8181
type Mapping struct {
82-
GroupID string `json:"group_id,omitempty"`
82+
GroupID string `json:"group_id,omitempty"`
83+
DisplayName string `json:"display_name,omitempty"`
8384
// The system where the Group comes from.
8485
System string `json:"system,omitempty"`
8586
Metadata MappingMetadata `json:"metadata,omitempty"`
8687
}
8788

89+
func (m Mapping) String() string {
90+
s := m.System + "/" + m.GroupID
91+
if m.DisplayName != "" {
92+
s += " (" + m.DisplayName + ")"
93+
}
94+
return s
95+
}
96+
8897
// MappingMetadata is arbitrary data that is combinable with other metadata,
8998
// allowing user-specific data to be calculated based on metadata from
9099
// multiple source groups mapping a user to a single target group.
@@ -125,6 +134,8 @@ func (m *noopUserMapper) MappedUser(ctx context.Context, user *User) (*User, err
125134
type User struct {
126135
// ID is the user's ID in the group system.
127136
ID string `json:"id,omitempty"`
137+
// DisplayName is the human friendly name for the user.
138+
DisplayName string `json:"display_name,omitempty"`
128139
// System is where the user comes from.
129140
System string `json:"system,omitempty"`
130141
// Attributes represent arbitrary attributes about the user
@@ -136,16 +147,34 @@ type User struct {
136147
Metadata MappingMetadata `json:"metadata,omitempty"`
137148
}
138149

150+
func (u User) String() string {
151+
s := u.System + "/" + u.ID
152+
if u.DisplayName != "" {
153+
s += " (" + u.DisplayName + ")"
154+
}
155+
return s
156+
}
157+
139158
// Group represents a group in a group system.
140159
type Group struct {
141160
// ID is the group's ID in the group system.
142161
ID string `json:"id,omitempty"`
162+
// DisplayName is the human friendly name for the group.
163+
DisplayName string `json:"display_name,omitempty"`
143164
// Attributes represent arbitrary attributes about the group
144165
// in the given group system. This field is typically set by
145166
// the corresponding GroupReader when retrieving the group.
146167
Attributes any `json:"attributes,omitempty"`
147168
}
148169

170+
func (g Group) String() string {
171+
s := g.ID
172+
if g.DisplayName != "" {
173+
s += " (" + g.DisplayName + ")"
174+
}
175+
return s
176+
}
177+
149178
// Member represents a member of a group. A member may either be
150179
// a User or another Group. An instance of Member will always be
151180
// either a User or a Group but not both.

0 commit comments

Comments
 (0)