mirror of
https://gitlab.com/ric_harvey/MailHog.git
synced 2024-11-23 22:34:04 +00:00
Read from socket
This commit is contained in:
parent
c27e0a3c7c
commit
6b119ea573
1 changed files with 24 additions and 3 deletions
|
@ -18,16 +18,37 @@ type Message struct {
|
||||||
Helo string
|
Helo string
|
||||||
}
|
}
|
||||||
|
|
||||||
func StartSession(conn *net.TCPConn) (*Session) {
|
func StartSession(conn *net.TCPConn) {
|
||||||
conv := &Session{conn}
|
conv := &Session{conn}
|
||||||
conv.Begin()
|
conv.Begin()
|
||||||
return conv
|
}
|
||||||
|
|
||||||
|
func (c Session) Read() {
|
||||||
|
buf := make([]byte, 1024)
|
||||||
|
n, err := c.conn.Read(buf)
|
||||||
|
if n == 0 {
|
||||||
|
log.Printf("Connection closed by remote host\n")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Error reading from socket: %s\n", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
text := string(buf)
|
||||||
|
log.Printf("Received %d bytes: %s\n", n, text)
|
||||||
|
c.Parse(text)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c Session) Parse(content string) {
|
||||||
|
log.Printf("Parsing string: %s", content)
|
||||||
|
c.Read()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Session) Begin() {
|
func (c Session) Begin() {
|
||||||
_, err := c.conn.Write([]byte("220 Go-MailHog\n"))
|
_, err := c.conn.Write([]byte("220 Go-MailHog\n"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Failed writing to socket: %s", err)
|
log.Printf("Failed writing to socket: %s\n", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
c.Read()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue