|
@@ -6,6 +6,7 @@ import (
|
|
"os"
|
|
"os"
|
|
"time"
|
|
"time"
|
|
|
|
|
|
|
|
+ "git.lattuga.net/boyska/circolog/data"
|
|
"git.lattuga.net/boyska/circolog/filtering"
|
|
"git.lattuga.net/boyska/circolog/filtering"
|
|
"gopkg.in/mcuadros/go-syslog.v2/format"
|
|
"gopkg.in/mcuadros/go-syslog.v2/format"
|
|
)
|
|
)
|
|
@@ -13,10 +14,11 @@ import (
|
|
// Client represent a client connected via websocket. Its most important field is the messages channel, where
|
|
// Client represent a client connected via websocket. Its most important field is the messages channel, where
|
|
// new messages are sent.
|
|
// new messages are sent.
|
|
type Client struct {
|
|
type Client struct {
|
|
- Messages chan format.LogParts // only hub should write/close this
|
|
|
|
|
|
+ Messages chan data.Message // only hub should write/close this
|
|
Options ClientOptions
|
|
Options ClientOptions
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// ClientOptions is a struct containing connection options for every reader
|
|
type ClientOptions struct {
|
|
type ClientOptions struct {
|
|
BacklogLength int // how many past messages the client wants to receive upon connection
|
|
BacklogLength int // how many past messages the client wants to receive upon connection
|
|
Nofollow bool // if Nofollow is true, the hub will not keep this client permanently. Rather, it will send every message to "Messages" and close the channel. Use this if you want to get the messages one-shot
|
|
Nofollow bool // if Nofollow is true, the hub will not keep this client permanently. Rather, it will send every message to "Messages" and close the channel. Use this if you want to get the messages one-shot
|
|
@@ -100,7 +102,7 @@ func (h *Hub) register(cl Client) {
|
|
item := buf.Value
|
|
item := buf.Value
|
|
if item != nil {
|
|
if item != nil {
|
|
select { // send with short timeout
|
|
select { // send with short timeout
|
|
- case cl.Messages <- item.(format.LogParts):
|
|
|
|
|
|
+ case cl.Messages <- item.(data.Message):
|
|
break
|
|
break
|
|
case <-time.After(500 * time.Millisecond):
|
|
case <-time.After(500 * time.Millisecond):
|
|
close(cl.Messages)
|
|
close(cl.Messages)
|
|
@@ -132,12 +134,13 @@ func (h *Hub) Run() {
|
|
delete(h.clients, cl)
|
|
delete(h.clients, cl)
|
|
}
|
|
}
|
|
case msg := <-h.LogMessages:
|
|
case msg := <-h.LogMessages:
|
|
- if active == true && filter.Validate(msg) {
|
|
|
|
- h.circbuf.Value = msg
|
|
|
|
|
|
+ newmsg := data.LogEntryToMessage(msg)
|
|
|
|
+ if active == true && filter.Validate(newmsg) {
|
|
|
|
+ h.circbuf.Value = newmsg
|
|
h.circbuf = h.circbuf.Next()
|
|
h.circbuf = h.circbuf.Next()
|
|
for client := range h.clients {
|
|
for client := range h.clients {
|
|
select { // send without blocking
|
|
select { // send without blocking
|
|
- case client.Messages <- msg:
|
|
|
|
|
|
+ case client.Messages <- newmsg:
|
|
break
|
|
break
|
|
default:
|
|
default:
|
|
break
|
|
break
|