Merge branch 'feature_server_launcher'
This commit is contained in:
@@ -0,0 +1,33 @@
|
|||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net/url"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
// StartServer Starts one instance of each server in a goroutine and remains listening on a channel for trace events generated by them
|
||||||
|
func StartServer(bindAddr, certfile, keyfile string, interactive bool) error {
|
||||||
|
|
||||||
|
// Parse URI and manage parameters to extract
|
||||||
|
userBindAddr, err := url.Parse(bindAddr)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
userPort, err := strconv.ParseInt(userBindAddr.Port(), 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Error extracting port from provided address %s", bindAddr)
|
||||||
|
}
|
||||||
|
|
||||||
|
ctrlBindAddr := fmt.Sprintf("%s:%d", userBindAddr.Host, userPort+1)
|
||||||
|
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 dataServer.Start(traceChannel)
|
||||||
|
//go ctrlServer.Start(traceChannel)
|
||||||
|
|
||||||
|
// Wait for ever
|
||||||
|
select {}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package server_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/BBVA/kapow/internal/server"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestStartServerWhenInvalidBindAddrReturnsError(t *testing.T) {
|
||||||
|
|
||||||
|
err := server.StartServer("foo;bar", "", "", true)
|
||||||
|
if err == nil {
|
||||||
|
t.Errorf("Expected error not found")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestStartServerWhenInvalidPortNumberReturnsError(t *testing.T) {
|
||||||
|
|
||||||
|
err := server.StartServer("0.0.0.0:bar", "", "", true)
|
||||||
|
if err == nil {
|
||||||
|
t.Errorf("Expected error not found")
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user