wings/api/websockets/consolewriter.go
Jakob Schrettenbrunner 184d7e0afe lots of api changes
use jsonapi to format responses
add somewhat working websockets
2018-02-20 23:36:17 +01:00

29 lines
519 B
Go

package websockets
import "io"
type ConsoleWriter struct {
Hub *Hub
HandlerFunc *func(string)
}
var _ io.Writer = ConsoleWriter{}
func (c ConsoleWriter) Write(b []byte) (n int, e error) {
line := make([]byte, len(b))
copy(line, b)
m := Message{
Type: MessageTypeConsole,
Payload: ConsolePayload{
Line: string(line),
Level: ConsoleLevelPlain,
Source: ConsoleSourceServer,
},
}
c.Hub.Broadcast <- m
if c.HandlerFunc != nil {
(*c.HandlerFunc)(string(line))
}
return len(b), nil
}