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

View file

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

2
hub.go
View file

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