- add compare targetURL with "localhost" string
authorjw_wonny.cha <jw_wonny.cha@samsung.com>
Fri, 29 Mar 2019 06:06:49 +0000 (15:06 +0900)
committerjw_wonny.cha <jw_wonny.cha@samsung.com>
Fri, 29 Mar 2019 06:06:49 +0000 (15:06 +0900)
- Add Init() export function

src/restapi/v1/restapi_test.go
src/servicemgr/configure.go
src/servicemgr/service_map.go
src/servicemgr/servicemgr.go

index 021e65d..49ce2f0 100644 (file)
@@ -15,7 +15,6 @@ import (
 )
 
 var (
-       server  *httptest.Server
        testURL string
 )
 
@@ -190,11 +189,11 @@ func executeService(t *testing.T) {
 
 func init() {
        devicemgr.InitDeviceMgr()
-       servicemgr.InitServiceMap()
+       servicemgr.Init()
        discoverymgr.InitDiscovery()
 
        router := NewRouter()
-       server = httptest.NewServer(router)
+       server := httptest.NewServer(router)
 
        testURL = server.URL
 
index 106c714..3bfc9d4 100644 (file)
@@ -46,7 +46,7 @@ const (
        ConstServiceStatusNotiURI = "/api/v1/servicemgr/services/notification/"
 
        //ConstLocalTarget is for knowing local environments
-       ConstLocalTarget = "local"
+       ConstLocalTarget = "localhost"
 
        //ConstPrefixHTTP is "http://"
        ConstPrefixHTTP = "http://"
index 7c2dbf3..419e98e 100644 (file)
@@ -4,8 +4,8 @@ import (
        "sync/atomic"
 )
 
-// InitServiceMap is for initializing service map
-func InitServiceMap() {
+// initServiceMap is for initializing service map
+func initServiceMap() {
        ServiceMap = ConcurrentMap{items: make(map[uint64]interface{})}
 }
 
index bc5d86b..42fc12a 100644 (file)
@@ -11,6 +11,11 @@ import (
        "strings"
 )
 
+// Init is for initializing serviemgr
+func Init() {
+       initServiceMap()
+}
+
 // ExecuteApp function
 func ExecuteApp(target string, name string, args []string, notiChan chan string) (serviceID uint64, err error) {
        appInfo := make(map[string]interface{})
@@ -23,7 +28,7 @@ func ExecuteApp(target string, name string, args []string, notiChan chan string)
        }
        appInfo[ConstKeyServiceName] = name
 
-       if strings.Compare(target, getOutboundIP()) == 0 {
+       if strings.Compare(target, getOutboundIP()) == 0 || strings.Compare(target, ConstLocalTarget) == 0 {
                appInfo[ConstKeyNotiTargetURL] = ConstLocalTarget
                err = executeLocalEnv(appInfo)
        } else {
@@ -37,7 +42,6 @@ func ExecuteApp(target string, name string, args []string, notiChan chan string)
 // Run is trigger point executing binary
 func Run(distService map[string]interface{}) {
        var serviceID uint64
-
        switch distService[ConstKeyServiceID].(type) {
        case uint64:
                serviceID = distService[ConstKeyServiceID].(uint64)
@@ -65,10 +69,10 @@ func Run(distService map[string]interface{}) {
        } else {
                args = nil
        }
+
        notificationTargetURL := distService[ConstKeyNotiTargetURL].(string)
 
        service := Service{serviceID, serviceName, args, notificationTargetURL}
-
        service.execute()
 }