mirror of https://github.com/fluffle/goirc
Generalise timestamp code and default to using time.LocalTime
This commit is contained in:
parent
08b7d63c27
commit
623247c995
|
@ -37,6 +37,9 @@ type Conn struct {
|
||||||
|
|
||||||
Debug bool
|
Debug bool
|
||||||
|
|
||||||
|
// Function which returns a *time.Time for use as a timestamp
|
||||||
|
Timestamp func() *time.Time
|
||||||
|
|
||||||
// Event handler mapping
|
// Event handler mapping
|
||||||
events map[string][]func(*Conn, *Line)
|
events map[string][]func(*Conn, *Line)
|
||||||
|
|
||||||
|
@ -63,6 +66,7 @@ type Line struct {
|
||||||
// that you can add event handlers to it. See AddHandler() for details.
|
// that you can add event handlers to it. See AddHandler() for details.
|
||||||
func New(nick, user, name string) *Conn {
|
func New(nick, user, name string) *Conn {
|
||||||
conn := new(Conn)
|
conn := new(Conn)
|
||||||
|
conn.Timestamp = time.LocalTime
|
||||||
conn.initialise()
|
conn.initialise()
|
||||||
conn.Me = conn.NewNick(nick, user, name, "")
|
conn.Me = conn.NewNick(nick, user, name, "")
|
||||||
conn.setupEvents()
|
conn.setupEvents()
|
||||||
|
@ -188,7 +192,7 @@ func (conn *Conn) send() {
|
||||||
}
|
}
|
||||||
conn.io.Flush()
|
conn.io.Flush()
|
||||||
if conn.Debug {
|
if conn.Debug {
|
||||||
fmt.Println(time.UTC().Format("[15:04:05]") + " -> " + line)
|
fmt.Println(conn.Timestamp().Format("[15:04:05]") + " -> " + line)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -197,7 +201,7 @@ func (conn *Conn) send() {
|
||||||
func (conn *Conn) recv() {
|
func (conn *Conn) recv() {
|
||||||
for {
|
for {
|
||||||
s, err := conn.io.ReadString('\n')
|
s, err := conn.io.ReadString('\n')
|
||||||
t := time.UTC()
|
t := conn.Timestamp()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
conn.error("irc.recv(): %s", err.String())
|
conn.error("irc.recv(): %s", err.String())
|
||||||
conn.shutdown()
|
conn.shutdown()
|
||||||
|
|
Loading…
Reference in New Issue