- Add rest api that getting scoring
authorjw_wonny.cha <jw_wonny.cha@samsung.com>
Tue, 2 Apr 2019 05:59:37 +0000 (14:59 +0900)
committerjw_wonny.cha <jw_wonny.cha@samsung.com>
Tue, 2 Apr 2019 05:59:37 +0000 (14:59 +0900)
src/restapi/v1/restapi.go
src/restapi/v1/routers.go

index d022836..fc3c1ca 100644 (file)
@@ -18,8 +18,11 @@ import (
        "net"
        "net/http"
        "os/exec"
+       "scoringmgr"
        "servicemgr"
        "strconv"
+
+       "github.com/gorilla/mux"
 )
 
 // APIV1DeviceResourceUsageCPUGet function
@@ -122,6 +125,29 @@ func APIV1ServicemgrServicesNotificationServiceIDPost(w http.ResponseWriter, r *
        }
 }
 
+// APIV1ScoringmgrScoreLibnameGet function
+func APIV1ScoringmgrScoreLibnameGet(w http.ResponseWriter, r *http.Request) {
+       log.Printf("[%s] APIV1ScoringmgrScoreLibnameGet", logPrefix)
+
+       vars := mux.Vars(r)
+       libName := vars["libname"]
+
+       name := libName
+       target := scoringmgr.ConstLocalTarget
+
+       scoreValue, err := scoringmgr.GetScore(target, name)
+
+       respInfo := make(map[string]interface{})
+       respInfo["ScoreValue"] = scoreValue
+       respBytes, err := json.Marshal(respInfo)
+
+       if err != nil {
+               w.WriteHeader(http.StatusBadRequest)
+       } else {
+               writeJSONResponse(w, respBytes, http.StatusOK)
+       }
+}
+
 func writeJSONResponse(w http.ResponseWriter, data []byte, status int) {
        log.Printf("[%s] writeJSONResponse: %s", logPrefix, data)
        w.Header().Set("Content-Type", "application/json; charset=UTF-8")
index 5834c11..cfddada 100644 (file)
@@ -114,4 +114,11 @@ var routes = Routes{
                "/api/v1/servicemgr/services/notification/{serviceid}",
                APIV1ServicemgrServicesNotificationServiceIDPost,
        },
+
+       Route{
+               "APIV1ScoringmgrScoreLibnameGet",
+               strings.ToUpper("Get"),
+               "/api/v1/scoringmgr/score/{libname}",
+               APIV1ScoringmgrScoreLibnameGet,
+       },
 }