summaryrefslogtreecommitdiffstats
path: root/msb2pilot
diff options
context:
space:
mode:
authorLvbo163 <lv.bo163@zte.com.cn>2018-08-06 15:21:24 +0800
committerLvbo163 <lv.bo163@zte.com.cn>2018-08-06 15:21:24 +0800
commitce890da0e79c26ad6f31f86956f690efee0106da (patch)
tree31dbcd72e9ef5b255fbf238671bdf0d4029ced6a /msb2pilot
parent9c3b0ca0535ddf6967983190986035b3890f3f5f (diff)
get published services from msb
Issue-ID: MSB-263 Change-Id: I3e155fec6e1e68190ad95da064d4d46b921a70b1 Signed-off-by: Lvbo163 <lv.bo163@zte.com.cn>
Diffstat (limited to 'msb2pilot')
-rw-r--r--msb2pilot/src/msb2pilot/models/config.go5
-rw-r--r--msb2pilot/src/msb2pilot/msb/msb.go59
2 files changed, 62 insertions, 2 deletions
diff --git a/msb2pilot/src/msb2pilot/models/config.go b/msb2pilot/src/msb2pilot/models/config.go
index 8dd2d3c..5773cf4 100644
--- a/msb2pilot/src/msb2pilot/models/config.go
+++ b/msb2pilot/src/msb2pilot/models/config.go
@@ -12,6 +12,7 @@
package models
const (
- EnvConsulAddress = "ConsulAddress" //http://localhost:8500
- EnvK8sAddress = "K8sAddress"
+ EnvConsulAddress = "ConsulAddress" //http://localhost:8500
+ EnvK8sAddress = "K8sAddress"
+ EnvMsbAddress = "MsbAddress"
)
diff --git a/msb2pilot/src/msb2pilot/msb/msb.go b/msb2pilot/src/msb2pilot/msb/msb.go
new file mode 100644
index 0000000..9d5754a
--- /dev/null
+++ b/msb2pilot/src/msb2pilot/msb/msb.go
@@ -0,0 +1,59 @@
+/**
+ * Copyright (c) 2018 ZTE Corporation.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and the Apache License 2.0 which both accompany this distribution,
+ * and are available at http://www.eclipse.org/legal/epl-v10.html
+ * and http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Contributors:
+ * ZTE - initial Project
+ */
+package msb
+
+import (
+ "encoding/json"
+ "io/ioutil"
+ "msb2pilot/log"
+ "msb2pilot/models"
+ "net/http"
+ "os"
+)
+
+var (
+ msbAddr = "http://localhost:9081"
+)
+
+func getBaseUrl() string {
+ baseUrl := os.Getenv(models.EnvMsbAddress)
+ if baseUrl == "" {
+ baseUrl = msbAddr
+ }
+
+ return baseUrl
+}
+
+func GetAllPublishServices() []*models.PublishService {
+ url := getBaseUrl() + "/api/msdiscover/v1/publishservicelist"
+ res, err := http.Get(url)
+
+ if err != nil {
+ log.Log.Error("fail to get public address", url, err)
+ return nil
+ }
+
+ b, err := ioutil.ReadAll(res.Body)
+ if err != nil {
+ log.Log.Error("fail to read response", err)
+ return nil
+ }
+
+ result := make([]*models.PublishService, 0)
+ err = json.Unmarshal(b, &result)
+ if err != nil {
+ log.Log.Error("fail to unmarshal publish address", err)
+ return nil
+ }
+
+ return result
+}