Reworking in module definition
This commit is contained in:
@@ -1,35 +1,39 @@
|
||||
package control
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
|
||||
"github.com/BBVA/kapow/internal/server/user"
|
||||
)
|
||||
|
||||
type ControlServer struct {
|
||||
bindAddr string
|
||||
ctrlMux *mux.Router
|
||||
func Run(bindAddr string) {
|
||||
|
||||
r := mux.NewRouter()
|
||||
|
||||
r.HandleFunc("/routes/{id}", removeRoute).
|
||||
Methods("DELETE")
|
||||
r.HandleFunc("/routes", listRoutes).
|
||||
Methods("GET")
|
||||
r.HandleFunc("/routes", addRoute).
|
||||
Methods("POST")
|
||||
|
||||
log.Fatal(http.ListenAndServe(bindAddr, r))
|
||||
}
|
||||
|
||||
var Server *ControlServer
|
||||
|
||||
func (srv *ControlServer) Run(bindAddr string) {
|
||||
|
||||
Server = &ControlServer{bindAddr, mux.NewRouter()}
|
||||
|
||||
Server.ctrlMux.HandleFunc("/routes/{id}", Server.removeRoute).Methods("DELETE")
|
||||
Server.ctrlMux.HandleFunc("/routes", Server.listRoutes).Methods("GET")
|
||||
Server.ctrlMux.HandleFunc("/routes", Server.addRoute).Methods("POST")
|
||||
}
|
||||
|
||||
func (srv *ControlServer) removeRoute(http.ResponseWriter, *http.Request) {
|
||||
func removeRoute(http.ResponseWriter, *http.Request) {
|
||||
|
||||
}
|
||||
|
||||
func (srv *ControlServer) listRoutes(http.ResponseWriter, *http.Request) {
|
||||
func listRoutes(http.ResponseWriter, *http.Request) {
|
||||
|
||||
user.Routes.Snapshot()
|
||||
|
||||
}
|
||||
|
||||
func (srv *ControlServer) addRoute(http.ResponseWriter, *http.Request) {
|
||||
func addRoute(http.ResponseWriter, *http.Request) {
|
||||
|
||||
user.Routes.Append(routeSpec)
|
||||
}
|
||||
|
||||
@@ -4,6 +4,6 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNewControlServerFillsTheStructCorrectly(t *testing.T) {
|
||||
func Test(t *testing.T) {
|
||||
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"github.com/BBVA/kapow/internal/server/control"
|
||||
)
|
||||
|
||||
// StartServer Starts one instance of each server in a goroutine and remains listening on a channel for trace events generated by them
|
||||
@@ -24,7 +26,7 @@ func StartServer(bindAddr, certfile, keyfile string, interactive bool) error {
|
||||
dataBindAddr := fmt.Sprintf("%s:%d", userBindAddr.Host, userPort+2)
|
||||
|
||||
fmt.Printf("User server bind address: %s, Control server bind address: %s, Data server bind address: %s", bindAddr, ctrlBindAddr, dataBindAddr)
|
||||
//go ctrlServer.Start(traceChannel)
|
||||
go control.Run(ctrlBindAddr)
|
||||
//go dataServer.Start(traceChannel)
|
||||
//go ctrlServer.Start(traceChannel)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user