1
0
Fork 0
forked from boyska/circolog

proper cmd directory

This commit is contained in:
boyska 2018-08-23 01:21:53 +02:00
parent 97743eaad5
commit bf145240c2
3 changed files with 10 additions and 9 deletions

View file

@ -4,18 +4,19 @@ import (
"net/http"
"time"
"git.lattuga.net/boyska/circolog"
"github.com/gorilla/websocket"
"gopkg.in/mcuadros/go-syslog.v2/format"
)
func setupHttp(hub Hub) {
func setupHttp(hub circolog.Hub) {
http.HandleFunc("/", getHTTPHandler(hub))
http.HandleFunc("/ws", getWSHandler(hub))
}
func getHTTPHandler(hub Hub) http.HandlerFunc {
func getHTTPHandler(hub circolog.Hub) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
client := Client{
client := circolog.Client{
Messages: make(chan format.LogParts),
Nofollow: true}
hub.Register <- client
@ -32,7 +33,7 @@ func getHTTPHandler(hub Hub) http.HandlerFunc {
}
}
func getWSHandler(hub Hub) http.HandlerFunc {
func getWSHandler(hub circolog.Hub) http.HandlerFunc {
var upgrader = websocket.Upgrader{
ReadBufferSize: 1024,
WriteBufferSize: 1024,
@ -42,12 +43,12 @@ func getWSHandler(hub Hub) http.HandlerFunc {
if err != nil {
return
}
client := Client{Messages: make(chan format.LogParts)}
client := circolog.Client{Messages: make(chan format.LogParts)}
hub.Register <- client
// Allow collection of memory referenced by the caller by doing all work in
// new goroutines.
go func(conn *websocket.Conn, c Client) {
go func(conn *websocket.Conn, c circolog.Client) {
defer func() {
hub.Unregister <- c
conn.Close()

View file

@ -6,6 +6,7 @@ import (
"net/http"
"os"
"git.lattuga.net/boyska/circolog"
syslog "gopkg.in/mcuadros/go-syslog.v2"
)
@ -18,8 +19,7 @@ func main() {
queryAddr := flag.String("query-addr", "127.0.0.1:9080", "Address:port where to bind the query service")
flag.Parse()
var hub Hub
hub = NewHub(*bufsize)
hub := circolog.NewHub(*bufsize)
handler := syslog.NewChannelHandler(hub.LogMessages)
server := syslog.NewServer()

2
hub.go
View file

@ -1,4 +1,4 @@
package main
package circolog
import (
"container/ring"