--- /dev/null
+package scoringmgr
+
+import (
+ "strings"
+ "errors"
+ "strconv"
+ "encoding/json"
+ "net"
+)
+
+
+// GetScore is getting score of device
+func GetScore(target string, name string) (scoreValue float64, err error) {
+ if strings.Compare(target, getOutboundIP()) == 0 || strings.Compare(target, ConstLocalTarget) == 0 {
+ scoreValue, err = getScoreLocalEnv(name)
+ } else {
+ scoreValue, err = getScoreRemoteEnv(target, name)
+ }
+
+ DLog.Println("scoreValue", scoreValue)
+
+ return
+}
+
+// func getScore(name string) (score float64, err error) {
+// handlerObj := handlers.table[name]
+
+// if handlerObj == nil {
+// err = errors.New("Invalid Service Name")
+// return
+// }
+
+// score = handlerObj.scoreValue
+
+// return
+// }
+
+func getScoreLocalEnv(name string) (scoreValue float64, err error) {
+ // scoreChan, err := getScore(name)
+ // if err != nil {
+ // return
+ // }
+
+ // select {
+ // case scoreValue = <-scoreChan:
+ // DLog.Println(scoreValue)
+ // }
+ // return
+
+ handlerObj := handlers.table[name]
+
+ if handlerObj == nil {
+ err = errors.New("Invalid Library Name")
+ return
+ }
+
+ scoreValue = handlerObj.scoreValue
+
+ return
+}
+
+func getScoreRemoteEnv(target string, name string) (scoreValue float64, err error) {
+ targetURL := ConstPrefixHTTP + target + ":" + strconv.Itoa(ConstWellknownPort) + "/api/v1/scoringmgr/score/" + name
+
+ respBytes, err := doGet(targetURL)
+ if checkError(err) == true {
+ return scoreValue, err
+ }
+
+ var responseMsg map[string]interface{}
+ err = json.Unmarshal(respBytes, &responseMsg)
+
+ if err == nil {
+ scoreValue = responseMsg["ScoreValue"].(float64)
+ }
+
+ return
+}
+
+func getOutboundIP() string {
+ conn, err := net.Dial("udp", "8.8.8.8:80")
+ if err != nil {
+ ELog.Fatal(err)
+ }
+ defer conn.Close()
+
+ localAddr := conn.LocalAddr().(*net.UDPAddr)
+
+ return localAddr.IP.String()
+}
+
+func checkError(err error) bool {
+ if err != nil {
+ ELog.Println(err.Error())
+ return true
+ }
+ return false
+}