Breaking this up a bit
parent
475f023379
commit
d21c9cf66c
@ -0,0 +1,7 @@
|
||||
package telnet
|
||||
|
||||
type TELNETOption struct {
|
||||
Us, UsQ, Them, ThemQ bool
|
||||
}
|
||||
|
||||
type TELNETOptions map[string]TELNETOption
|
@ -0,0 +1,40 @@
|
||||
package telnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
|
||||
"github.com/ThreeDotsLabs/watermill"
|
||||
"github.com/ThreeDotsLabs/watermill/message"
|
||||
)
|
||||
|
||||
type TELNETParser struct {
|
||||
s message.Subscriber
|
||||
c context.Context
|
||||
logger watermill.LoggerAdapter
|
||||
to TELNETOptions
|
||||
}
|
||||
|
||||
func (tp *TELNETParser) Handle() {
|
||||
messages, err := tp.s.Subscribe(tp.c, "telnet.raw")
|
||||
if err != nil {
|
||||
log.Fatalln("couldn't subscribe to telnet.raw")
|
||||
}
|
||||
|
||||
for message := range messages {
|
||||
fields := make(watermill.LogFields)
|
||||
fields["body"] = string(message.Payload)
|
||||
fields["correlation_id"] = string(message.Metadata["correlation_id"])
|
||||
tp.logger.Trace("received raw TCP line", fields)
|
||||
message.Ack()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func NewTELNETParser(c context.Context, s message.Subscriber, wml watermill.LoggerAdapter) *TELNETParser {
|
||||
return &TELNETParser{
|
||||
c: c,
|
||||
s: s,
|
||||
logger: wml,
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue