Skip to content

Instantly share code, notes, and snippets.

@suzuki-shunsuke
Created May 1, 2018 12:58
package users
import (
"encoding/json"
)
// UserProfile contains all the information details of a given user
type UserProfile struct {
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
RealName string `json:"real_name"`
RealNameNormalized string `json:"real_name_normalized"`
DisplayName string `json:"display_name"`
DisplayNameNormalized string `json:"display_name_normalized"`
Email string `json:"email"`
Skype string `json:"skype"`
Phone string `json:"phone"`
Image24 string `json:"image_24"`
Image32 string `json:"image_32"`
Image48 string `json:"image_48"`
Image72 string `json:"image_72"`
Image192 string `json:"image_192"`
ImageOriginal string `json:"image_original"`
Title string `json:"title"`
BotID string `json:"bot_id,omitempty"`
ApiAppID string `json:"api_app_id,omitempty"`
StatusText string `json:"status_text,omitempty"`
StatusEmoji string `json:"status_emoji,omitempty"`
Team string `json:"team"`
Fields *UserProfileCustomFields `json:"fields"`
}
type UserProfileCustomFields struct {
fields map[string]UserProfileCustomField
}
func (fields *UserProfileCustomFields) UnmarshalJSON(b []byte) error {
if string(b) == "[]" {
return nil
}
if fields.fields == nil {
fields.fields = map[string]UserProfileCustomField{}
}
return json.Unmarshal(b, &fields.fields)
}
func (fields *UserProfileCustomFields) ToMap() map[string]UserProfileCustomField {
return fields.fields
}
func (profile *UserProfile) FieldsMap() map[string]UserProfileCustomField {
return profile.Fields.ToMap()
}
// UserProfileCustomField represents a custom user profile field
type UserProfileCustomField struct {
Value string `json:"value"`
Alt string `json:"alt"`
Label string `json:"label"`
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment