From 37def48be04bb087ceb0dc03fedf5545fc320fee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20=C3=98en=20Fylling?= Date: Wed, 28 Oct 2020 20:04:29 +0100 Subject: [PATCH] unexport DeepCopy and CopyOverTo methods, introduce procedural option --- auditlog.go | 54 ++++++++++++------------- cache.go | 52 ++++++++++++------------ channel.go | 15 ++++--- channel_test.go | 2 +- disgord.go | 22 +++++++++++ embed.go | 102 ++++++++++++++++++++++-------------------------- emoji.go | 13 +++--- guild.go | 86 +++++++++++++++++++--------------------- invite.go | 24 ++++++------ message.go | 23 ++++++----- reaction.go | 13 +++--- role.go | 11 +++--- std/utils.go | 10 ++--- struct.go | 13 ------ user.go | 102 ++++++++++++++++++++++-------------------------- voice.go | 22 +++++------ webhook.go | 13 +++--- 17 files changed, 275 insertions(+), 302 deletions(-) diff --git a/auditlog.go b/auditlog.go index d4128498..22c239a3 100644 --- a/auditlog.go +++ b/auditlog.go @@ -119,15 +119,14 @@ func (l *AuditLog) Bans() (bans []*PartialBan) { } // DeepCopy see interface at struct.go#DeepCopier -func (l *AuditLog) DeepCopy() (copy interface{}) { - copy = &AuditLog{} - l.CopyOverTo(copy) - - return +func (l *AuditLog) deepCopy() interface{} { + cp := &AuditLog{} + _ = DeepCopyOver(cp, l) + return cp } // CopyOverTo see interface at struct.go#Copier -func (l *AuditLog) CopyOverTo(other interface{}) (err error) { +func (l *AuditLog) copyOverTo(other interface{}) (err error) { var ok bool var log *AuditLog if log, ok = other.(*AuditLog); !ok { @@ -136,13 +135,13 @@ func (l *AuditLog) CopyOverTo(other interface{}) (err error) { } for _, webhook := range l.Webhooks { - log.Webhooks = append(log.Webhooks, webhook.DeepCopy().(*Webhook)) + log.Webhooks = append(log.Webhooks, DeepCopy(webhook).(*Webhook)) } for _, user := range l.Users { - log.Users = append(log.Users, user.DeepCopy().(*User)) + log.Users = append(log.Users, DeepCopy(user).(*User)) } for _, entry := range l.AuditLogEntries { - log.AuditLogEntries = append(log.AuditLogEntries, entry.DeepCopy().(*AuditLogEntry)) + log.AuditLogEntries = append(log.AuditLogEntries, DeepCopy(entry).(*AuditLogEntry)) } return } @@ -159,15 +158,14 @@ type AuditLogEntry struct { } // DeepCopy see interface at struct.go#DeepCopier -func (l *AuditLogEntry) DeepCopy() (copy interface{}) { - copy = &AuditLogEntry{} - l.CopyOverTo(copy) - - return +func (l *AuditLogEntry) deepCopy() interface{} { + cp := &AuditLogEntry{} + _ = DeepCopyOver(cp, l) + return cp } // CopyOverTo see interface at struct.go#Copier -func (l *AuditLogEntry) CopyOverTo(other interface{}) (err error) { +func (l *AuditLogEntry) copyOverTo(other interface{}) (err error) { var ok bool var log *AuditLogEntry if log, ok = other.(*AuditLogEntry); !ok { @@ -182,11 +180,11 @@ func (l *AuditLogEntry) CopyOverTo(other interface{}) (err error) { log.Reason = l.Reason for _, change := range l.Changes { - log.Changes = append(log.Changes, change.DeepCopy().(*AuditLogChanges)) + log.Changes = append(log.Changes, DeepCopy(change).(*AuditLogChanges)) } if l.Options != nil { - log.Options = l.Options.DeepCopy().(*AuditLogOption) + log.Options = DeepCopy(l.Options).(*AuditLogOption) } return } @@ -203,15 +201,14 @@ type AuditLogOption struct { } // DeepCopy see interface at struct.go#DeepCopier -func (l *AuditLogOption) DeepCopy() (copy interface{}) { - copy = &AuditLogOption{} - l.CopyOverTo(copy) - - return +func (l *AuditLogOption) deepCopy() interface{} { + cp := &AuditLogOption{} + _ = DeepCopyOver(cp, l) + return cp } // CopyOverTo see interface at struct.go#Copier -func (l *AuditLogOption) CopyOverTo(other interface{}) (err error) { +func (l *AuditLogOption) copyOverTo(other interface{}) (err error) { var ok bool var log *AuditLogOption if log, ok = other.(*AuditLogOption); !ok { @@ -237,15 +234,14 @@ type AuditLogChanges struct { } // DeepCopy see interface at struct.go#DeepCopier -func (l *AuditLogChanges) DeepCopy() (copy interface{}) { - copy = &AuditLogChanges{} - l.CopyOverTo(copy) - - return +func (l *AuditLogChanges) deepCopy() interface{} { + cp := &AuditLogChanges{} + _ = DeepCopyOver(cp, l) + return cp } // CopyOverTo see interface at struct.go#Copier -func (l *AuditLogChanges) CopyOverTo(other interface{}) (err error) { +func (l *AuditLogChanges) copyOverTo(other interface{}) (err error) { var ok bool var log *AuditLogChanges if log, ok = other.(*AuditLogChanges); !ok { diff --git a/cache.go b/cache.go index c6dc8b11..ba6f5966 100644 --- a/cache.go +++ b/cache.go @@ -68,8 +68,8 @@ func (c *CacheLFUImmutable) createDMChannel(msg *Message) { channel := &Channel{ ID: channelID, Recipients: []*User{ - c.CurrentUser.DeepCopy().(*User), - msg.Author.DeepCopy().(*User), + DeepCopy(c.CurrentUser).(*User), + DeepCopy(msg.Author).(*User), }, LastMessageID: msg.ID, Type: ChannelTypeDM, @@ -104,7 +104,7 @@ func (c *CacheLFUImmutable) Ready(data []byte) (*Ready, error) { } err := json.Unmarshal(data, rdy) - rdy.User = c.CurrentUser.DeepCopy().(*User) + rdy.User = DeepCopy(c.CurrentUser).(*User) c.Patch(rdy) return rdy, err } @@ -129,7 +129,7 @@ func (c *CacheLFUImmutable) ChannelCreate(data []byte) (*ChannelCreate, error) { // assumption#3: a channel can not change from one type to another (text => news, text => voice) wrap := func(c *Channel) *ChannelCreate { - return &ChannelCreate{Channel: c.DeepCopy().(*Channel)} + return &ChannelCreate{Channel: DeepCopy(c).(*Channel)} } channel := &Channel{} @@ -170,7 +170,7 @@ func (c *CacheLFUImmutable) ChannelUpdate(data []byte) (*ChannelUpdate, error) { } c.Patch(channel) - channel = channel.DeepCopy().(*Channel) + channel = DeepCopy(channel).(*Channel) return channel, nil } @@ -197,7 +197,7 @@ func (c *CacheLFUImmutable) ChannelUpdate(data []byte) (*ChannelUpdate, error) { return nil, err } c.Patch(tmp) - channel = tmp.DeepCopy().(*Channel) + channel = DeepCopy(tmp).(*Channel) freshItem := c.Channels.CreateCacheableItem(tmp) c.Channels.Lock() @@ -280,7 +280,7 @@ func (c *CacheLFUImmutable) UserUpdate(data []byte) (*UserUpdate, error) { return nil, err } - update.User = c.CurrentUser.DeepCopy().(*User) + update.User = DeepCopy(c.CurrentUser).(*User) c.Patch(update) return update, nil @@ -340,15 +340,15 @@ func (c *CacheLFUImmutable) GuildMemberAdd(data []byte) (*GuildMemberAdd, error) // TODO: i assume the user is partial and doesn't hold any real updates usr := cachedUser.Val.(*User) // if err := json.Unmarshal(data, &Member{User:usr}); err == nil { - // gmr.Member.User = usr.DeepCopy().(*User) + // gmr.Member.User = DeepCopy(usr).(*User) // } - gmr.Member.User = usr.DeepCopy().(*User) + gmr.Member.User = DeepCopy(usr).(*User) } else { c.Users.Lock() defer c.Users.Unlock() if _, exists := c.Users.Get(userID); !exists { - usr := c.Users.CreateCacheableItem(gmr.Member.User.DeepCopy().(*User)) + usr := c.Users.CreateCacheableItem(DeepCopy(gmr.Member.User).(*User)) c.Users.Set(userID, usr) } } @@ -376,7 +376,7 @@ func (c *CacheLFUImmutable) GuildMemberAdd(data []byte) (*GuildMemberAdd, error) } } if member == nil { - member = gmr.Member.DeepCopy().(*Member) + member = DeepCopy(gmr.Member).(*Member) guild.Members = append(guild.Members, member) guild.MemberCount++ @@ -412,7 +412,7 @@ func (c *CacheLFUImmutable) GuildCreate(data []byte) (*GuildCreate, error) { guild.Unavailable = false c.Patch(guild) - guild = guild.DeepCopy().(*Guild) + guild = DeepCopy(guild).(*Guild) } else if exists { // not pre-loaded from ready event if err := json.Unmarshal(data, &guild); err != nil { @@ -427,7 +427,7 @@ func (c *CacheLFUImmutable) GuildCreate(data []byte) (*GuildCreate, error) { c.Patch(guild) e := c.Guilds.CreateCacheableItem(guild) - guild = guild.DeepCopy().(*Guild) + guild = DeepCopy(guild).(*Guild) c.Guilds.Lock() if _, exists := c.Guilds.Get(guildID); !exists { @@ -454,7 +454,7 @@ func (c *CacheLFUImmutable) GuildUpdate(data []byte) (*GuildUpdate, error) { } c.Patch(guild) - return guild.DeepCopy().(*Guild), nil + return DeepCopy(guild).(*Guild), nil } var metadata *idHolder @@ -484,7 +484,7 @@ func (c *CacheLFUImmutable) GuildUpdate(data []byte) (*GuildUpdate, error) { guild, err = updateGuild(guildID, oldItem) // fallback } else { c.Guilds.Set(guildID, e) - guild = guild.DeepCopy().(*Guild) + guild = DeepCopy(guild).(*Guild) } } @@ -529,7 +529,7 @@ func (c *CacheLFUImmutable) GetChannel(id Snowflake) (*Channel, error) { defer mutex.Unlock() channel := cachedItem.Val.(*Channel) - return channel.DeepCopy().(*Channel), nil + return DeepCopy(channel).(*Channel), nil } return nil, nil } @@ -545,7 +545,7 @@ func (c *CacheLFUImmutable) GetGuildEmoji(guildID, emojiID Snowflake) (*Emoji, e guild := cachedItem.Val.(*Guild) emoji, _ := guild.Emoji(emojiID) - return emoji.DeepCopy().(*Emoji), nil + return DeepCopy(emoji).(*Emoji), nil } return nil, errors.New("guild does not exist") } @@ -562,7 +562,7 @@ func (c *CacheLFUImmutable) GetGuildEmojis(id Snowflake) ([]*Emoji, error) { guild := cachedItem.Val.(*Guild) emojis := make([]*Emoji, len(guild.Emojis)) for i, emoji := range emojis { - emojis[i] = emoji.DeepCopy().(*Emoji) + emojis[i] = DeepCopy(emoji).(*Emoji) } return emojis, nil @@ -580,7 +580,7 @@ func (c *CacheLFUImmutable) GetGuild(id Snowflake) (*Guild, error) { mutex.Lock() defer mutex.Unlock() - guild = cachedItem.Val.(*Guild).DeepCopy().(*Guild) + guild = DeepCopy(cachedItem.Val.(*Guild)).(*Guild) } return guild, nil @@ -599,7 +599,7 @@ func (c *CacheLFUImmutable) GetGuildChannels(id Snowflake) ([]*Channel, error) { channels := make([]*Channel, len(guild.Channels)) for i, channel := range guild.Channels { - channels[i] = channel.DeepCopy().(*Channel) + channels[i] = DeepCopy(channel).(*Channel) } return channels, nil @@ -620,7 +620,7 @@ func (c *CacheLFUImmutable) GetMember(guildID, userID Snowflake) (*Member, error if user != nil { mutex := c.Mutex(&c.Users, userID) mutex.Lock() - user = user.DeepCopy().(*User) + user = DeepCopy(user).(*User) mutex.Unlock() } wg.Done() @@ -637,7 +637,7 @@ func (c *CacheLFUImmutable) GetMember(guildID, userID Snowflake) (*Member, error guild := cachedItem.Val.(*Guild) member, _ = guild.Member(userID) if member != nil { - member = member.DeepCopy().(*Member) + member = DeepCopy(member).(*Member) } mutex.Unlock() @@ -665,7 +665,7 @@ func (c *CacheLFUImmutable) GetGuildRoles(guildID Snowflake) ([]*Role, error) { guild := cachedItem.Val.(*Guild) roles := make([]*Role, len(guild.Roles)) for i, role := range guild.Roles { - roles[i] = role.DeepCopy().(*Role) + roles[i] = DeepCopy(role).(*Role) } return roles, nil @@ -676,7 +676,7 @@ func (c *CacheLFUImmutable) GetCurrentUser() (*User, error) { c.CurrentUserMu.Lock() defer c.CurrentUserMu.Unlock() - return c.CurrentUser.DeepCopy().(*User), nil + return DeepCopy(c.CurrentUser).(*User), nil } func (c *CacheLFUImmutable) GetUser(id Snowflake) (*User, error) { currentUser := func() *User { @@ -690,7 +690,7 @@ func (c *CacheLFUImmutable) GetUser(id Snowflake) (*User, error) { } // hmmm.. ugly if match := currentUser(); match != nil { - return match.DeepCopy().(*User), nil + return DeepCopy(match).(*User), nil } c.Users.RLock() @@ -703,7 +703,7 @@ func (c *CacheLFUImmutable) GetUser(id Snowflake) (*User, error) { mutex.Lock() defer mutex.Unlock() - user = item.Val.(*User).DeepCopy().(*User) + user = DeepCopy(item.Val.(*User)).(*User) } return user, nil diff --git a/channel.go b/channel.go index a67ba499..3f6784a6 100644 --- a/channel.go +++ b/channel.go @@ -54,7 +54,7 @@ func (a *Attachment) updateInternals() { } // DeepCopy see interface at struct.go#DeepCopier -func (a *Attachment) DeepCopy() (copy interface{}) { +func (a *Attachment) deepCopy() (copy interface{}) { copy = &Attachment{ ID: a.ID, Filename: a.Filename, @@ -201,15 +201,14 @@ func (c *Channel) Compare(other *Channel) bool { } // DeepCopy see interface at struct.go#DeepCopier -func (c *Channel) DeepCopy() (copy interface{}) { - copy = &Channel{} - _ = c.CopyOverTo(copy) - - return +func (c *Channel) deepCopy() interface{} { + cp := &Channel{} + _ = DeepCopyOver(cp, c) + return cp } // CopyOverTo see interface at struct.go#Copier -func (c *Channel) CopyOverTo(other interface{}) (err error) { +func (c *Channel) copyOverTo(other interface{}) (err error) { var channel *Channel var valid bool if channel, valid = other.(*Channel); !valid { @@ -239,7 +238,7 @@ func (c *Channel) CopyOverTo(other interface{}) (err error) { // add recipients if it's a DM channel.Recipients = make([]*User, 0, len(c.Recipients)) for _, recipient := range c.Recipients { - channel.Recipients = append(channel.Recipients, recipient.DeepCopy().(*User)) + channel.Recipients = append(channel.Recipients, DeepCopy(recipient).(*User)) } return diff --git a/channel_test.go b/channel_test.go index 4bef5e95..3ef095f5 100644 --- a/channel_test.go +++ b/channel_test.go @@ -19,7 +19,7 @@ func TestChannel_DeepCopy(t *testing.T) { Type: 1, }) - cp := test.DeepCopy().(*Channel) + cp := DeepCopy(test).(*Channel) icon2 := "sfkjdsf" test.Icon = icon2 if cp.Icon != icon1 { diff --git a/disgord.go b/disgord.go index 824fe2f9..f231da89 100644 --- a/disgord.go +++ b/disgord.go @@ -138,6 +138,28 @@ func LibraryInfo() string { return fmt.Sprintf("%s %s", constant.Name, constant.Version) } +// DeepCopier holds the DeepCopy method which creates and returns a deep copy of +// any struct. +type DeepCopier interface { + deepCopy() interface{} +} + +func DeepCopy(cp DeepCopier) interface{} { + return cp.deepCopy() +} + +// Copier holds the CopyOverTo method which copies all it's content from one +// struct to another. Note that this requires a deep copy. +// useful when overwriting already existing content in the cacheLink to reduce GC. +type Copier interface { + copyOverTo(other interface{}) error +} + +func DeepCopyOver(dst Copier, src Copier) error { + // TODO: make sure dst and src are of the same type! + return src.copyOverTo(dst) +} + // Wrapper for github.com/andersfylling/snowflake // ------------------ diff --git a/embed.go b/embed.go index 2171fdf0..cfb96dfd 100644 --- a/embed.go +++ b/embed.go @@ -21,15 +21,14 @@ type Embed struct { } // DeepCopy see interface at struct.go#DeepCopier -func (c *Embed) DeepCopy() (copy interface{}) { - copy = &Embed{} - c.CopyOverTo(copy) - - return +func (c *Embed) deepCopy() interface{} { + cp := &Embed{} + _ = DeepCopyOver(cp, c) + return cp } // CopyOverTo see interface at struct.go#Copier -func (c *Embed) CopyOverTo(other interface{}) (err error) { +func (c *Embed) copyOverTo(other interface{}) (err error) { var embed *Embed var valid bool if embed, valid = other.(*Embed); !valid { @@ -45,27 +44,27 @@ func (c *Embed) CopyOverTo(other interface{}) (err error) { embed.Color = c.Color if c.Footer != nil { - embed.Footer = c.Footer.DeepCopy().(*EmbedFooter) + embed.Footer = DeepCopy(c.Footer).(*EmbedFooter) } if c.Image != nil { - embed.Image = c.Image.DeepCopy().(*EmbedImage) + embed.Image = DeepCopy(c.Image).(*EmbedImage) } if c.Thumbnail != nil { - embed.Thumbnail = c.Thumbnail.DeepCopy().(*EmbedThumbnail) + embed.Thumbnail = DeepCopy(c.Thumbnail).(*EmbedThumbnail) } if c.Video != nil { - embed.Video = c.Video.DeepCopy().(*EmbedVideo) + embed.Video = DeepCopy(c.Video).(*EmbedVideo) } if c.Provider != nil { - embed.Provider = c.Provider.DeepCopy().(*EmbedProvider) + embed.Provider = DeepCopy(c.Provider).(*EmbedProvider) } if c.Author != nil { - embed.Author = c.Author.DeepCopy().(*EmbedAuthor) + embed.Author = DeepCopy(c.Author).(*EmbedAuthor) } embed.Fields = make([]*EmbedField, len(c.Fields)) for i, field := range c.Fields { - embed.Fields[i] = field.DeepCopy().(*EmbedField) + embed.Fields[i] = DeepCopy(field).(*EmbedField) } return nil } @@ -79,15 +78,14 @@ type EmbedThumbnail struct { } // DeepCopy see interface at struct.go#DeepCopier -func (c *EmbedThumbnail) DeepCopy() (copy interface{}) { - copy = &EmbedThumbnail{} - c.CopyOverTo(copy) - - return +func (c *EmbedThumbnail) deepCopy() interface{} { + cp := &EmbedThumbnail{} + _ = DeepCopyOver(cp, c) + return cp } // CopyOverTo see interface at struct.go#Copier -func (c *EmbedThumbnail) CopyOverTo(other interface{}) (err error) { +func (c *EmbedThumbnail) copyOverTo(other interface{}) (err error) { var embed *EmbedThumbnail var valid bool if embed, valid = other.(*EmbedThumbnail); !valid { @@ -110,15 +108,14 @@ type EmbedVideo struct { } // DeepCopy see interface at struct.go#DeepCopier -func (c *EmbedVideo) DeepCopy() (copy interface{}) { - copy = &EmbedVideo{} - c.CopyOverTo(copy) - - return +func (c *EmbedVideo) deepCopy() interface{} { + cp := &EmbedVideo{} + _ = DeepCopyOver(cp, c) + return cp } // CopyOverTo see interface at struct.go#Copier -func (c *EmbedVideo) CopyOverTo(other interface{}) (err error) { +func (c *EmbedVideo) copyOverTo(other interface{}) (err error) { var embed *EmbedVideo var valid bool if embed, valid = other.(*EmbedVideo); !valid { @@ -141,15 +138,14 @@ type EmbedImage struct { } // DeepCopy see interface at struct.go#DeepCopier -func (c *EmbedImage) DeepCopy() (copy interface{}) { - copy = &EmbedImage{} - c.CopyOverTo(copy) - - return +func (c *EmbedImage) deepCopy() interface{} { + cp := &EmbedImage{} + _ = DeepCopyOver(cp, c) + return cp } // CopyOverTo see interface at struct.go#Copier -func (c *EmbedImage) CopyOverTo(other interface{}) (err error) { +func (c *EmbedImage) copyOverTo(other interface{}) (err error) { var embed *EmbedImage var valid bool if embed, valid = other.(*EmbedImage); !valid { @@ -171,15 +167,14 @@ type EmbedProvider struct { } // DeepCopy see interface at struct.go#DeepCopier -func (c *EmbedProvider) DeepCopy() (copy interface{}) { - copy = &EmbedProvider{} - c.CopyOverTo(copy) - - return +func (c *EmbedProvider) deepCopy() interface{} { + cp := &EmbedProvider{} + _ = DeepCopyOver(cp, c) + return cp } // CopyOverTo see interface at struct.go#Copier -func (c *EmbedProvider) CopyOverTo(other interface{}) (err error) { +func (c *EmbedProvider) copyOverTo(other interface{}) (err error) { var embed *EmbedProvider var valid bool if embed, valid = other.(*EmbedProvider); !valid { @@ -201,15 +196,14 @@ type EmbedAuthor struct { } // DeepCopy see interface at struct.go#DeepCopier -func (c *EmbedAuthor) DeepCopy() (copy interface{}) { - copy = &EmbedAuthor{} - c.CopyOverTo(copy) - - return +func (c *EmbedAuthor) deepCopy() interface{} { + cp := &EmbedAuthor{} + _ = DeepCopyOver(cp, c) + return cp } // CopyOverTo see interface at struct.go#Copier -func (c *EmbedAuthor) CopyOverTo(other interface{}) (err error) { +func (c *EmbedAuthor) copyOverTo(other interface{}) (err error) { var embed *EmbedAuthor var valid bool if embed, valid = other.(*EmbedAuthor); !valid { @@ -232,15 +226,14 @@ type EmbedFooter struct { } // DeepCopy see interface at struct.go#DeepCopier -func (c *EmbedFooter) DeepCopy() (copy interface{}) { - copy = &EmbedFooter{} - c.CopyOverTo(copy) - - return +func (c *EmbedFooter) deepCopy() interface{} { + cp := &EmbedFooter{} + _ = DeepCopyOver(cp, c) + return cp } // CopyOverTo see interface at struct.go#Copier -func (c *EmbedFooter) CopyOverTo(other interface{}) (err error) { +func (c *EmbedFooter) copyOverTo(other interface{}) (err error) { var embed *EmbedFooter var valid bool if embed, valid = other.(*EmbedFooter); !valid { @@ -262,15 +255,14 @@ type EmbedField struct { } // DeepCopy see interface at struct.go#DeepCopier -func (c *EmbedField) DeepCopy() (copy interface{}) { - copy = &EmbedField{} - c.CopyOverTo(copy) - - return +func (c *EmbedField) deepCopy() interface{} { + cp := &EmbedField{} + _ = DeepCopyOver(cp, c) + return cp } // CopyOverTo see interface at struct.go#Copier -func (c *EmbedField) CopyOverTo(other interface{}) (err error) { +func (c *EmbedField) copyOverTo(other interface{}) (err error) { var embed *EmbedField var valid bool if embed, valid = other.(*EmbedField); !valid { diff --git a/emoji.go b/emoji.go index 12593d14..88d1de6f 100644 --- a/emoji.go +++ b/emoji.go @@ -55,15 +55,14 @@ func (e *Emoji) Mention() string { } // DeepCopy see interface at struct.go#DeepCopier -func (e *Emoji) DeepCopy() (copy interface{}) { - copy = &Emoji{} - e.CopyOverTo(copy) - - return +func (e *Emoji) deepCopy() interface{} { + cp := &Emoji{} + _ = DeepCopyOver(cp, e) + return cp } // CopyOverTo see interface at struct.go#Copier -func (e *Emoji) CopyOverTo(other interface{}) (err error) { +func (e *Emoji) copyOverTo(other interface{}) (err error) { var emoji *Emoji var ok bool if emoji, ok = other.(*Emoji); !ok { @@ -79,7 +78,7 @@ func (e *Emoji) CopyOverTo(other interface{}) (err error) { emoji.Animated = e.Animated if e.User != nil { - emoji.User = e.User.DeepCopy().(*User) + emoji.User = DeepCopy(e.User).(*User) } return } diff --git a/guild.go b/guild.go index 9c1dc35b..cb7d58c5 100644 --- a/guild.go +++ b/guild.go @@ -428,15 +428,14 @@ func (g *Guild) Emoji(id Snowflake) (emoji *Emoji, err error) { } // DeepCopy see interface at struct.go#DeepCopier -func (g *Guild) DeepCopy() (copy interface{}) { - copy = &Guild{} - _ = g.CopyOverTo(copy) - - return +func (g *Guild) deepCopy() interface{} { + cp := &Guild{} + _ = DeepCopyOver(cp, g) + return cp } // CopyOverTo see interface at struct.go#Copier -func (g *Guild) CopyOverTo(other interface{}) (err error) { +func (g *Guild) copyOverTo(other interface{}) (err error) { var guild *Guild var valid bool if guild, valid = other.(*Guild); !valid { @@ -484,38 +483,38 @@ func (g *Guild) CopyOverTo(other interface{}) (err error) { if roleP == nil { continue } - guild.Roles = append(guild.Roles, roleP.DeepCopy().(*Role)) + guild.Roles = append(guild.Roles, DeepCopy(roleP).(*Role)) } for _, emojiP := range g.Emojis { if emojiP == nil { continue } - guild.Emojis = append(guild.Emojis, emojiP.DeepCopy().(*Emoji)) + guild.Emojis = append(guild.Emojis, DeepCopy(emojiP).(*Emoji)) } for _, vsP := range g.VoiceStates { if vsP == nil { continue } - guild.VoiceStates = append(guild.VoiceStates, vsP.DeepCopy().(*VoiceState)) + guild.VoiceStates = append(guild.VoiceStates, DeepCopy(vsP).(*VoiceState)) } for _, memberP := range g.Members { if memberP == nil { continue } - guild.Members = append(guild.Members, memberP.DeepCopy().(*Member)) + guild.Members = append(guild.Members, DeepCopy(memberP).(*Member)) } for _, channelP := range g.Channels { if channelP == nil { continue } - guild.Channels = append(guild.Channels, channelP.DeepCopy().(*Channel)) + guild.Channels = append(guild.Channels, DeepCopy(channelP).(*Channel)) } for _, presenceP := range g.Presences { if presenceP == nil { continue } - guild.Presences = append(guild.Presences, presenceP.DeepCopy().(*UserPresence)) + guild.Presences = append(guild.Presences, DeepCopy(presenceP).(*UserPresence)) } return @@ -543,15 +542,14 @@ type Ban struct { } // DeepCopy see interface at struct.go#DeepCopier -func (b *Ban) DeepCopy() (copy interface{}) { - copy = &Ban{} - _ = b.CopyOverTo(copy) - - return +func (b *Ban) deepCopy() interface{} { + cp := &Ban{} + _ = DeepCopyOver(cp, b) + return cp } // CopyOverTo see interface at struct.go#Copier -func (b *Ban) CopyOverTo(other interface{}) (err error) { +func (b *Ban) copyOverTo(other interface{}) (err error) { var ok bool var ban *Ban if ban, ok = other.(*Ban); !ok { @@ -562,7 +560,7 @@ func (b *Ban) CopyOverTo(other interface{}) (err error) { ban.Reason = b.Reason if b.User != nil { - ban.User = b.User.DeepCopy().(*User) + ban.User = DeepCopy(b.User).(*User) } return @@ -577,15 +575,14 @@ type GuildEmbed struct { } // DeepCopy see interface at struct.go#DeepCopier -func (e *GuildEmbed) DeepCopy() (copy interface{}) { - copy = &GuildEmbed{} - _ = e.CopyOverTo(copy) - - return +func (e *GuildEmbed) deepCopy() interface{} { + cp := &GuildEmbed{} + _ = DeepCopyOver(cp, e) + return cp } // CopyOverTo see interface at struct.go#Copier -func (e *GuildEmbed) CopyOverTo(other interface{}) (err error) { +func (e *GuildEmbed) copyOverTo(other interface{}) (err error) { var ok bool var embed *GuildEmbed if embed, ok = other.(*GuildEmbed); !ok { @@ -616,15 +613,14 @@ type Integration struct { } // DeepCopy see interface at struct.go#DeepCopier -func (i *Integration) DeepCopy() (copy interface{}) { - copy = &Integration{} - _ = i.CopyOverTo(copy) - - return +func (i *Integration) deepCopy() interface{} { + cp := &Integration{} + _ = DeepCopyOver(cp, i) + return cp } // CopyOverTo see interface at struct.go#Copier -func (i *Integration) CopyOverTo(other interface{}) (err error) { +func (i *Integration) copyOverTo(other interface{}) (err error) { var ok bool var integration *Integration if integration, ok = other.(*Integration); !ok { @@ -642,10 +638,10 @@ func (i *Integration) CopyOverTo(other interface{}) (err error) { integration.ExpireGracePeriod = i.ExpireGracePeriod if i.User != nil { - integration.User = i.User.DeepCopy().(*User) + integration.User = DeepCopy(i.User).(*User) } if i.Account != nil { - integration.Account = i.Account.DeepCopy().(*IntegrationAccount) + integration.Account = DeepCopy(i.Account).(*IntegrationAccount) } return @@ -658,15 +654,14 @@ type IntegrationAccount struct { } // DeepCopy see interface at struct.go#DeepCopier -func (i *IntegrationAccount) DeepCopy() (copy interface{}) { - copy = &IntegrationAccount{} - _ = i.CopyOverTo(copy) - - return +func (i *IntegrationAccount) deepCopy() interface{} { + cp := &IntegrationAccount{} + _ = DeepCopyOver(cp, i) + return cp } // CopyOverTo see interface at struct.go#Copier -func (i *IntegrationAccount) CopyOverTo(other interface{}) (err error) { +func (i *IntegrationAccount) copyOverTo(other interface{}) (err error) { var ok bool var account *IntegrationAccount if account, ok = other.(*IntegrationAccount); !ok { @@ -782,15 +777,14 @@ func (m *Member) Mention() string { } // DeepCopy see interface at struct.go#DeepCopier -func (m *Member) DeepCopy() (copy interface{}) { - copy = &Member{} - _ = m.CopyOverTo(copy) - - return +func (m *Member) deepCopy() interface{} { + cp := &Member{} + _ = DeepCopyOver(cp, m) + return cp } // CopyOverTo see interface at struct.go#Copier -func (m *Member) CopyOverTo(other interface{}) (err error) { +func (m *Member) copyOverTo(other interface{}) (err error) { var ok bool var member *Member if member, ok = other.(*Member); !ok { @@ -807,7 +801,7 @@ func (m *Member) CopyOverTo(other interface{}) (err error) { member.UserID = m.UserID if m.User != nil { - member.User = m.User.DeepCopy().(*User) + member.User = DeepCopy(m.User).(*User) } return } diff --git a/invite.go b/invite.go index 2137b758..5f2f383f 100644 --- a/invite.go +++ b/invite.go @@ -58,15 +58,14 @@ var _ Copier = (*Invite)(nil) var _ DeepCopier = (*Invite)(nil) // DeepCopy see interface at struct.go#DeepCopier -func (i *Invite) DeepCopy() (copy interface{}) { - copy = &Invite{} - i.CopyOverTo(copy) - - return +func (i *Invite) deepCopy() interface{} { + cp := &Invite{} + _ = DeepCopyOver(cp, i) + return cp } // CopyOverTo see interface at struct.go#Copier -func (i *Invite) CopyOverTo(other interface{}) (err error) { +func (i *Invite) copyOverTo(other interface{}) (err error) { var ok bool var invite *Invite if invite, ok = other.(*Invite); !ok { @@ -123,15 +122,14 @@ var _ Copier = (*InviteMetadata)(nil) var _ DeepCopier = (*InviteMetadata)(nil) // DeepCopy see interface at struct.go#DeepCopier -func (i *InviteMetadata) DeepCopy() (copy interface{}) { - copy = &InviteMetadata{} - i.CopyOverTo(copy) - - return +func (i *InviteMetadata) deepCopy() interface{} { + cp := &InviteMetadata{} + _ = DeepCopyOver(cp, i) + return cp } // CopyOverTo see interface at struct.go#Copier -func (i *InviteMetadata) CopyOverTo(other interface{}) (err error) { +func (i *InviteMetadata) copyOverTo(other interface{}) (err error) { var ok bool var invite *InviteMetadata if invite, ok = other.(*InviteMetadata); !ok { @@ -147,7 +145,7 @@ func (i *InviteMetadata) CopyOverTo(other interface{}) (err error) { invite.Revoked = i.Revoked if i.Inviter != nil { - invite.Inviter = i.Inviter.DeepCopy().(*User) + invite.Inviter = DeepCopy(i.Inviter).(*User) } return nil } diff --git a/message.go b/message.go index ea445d2b..e3f46cec 100644 --- a/message.go +++ b/message.go @@ -181,15 +181,14 @@ func (m *Message) IsDirectMessage() bool { } // DeepCopy see interface at struct.go#DeepCopier -func (m *Message) DeepCopy() (copy interface{}) { - copy = &Message{} - m.CopyOverTo(copy) - - return +func (m *Message) deepCopy() interface{} { + cp := &Message{} + _ = DeepCopyOver(cp, m) + return cp } // CopyOverTo see interface at struct.go#Copier -func (m *Message) CopyOverTo(other interface{}) (err error) { +func (m *Message) copyOverTo(other interface{}) (err error) { var message *Message var valid bool if message, valid = other.(*Message); !valid { @@ -218,23 +217,23 @@ func (m *Message) CopyOverTo(other interface{}) (err error) { message.Nonce = m.Nonce if m.Author != nil { - message.Author = m.Author.DeepCopy().(*User) + message.Author = DeepCopy(m.Author).(*User) } for _, mention := range m.Mentions { - message.Mentions = append(message.Mentions, mention.DeepCopy().(*User)) + message.Mentions = append(message.Mentions, DeepCopy(mention).(*User)) } for _, attachment := range m.Attachments { - message.Attachments = append(message.Attachments, attachment.DeepCopy().(*Attachment)) + message.Attachments = append(message.Attachments, DeepCopy(attachment).(*Attachment)) } for _, embed := range m.Embeds { - message.Embeds = append(message.Embeds, embed.DeepCopy().(*Embed)) + message.Embeds = append(message.Embeds, DeepCopy(embed).(*Embed)) } for _, reaction := range m.Reactions { - message.Reactions = append(message.Reactions, reaction.DeepCopy().(*Reaction)) + message.Reactions = append(message.Reactions, DeepCopy(reaction).(*Reaction)) } return @@ -257,7 +256,7 @@ func (m *Message) Send(ctx context.Context, s Session, flags ...Flag) (msg *Mess } if len(m.Embeds) > 0 { params.Embed = &Embed{} - _ = m.Embeds[0].CopyOverTo(params.Embed) + _ = DeepCopyOver(params.Embed, m.Embeds[0]) } channelID := m.ChannelID diff --git a/reaction.go b/reaction.go index f63481fc..2188748c 100644 --- a/reaction.go +++ b/reaction.go @@ -20,15 +20,14 @@ type Reaction struct { var _ Reseter = (*Reaction)(nil) // DeepCopy see interface at struct.go#DeepCopier -func (r *Reaction) DeepCopy() (copy interface{}) { - copy = &Reaction{} - r.CopyOverTo(copy) - - return +func (r *Reaction) deepCopy() interface{} { + cp := &Reaction{} + _ = DeepCopyOver(cp, r) + return cp } // CopyOverTo see interface at struct.go#Copier -func (r *Reaction) CopyOverTo(other interface{}) (err error) { +func (r *Reaction) copyOverTo(other interface{}) (err error) { var reaction *Reaction var valid bool if reaction, valid = other.(*Reaction); !valid { @@ -40,7 +39,7 @@ func (r *Reaction) CopyOverTo(other interface{}) (err error) { reaction.Me = r.Me if r.Emoji != nil { - reaction.Emoji = r.Emoji.DeepCopy().(*Emoji) + reaction.Emoji = DeepCopy(r.Emoji).(*Emoji) } return } diff --git a/role.go b/role.go index a1fd20dc..4f74ce54 100644 --- a/role.go +++ b/role.go @@ -70,15 +70,14 @@ func (r *Role) SetGuildID(id Snowflake) { } // DeepCopy see interface at struct.go#DeepCopier -func (r *Role) DeepCopy() (copy interface{}) { - copy = &Role{} - _ = r.CopyOverTo(copy) - - return +func (r *Role) deepCopy() interface{} { + cp := &Role{} + _ = DeepCopyOver(cp, r) + return cp } // CopyOverTo see interface at struct.go#Copier -func (r *Role) CopyOverTo(other interface{}) (err error) { +func (r *Role) copyOverTo(other interface{}) (err error) { var ok bool var role *Role if role, ok = other.(*Role); !ok { diff --git a/std/utils.go b/std/utils.go index 49ee9115..666b930a 100644 --- a/std/utils.go +++ b/std/utils.go @@ -17,12 +17,12 @@ func CopyMsgEvt(evt interface{}) interface{} { switch t := evt.(type) { case *disgord.MessageCreate: return &disgord.MessageCreate{ - Message: t.Message.DeepCopy().(*disgord.Message), + Message: disgord.DeepCopy(t.Message).(*disgord.Message), ShardID: t.ShardID, } case *disgord.MessageUpdate: return &disgord.MessageUpdate{ - Message: t.Message.DeepCopy().(*disgord.Message), + Message: disgord.DeepCopy(t.Message).(*disgord.Message), ShardID: t.ShardID, } case *disgord.MessageDelete: @@ -40,7 +40,7 @@ func CopyMsgEvt(evt interface{}) interface{} { } case *disgord.MessageReactionAdd: return &disgord.MessageReactionAdd{ - PartialEmoji: t.PartialEmoji.DeepCopy().(*disgord.PartialEmoji), + PartialEmoji: disgord.DeepCopy(t.PartialEmoji).(*disgord.PartialEmoji), MessageID: t.MessageID, ChannelID: t.ChannelID, UserID: t.UserID, @@ -48,7 +48,7 @@ func CopyMsgEvt(evt interface{}) interface{} { } case *disgord.MessageReactionRemove: return &disgord.MessageReactionRemove{ - PartialEmoji: t.PartialEmoji.DeepCopy().(*disgord.PartialEmoji), + PartialEmoji: disgord.DeepCopy(t.PartialEmoji).(*disgord.PartialEmoji), MessageID: t.MessageID, ChannelID: t.ChannelID, UserID: t.UserID, @@ -65,7 +65,7 @@ func CopyMsgEvt(evt interface{}) interface{} { MessageID: t.MessageID, GuildID: t.GuildID, ChannelID: t.ChannelID, - Emoji: t.Emoji.DeepCopy().(*disgord.Emoji), + Emoji: disgord.DeepCopy(t.Emoji).(*disgord.Emoji), ShardID: t.ShardID, } } diff --git a/struct.go b/struct.go index 4d6db108..40c7c71e 100644 --- a/struct.go +++ b/struct.go @@ -14,19 +14,6 @@ import ( //go:generate go run generate/sorters/main.go //go:generate go run generate/json/main.go -// Copier holds the CopyOverTo method which copies all it's content from one -// struct to another. Note that this requires a deep copy. -// useful when overwriting already existing content in the cacheLink to reduce GC. -type Copier interface { - CopyOverTo(other interface{}) error -} - -// DeepCopier holds the DeepCopy method which creates and returns a deep copy of -// any struct. -type DeepCopier interface { - DeepCopy() interface{} -} - func newErrorUnsupportedType(message string) *ErrorUnsupportedType { return &ErrorUnsupportedType{ info: message, diff --git a/user.go b/user.go index 403dac5e..bd948495 100644 --- a/user.go +++ b/user.go @@ -36,15 +36,14 @@ func (ap *ActivityParty) NumberOfPeople() int { } // DeepCopy see interface at struct.go#DeepCopier -func (ap *ActivityParty) DeepCopy() (copy interface{}) { - copy = &ActivityParty{} - ap.CopyOverTo(copy) - - return +func (ap *ActivityParty) deepCopy() interface{} { + cp := &ActivityParty{} + _ = DeepCopyOver(cp, ap) + return cp } // CopyOverTo see interface at struct.go#Copier -func (ap *ActivityParty) CopyOverTo(other interface{}) (err error) { +func (ap *ActivityParty) copyOverTo(other interface{}) (err error) { var ok bool var activity *ActivityParty if activity, ok = other.(*ActivityParty); !ok { @@ -66,15 +65,14 @@ type ActivityAssets struct { } // DeepCopy see interface at struct.go#DeepCopier -func (a *ActivityAssets) DeepCopy() (copy interface{}) { - copy = &ActivityAssets{} - a.CopyOverTo(copy) - - return +func (a *ActivityAssets) deepCopy() interface{} { + cp := &ActivityAssets{} + _ = DeepCopyOver(cp, a) + return cp } // CopyOverTo see interface at struct.go#Copier -func (a *ActivityAssets) CopyOverTo(other interface{}) (err error) { +func (a *ActivityAssets) copyOverTo(other interface{}) (err error) { var ok bool var activity *ActivityAssets if activity, ok = other.(*ActivityAssets); !ok { @@ -97,15 +95,14 @@ type ActivitySecrets struct { } // DeepCopy see interface at struct.go#DeepCopier -func (a *ActivitySecrets) DeepCopy() (copy interface{}) { - copy = &ActivitySecrets{} - a.CopyOverTo(copy) - - return +func (a *ActivitySecrets) deepCopy() interface{} { + cp := &ActivitySecrets{} + _ = DeepCopyOver(cp, a) + return cp } // CopyOverTo see interface at struct.go#Copier -func (a *ActivitySecrets) CopyOverTo(other interface{}) (err error) { +func (a *ActivitySecrets) copyOverTo(other interface{}) (err error) { var ok bool var activity *ActivitySecrets if activity, ok = other.(*ActivitySecrets); !ok { @@ -133,15 +130,14 @@ type ActivityTimestamp struct { } // DeepCopy see interface at struct.go#DeepCopier -func (a *ActivityTimestamp) DeepCopy() (copy interface{}) { - copy = &ActivityTimestamp{} - a.CopyOverTo(copy) - - return +func (a *ActivityTimestamp) deepCopy() interface{} { + cp := &ActivityTimestamp{} + _ = DeepCopyOver(cp, a) + return cp } // CopyOverTo see interface at struct.go#Copier -func (a *ActivityTimestamp) CopyOverTo(other interface{}) (err error) { +func (a *ActivityTimestamp) copyOverTo(other interface{}) (err error) { var ok bool var activity *ActivityTimestamp if activity, ok = other.(*ActivityTimestamp); !ok { @@ -204,15 +200,14 @@ type Activity struct { var _ Reseter = (*Activity)(nil) // DeepCopy see interface at struct.go#DeepCopier -func (a *Activity) DeepCopy() (copy interface{}) { - copy = &Activity{} - a.CopyOverTo(copy) - - return +func (a *Activity) deepCopy() interface{} { + cp := &Activity{} + _ = DeepCopyOver(cp, a) + return cp } // CopyOverTo see interface at struct.go#Copier -func (a *Activity) CopyOverTo(other interface{}) (err error) { +func (a *Activity) copyOverTo(other interface{}) (err error) { var ok bool var activity *Activity if activity, ok = other.(*Activity); !ok { @@ -230,16 +225,16 @@ func (a *Activity) CopyOverTo(other interface{}) (err error) { activity.State = a.State if a.Timestamps != nil { - activity.Timestamps = a.Timestamps.DeepCopy().(*ActivityTimestamp) + activity.Timestamps = DeepCopy(a.Timestamps).(*ActivityTimestamp) } if a.Party != nil { - activity.Party = a.Party.DeepCopy().(*ActivityParty) + activity.Party = DeepCopy(a.Party).(*ActivityParty) } if a.Assets != nil { - activity.Assets = a.Assets.DeepCopy().(*ActivityAssets) + activity.Assets = DeepCopy(a.Assets).(*ActivityAssets) } if a.Secrets != nil { - activity.Secrets = a.Secrets.DeepCopy().(*ActivitySecrets) + activity.Secrets = DeepCopy(a.Secrets).(*ActivitySecrets) } return @@ -384,15 +379,14 @@ func (u *User) SendMsgString(ctx context.Context, session Session, content strin // DeepCopy see interface at struct.go#DeepCopier // CopyOverTo see interface at struct.go#Copier -func (u *User) DeepCopy() (copy interface{}) { - copy = &User{} - u.CopyOverTo(copy) - - return +func (u *User) deepCopy() interface{} { + cp := &User{} + _ = DeepCopyOver(cp, u) + return cp } // CopyOverTo see interface at struct.go#Copier -func (u *User) CopyOverTo(other interface{}) (err error) { +func (u *User) copyOverTo(other interface{}) (err error) { var user *User var valid bool if user, valid = other.(*User); !valid { @@ -439,15 +433,14 @@ func (p *UserPresence) String() string { } // DeepCopy see interface at struct.go#DeepCopier -func (p *UserPresence) DeepCopy() (copy interface{}) { - copy = &UserPresence{} - _ = p.CopyOverTo(copy) - - return +func (p *UserPresence) deepCopy() interface{} { + cp := &UserPresence{} + _ = DeepCopyOver(cp, p) + return cp } // CopyOverTo see interface at struct.go#Copier -func (p *UserPresence) CopyOverTo(other interface{}) (err error) { +func (p *UserPresence) copyOverTo(other interface{}) (err error) { var ok bool var presence *UserPresence if presence, ok = other.(*UserPresence); !ok { @@ -455,7 +448,7 @@ func (p *UserPresence) CopyOverTo(other interface{}) (err error) { return } - presence.User = p.User.DeepCopy().(*User) + presence.User = DeepCopy(p.User).(*User) presence.GuildID = p.GuildID presence.Nick = p.Nick presence.Status = p.Status @@ -466,7 +459,7 @@ func (p *UserPresence) CopyOverTo(other interface{}) (err error) { } if p.Game != nil { - presence.Game = p.Game.DeepCopy().(*Activity) + presence.Game = DeepCopy(p.Game).(*Activity) } return @@ -482,15 +475,14 @@ type UserConnection struct { } // DeepCopy see interface at struct.go#DeepCopier -func (c *UserConnection) DeepCopy() (copy interface{}) { - copy = &UserConnection{} - c.CopyOverTo(copy) - - return +func (c *UserConnection) deepCopy() interface{} { + cp := &UserConnection{} + _ = DeepCopyOver(cp, c) + return cp } // CopyOverTo see interface at struct.go#Copier -func (c *UserConnection) CopyOverTo(other interface{}) (err error) { +func (c *UserConnection) copyOverTo(other interface{}) (err error) { var ok bool var con *UserConnection if con, ok = other.(*UserConnection); !ok { @@ -505,7 +497,7 @@ func (c *UserConnection) CopyOverTo(other interface{}) (err error) { con.Integrations = make([]*IntegrationAccount, len(c.Integrations)) for i, account := range c.Integrations { - con.Integrations[i] = account.DeepCopy().(*IntegrationAccount) + con.Integrations[i] = DeepCopy(account).(*IntegrationAccount) } return diff --git a/voice.go b/voice.go index 21b1da4e..610ee25f 100644 --- a/voice.go +++ b/voice.go @@ -50,11 +50,10 @@ var _ DeepCopier = (*VoiceState)(nil) //} // DeepCopy see interface at struct.go#DeepCopier -func (v *VoiceState) DeepCopy() (copy interface{}) { - copy = &VoiceState{} - v.CopyOverTo(copy) - - return +func (v *VoiceState) deepCopy() interface{} { + cp := &VoiceState{} + _ = DeepCopyOver(cp, v) + return cp } // UnmarshalJSON is used to unmarshal Discord's JSON. @@ -71,7 +70,7 @@ func (v *VoiceState) UnmarshalJSON(data []byte) error { } // CopyOverTo see interface at struct.go#Copier -func (v *VoiceState) CopyOverTo(other interface{}) (err error) { +func (v *VoiceState) copyOverTo(other interface{}) (err error) { var ok bool var voiceState *VoiceState if voiceState, ok = other.(*VoiceState); !ok { @@ -125,15 +124,14 @@ var _ Copier = (*VoiceRegion)(nil) var _ DeepCopier = (*VoiceRegion)(nil) // DeepCopy see interface at struct.go#DeepCopier -func (v *VoiceRegion) DeepCopy() (copy interface{}) { - copy = &VoiceRegion{} - v.CopyOverTo(copy) - - return +func (v *VoiceRegion) deepCopy() interface{} { + cp := &VoiceRegion{} + _ = DeepCopyOver(cp, v) + return cp } // CopyOverTo see interface at struct.go#Copier -func (v *VoiceRegion) CopyOverTo(other interface{}) (err error) { +func (v *VoiceRegion) copyOverTo(other interface{}) (err error) { var ok bool var voice *VoiceRegion if voice, ok = other.(*VoiceRegion); !ok { diff --git a/webhook.go b/webhook.go index 4ed4eb89..fa7b8439 100644 --- a/webhook.go +++ b/webhook.go @@ -22,15 +22,14 @@ type Webhook struct { } // DeepCopy see interface at struct.go#DeepCopier -func (w *Webhook) DeepCopy() (copy interface{}) { - copy = &Webhook{} - w.CopyOverTo(copy) - - return +func (w *Webhook) deepCopy() interface{} { + cp := &Webhook{} + _ = DeepCopyOver(cp, w) + return cp } // CopyOverTo see interface at struct.go#Copier -func (w *Webhook) CopyOverTo(other interface{}) (err error) { +func (w *Webhook) copyOverTo(other interface{}) (err error) { var ok bool var hook *Webhook if hook, ok = other.(*Webhook); !ok { @@ -41,7 +40,7 @@ func (w *Webhook) CopyOverTo(other interface{}) (err error) { hook.ID = w.ID hook.GuildID = w.GuildID hook.ChannelID = w.ChannelID - hook.User = w.User.DeepCopy().(*User) + hook.User = DeepCopy(w.User).(*User) hook.Name = w.Name hook.Avatar = w.Avatar hook.Token = w.Token