mirror of https://github.com/fluffle/goirc
Ditch initialise() functions and just make constructors better.
This commit is contained in:
parent
6266eba245
commit
2c333e0e9a
|
@ -90,9 +90,12 @@ func init() {
|
||||||
* Channel methods for state management
|
* Channel methods for state management
|
||||||
\******************************************************************************/
|
\******************************************************************************/
|
||||||
|
|
||||||
func (ch *Channel) initialise() {
|
func NewChannel(name string) *Channel {
|
||||||
ch.Modes = new(ChanMode)
|
return &Channel{
|
||||||
ch.nicks = make(map[*Nick]*ChanPrivs)
|
Name: name,
|
||||||
|
Modes: new(ChanMode),
|
||||||
|
nicks: make(map[*Nick]*ChanPrivs),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Associates a Nick with a Channel using a shared set of ChanPrivs
|
// Associates a Nick with a Channel using a shared set of ChanPrivs
|
||||||
|
|
|
@ -44,9 +44,12 @@ func init() {
|
||||||
* Nick methods for state management
|
* Nick methods for state management
|
||||||
\******************************************************************************/
|
\******************************************************************************/
|
||||||
|
|
||||||
func (n *Nick) initialise() {
|
func NewNick(nick string) *Nick {
|
||||||
n.Modes = new(NickMode)
|
return &Nick{
|
||||||
n.chans = make(map[*Channel]*ChanPrivs)
|
Nick: nick,
|
||||||
|
Modes: new(NickMode),
|
||||||
|
chans: make(map[*Channel]*ChanPrivs),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Associates a Channel with a Nick using a shared ChanPrivs
|
// Associates a Channel with a Nick using a shared ChanPrivs
|
||||||
|
|
|
@ -29,14 +29,10 @@ type stateTracker struct {
|
||||||
\******************************************************************************/
|
\******************************************************************************/
|
||||||
|
|
||||||
func NewTracker() *stateTracker {
|
func NewTracker() *stateTracker {
|
||||||
st := &stateTracker{}
|
return &stateTracker{
|
||||||
st.initialise()
|
chans: make(map[string]*Channel),
|
||||||
return st
|
nicks: make(map[string]*Nick),
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *stateTracker) initialise() {
|
|
||||||
st.nicks = make(map[string]*Nick)
|
|
||||||
st.chans = make(map[string]*Channel)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creates a new Nick, initialises it, and stores it so it
|
// Creates a new Nick, initialises it, and stores it so it
|
||||||
|
@ -46,10 +42,9 @@ func (st *stateTracker) NewNick(nick string) *Nick {
|
||||||
logging.Warn("StateTracker.NewNick(): %s already tracked.", nick)
|
logging.Warn("StateTracker.NewNick(): %s already tracked.", nick)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
n := &Nick{Nick: nick, st: st}
|
st.nicks[nick] = NewNick(nick)
|
||||||
n.initialise()
|
st.nicks[nick].st = st
|
||||||
st.nicks[nick] = n
|
return st.nicks[nick]
|
||||||
return n
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns a Nick for the nick n, if we're tracking it.
|
// Returns a Nick for the nick n, if we're tracking it.
|
||||||
|
@ -92,10 +87,9 @@ func (st *stateTracker) NewChannel(c string) *Channel {
|
||||||
logging.Warn("StateTracker.NewChannel(): %s already tracked", c)
|
logging.Warn("StateTracker.NewChannel(): %s already tracked", c)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
ch := &Channel{Name: c, st: st}
|
st.chans[c] = NewChannel(c)
|
||||||
ch.initialise()
|
st.chans[c].st = st
|
||||||
st.chans[c] = ch
|
return st.chans[c]
|
||||||
return ch
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns a Channel for the channel c, if we're tracking it.
|
// Returns a Channel for the channel c, if we're tracking it.
|
||||||
|
|
Loading…
Reference in New Issue