示例#1
0
文件: server.go 项目: JonPulfer/gomq
// StartServer starts up all of the goroutines required to run the service.
func StartServer(context *data.Context) {
	ln, err := net.ListenTCP("tcp4", context.QueueServerTcpAddr)
	if err != nil {
		log.Fatalf("Unable to start the listener : %v\n", err)
	}

	// Check whether there is a message store
	if context.MessageStore == nil {
		var ms data.MessageStore
		ms.Messages = make(map[string]*data.Message)
		context.MessageStore = &ms
	}

	// Launch all the services
	go queue.Manager(context)
	go RunBrokers(context)
	go webmanager.Server(context)

	for {
		conn, err := ln.Accept()
		if err != nil {
			log.Printf("Connection error : %v\n", err)
			continue
		}
		go ConnectionHandler(context, conn)

	}
}
示例#2
0
文件: server.go 项目: JonPulfer/gomq
// Server defines all the handlers and runs the webserver.
func Server(context *data.Context) {

	// Check if a custom port has been set in the context otherwise use port 8080.
	if context.WebMgrPort == "" {
		context.WebMgrPort = "8080"
	}

	// Add required handlers.
	http.HandleFunc("/api/", func(w http.ResponseWriter, r *http.Request) {
		ApiHandler(w, r, context)
	})

	// Run the http server with the default mux.
	if err := http.ListenAndServe(":"+context.WebMgrPort, nil); err != nil {
		log.Fatalln(err)
	}

}