"bytes"
"encoding/json"
"fmt"
- "github.com/spf13/viper"
+ "net"
"net/http"
"os"
"os/signal"
"strings"
"sync/atomic"
"syscall"
+ "testing"
"time"
+
+ "github.com/spf13/viper"
)
+// For testing purpose go version 1.13 ->
+var _ = func() bool {
+ testing.Init()
+ return true
+}()
+
type ReadyCB func(interface{})
type ShutdownCB func()
svc := fmt.Sprintf(service, strings.ToUpper(appnamespace), strings.ToUpper(host))
url := strings.Split(os.Getenv(strings.Replace(svc, "-", "_", -1)), "//")
+
+ Logger.Info("getService: %+v %+v", svc, url)
if len(url) > 1 {
return url[1]
}
InstallSignalHandler()
}
+func getIpAdress() string {
+ var ip net.IP
+ itf, err := net.InterfaceByName(os.Getenv("INTERFACE_NAME"))
+ if err != nil {
+ Logger.Info("Interface name is not able to resolve " + err.Error())
+ return ip.String()
+ }
+ item, err := itf.Addrs()
+ if err != nil {
+ Logger.Info("IP address is not able to resolve " + err.Error())
+ return ip.String()
+ }
+ for _, addr := range item {
+ switch v := addr.(type) {
+ case *net.IPNet:
+ if !v.IP.IsLinkLocalUnicast() {
+ ip = v.IP
+ }
+ }
+ }
+ return ip.String()
+}
+
func RunWithParams(c MessageConsumer, sdlcheck bool) {
Rmr = NewRMRClient()
Rmr.SetReadyCB(XappReadyCb, nil)
-
- host := fmt.Sprintf(":%d", GetPortData("http").Port)
+ ipString := getIpAdress()
+ var host string
+ if ipString == "<nil>" {
+ host = fmt.Sprintf(":%d", GetPortData("http").Port)
+ } else {
+ host = fmt.Sprintf("%s:%d", ipString, GetPortData("http").Port)
+ }
go http.ListenAndServe(host, Resource.router)
Logger.Info(fmt.Sprintf("Xapp started, listening on: %s", host))