mirror of
				https://github.com/fluffle/goirc
				synced 2025-11-03 19:48:04 +00:00 
			
		
		
		
	Generalise timestamp code and default to using time.LocalTime
This commit is contained in:
		
							parent
							
								
									08b7d63c27
								
							
						
					
					
						commit
						623247c995
					
				
					 1 changed files with 6 additions and 2 deletions
				
			
		| 
						 | 
					@ -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…
	
	Add table
		Add a link
		
	
		Reference in a new issue