implement Source.Copy(), and rewrite Event.Copy()
This commit is contained in:
parent
22e4b8c8a4
commit
9cb3f3c522
@ -78,7 +78,9 @@ func handleConnect(c *Client, e Event) {
|
|||||||
// the one we supplied during connection, but some networks will rename
|
// the one we supplied during connection, but some networks will rename
|
||||||
// users on connect.
|
// users on connect.
|
||||||
if len(e.Params) > 0 {
|
if len(e.Params) > 0 {
|
||||||
|
c.state.mu.Lock()
|
||||||
c.state.nick = e.Params[0]
|
c.state.nick = e.Params[0]
|
||||||
|
c.state.mu.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
time.Sleep(2 * time.Second)
|
time.Sleep(2 * time.Second)
|
||||||
|
29
event.go
29
event.go
@ -125,17 +125,25 @@ func ParseEvent(raw string) (e *Event) {
|
|||||||
// functions/handlers edit the event without causing potential issues with
|
// functions/handlers edit the event without causing potential issues with
|
||||||
// other handlers.
|
// other handlers.
|
||||||
func (e *Event) Copy() *Event {
|
func (e *Event) Copy() *Event {
|
||||||
newEvent := &Event{}
|
if e == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
*newEvent = *e
|
newEvent := &Event{
|
||||||
|
Command: e.Command,
|
||||||
|
Trailing: e.Trailing,
|
||||||
|
EmptyTrailing: e.EmptyTrailing,
|
||||||
|
Sensitive: e.Sensitive,
|
||||||
|
}
|
||||||
|
|
||||||
// Copy Source field, as it's a pointer and needs to be dereferenced.
|
// Copy Source field, as it's a pointer and needs to be dereferenced.
|
||||||
if e.Source != nil {
|
if e.Source != nil {
|
||||||
*newEvent.Source = *e.Source
|
newEvent.Source = e.Source.Copy()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy Params in order to dereference as well.
|
// Copy Params in order to dereference as well.
|
||||||
if e.Params != nil {
|
if e.Params != nil {
|
||||||
|
newEvent.Params = make([]string, len(e.Params))
|
||||||
copy(newEvent.Params, e.Params)
|
copy(newEvent.Params, e.Params)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -422,6 +430,21 @@ type Source struct {
|
|||||||
Host string
|
Host string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Copy returns a deep copy of Source.
|
||||||
|
func (s *Source) Copy() *Source {
|
||||||
|
if s == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
newSource := &Source{
|
||||||
|
Name: s.Name,
|
||||||
|
Ident: s.Ident,
|
||||||
|
Host: s.Host,
|
||||||
|
}
|
||||||
|
|
||||||
|
return newSource
|
||||||
|
}
|
||||||
|
|
||||||
// ParseSource takes a string and attempts to create a Source struct.
|
// ParseSource takes a string and attempts to create a Source struct.
|
||||||
func ParseSource(raw string) (src *Source) {
|
func ParseSource(raw string) (src *Source) {
|
||||||
src = new(Source)
|
src = new(Source)
|
||||||
|
Loading…
Reference in New Issue
Block a user