From bf145240c22828187aecb60e4b2b0be68e4885e9 Mon Sep 17 00:00:00 2001 From: boyska Date: Thu, 23 Aug 2018 01:21:53 +0200 Subject: [PATCH] proper cmd directory --- http.go => cmd/circologd/http.go | 13 +++++++------ main.go => cmd/circologd/main.go | 4 ++-- hub.go | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) rename http.go => cmd/circologd/http.go (82%) rename main.go => cmd/circologd/main.go (95%) diff --git a/http.go b/cmd/circologd/http.go similarity index 82% rename from http.go rename to cmd/circologd/http.go index 5a5a056..3a6385a 100644 --- a/http.go +++ b/cmd/circologd/http.go @@ -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() diff --git a/main.go b/cmd/circologd/main.go similarity index 95% rename from main.go rename to cmd/circologd/main.go index 3847dbb..55445bd 100644 --- a/main.go +++ b/cmd/circologd/main.go @@ -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() diff --git a/hub.go b/hub.go index d68ef08..81a9bc9 100644 --- a/hub.go +++ b/hub.go @@ -1,4 +1,4 @@ -package main +package circolog import ( "container/ring"