From f605a516c08839642762afae21c793be36659996 Mon Sep 17 00:00:00 2001 From: Syfaro Date: Fri, 31 Jul 2015 03:22:01 -0400 Subject: [PATCH] string function for user --- types.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/types.go b/types.go index ec72e85..aaa2bf1 100644 --- a/types.go +++ b/types.go @@ -26,6 +26,22 @@ type User struct { UserName string `json:"username"` } +// String displays a simple text version of a user. +// It is normally a user's username, +// but falls back to a first/last name as available. +func (u *User) String() string { + if u.UserName != "" { + return u.UserName + } + + name := u.FirstName + if u.LastName != "" { + name += " " + u.LastName + } + + return name +} + // GroupChat is a group chat, and not currently in use. type GroupChat struct { ID int `json:"id"`