Permalink
Browse files

Move main() and admin server into separate packages

  • Loading branch information...
jeffjenkins committed Dec 16, 2015
1 parent 220b430 commit 8cab074572faa3d8c79883acda077c4b4113a915
@@ -1,22 +1,23 @@
package main
package adminserver
import (
"encoding/json"
"fmt"
"github.com/jeffjenkins/dispatchd/server"
"github.com/rcrowley/go-metrics"
"net/http"
"os"
)
func homeJSON(w http.ResponseWriter, r *http.Request, server *Server) {
func homeJSON(w http.ResponseWriter, r *http.Request, server *server.Server) {
var b, err = json.MarshalIndent(server, "", " ")
if err != nil {
w.Write([]byte(err.Error()))
}
w.Write(b)
}
func statsJSON(w http.ResponseWriter, r *http.Request, server *Server) {
func statsJSON(w http.ResponseWriter, r *http.Request, server *server.Server) {
// fmt.Println(metrics.DefaultRegistry)
var b, err = json.MarshalIndent(metrics.DefaultRegistry, "", " ")
if err != nil {
@@ -25,7 +26,7 @@ func statsJSON(w http.ResponseWriter, r *http.Request, server *Server) {
w.Write(b)
}
func startAdminServer(server *Server, port int) {
func StartAdminServer(server *server.Server, port int) {
// Static files
var path = os.Getenv("STATIC_PATH")
if len(path) == 0 {
View
@@ -1,4 +1,4 @@
package main
package server
import (
"bytes"
View
@@ -1,4 +1,4 @@
package main
package server
import (
"text/template"
File renamed without changes.
@@ -5,13 +5,15 @@ import (
"fmt"
"net"
// _ "net/http/pprof" // uncomment for debugging
"github.com/jeffjenkins/dispatchd/adminserver"
"github.com/jeffjenkins/dispatchd/server"
"os"
"path/filepath"
"runtime"
)
func handleConnection(server *Server, conn net.Conn) {
server.openConnection(conn)
func handleConnection(server *server.Server, conn net.Conn) {
server.OpenConnection(conn)
}
func main() {
@@ -20,15 +22,15 @@ func main() {
runtime.SetBlockProfileRate(1)
serverDbPath := filepath.Join(persistDir, "dispatchd-server.db")
msgDbPath := filepath.Join(persistDir, "messages.db")
var server = NewServer(serverDbPath, msgDbPath, config["users"].(map[string]interface{}))
var server = server.NewServer(serverDbPath, msgDbPath, config["users"].(map[string]interface{}))
ln, err := net.Listen("tcp", fmt.Sprintf(":%d", amqpPort))
if err != nil {
fmt.Printf("Error!\n")
os.Exit(1)
}
fmt.Printf("Listening on port %d\n", amqpPort)
go func() {
startAdminServer(server, adminPort)
adminserver.StartAdminServer(server, adminPort)
}()
for {
conn, err := ln.Accept()
View
@@ -1,4 +1,4 @@
package main
package server
import (
"bytes"
View
@@ -1,4 +1,4 @@
package main
package server
import (
"github.com/jeffjenkins/dispatchd/amqp"
View
@@ -1,4 +1,4 @@
package main
package server
import (
"bytes"
View
@@ -1,4 +1,4 @@
package main
package server
import (
"github.com/jeffjenkins/dispatchd/amqp"
View
@@ -1,4 +1,4 @@
package main
package server
import (
"github.com/jeffjenkins/dispatchd/amqp"
View
@@ -1,4 +1,4 @@
package main
package server
import (
"bytes"
@@ -1,4 +1,4 @@
package main
package server
import (
"github.com/jeffjenkins/dispatchd/amqp"
@@ -1,4 +1,4 @@
package main
package server
import (
_ "fmt"
View
@@ -1,4 +1,4 @@
package main
package server
import (
"fmt"
View
@@ -1,4 +1,4 @@
package main
package server
import (
"encoding/json"
@@ -299,7 +299,7 @@ func (server *Server) deregisterConnection(id int64) {
delete(server.conns, id)
}
func (server *Server) openConnection(network net.Conn) {
func (server *Server) OpenConnection(network net.Conn) {
c := NewAMQPConnection(server, network)
server.conns[c.id] = c
c.openConnection()
@@ -1,4 +1,4 @@
package main
package server
import (
"github.com/jeffjenkins/dispatchd/util"
@@ -1,4 +1,4 @@
package main
package server
import (
"testing"
@@ -1,4 +1,4 @@
package main
package server
import (
"github.com/jeffjenkins/dispatchd/util"
@@ -1,4 +1,4 @@
package main
package server
import (
"testing"
View
@@ -1,4 +1,4 @@
package main
package server
import (
"github.com/jeffjenkins/dispatchd/util"
View
@@ -1,4 +1,4 @@
package main
package server
import (
"github.com/jeffjenkins/dispatchd/util"
View
@@ -1,4 +1,4 @@
package main
package server
import (
"github.com/jeffjenkins/dispatchd/amqp"

0 comments on commit 8cab074

Please sign in to comment.