update restapi function
authorwansuyoo <wansu.yoo@samsung.com>
Wed, 20 Mar 2019 10:37:00 +0000 (19:37 +0900)
committerwansuyoo <wansu.yoo@samsung.com>
Wed, 20 Mar 2019 10:37:00 +0000 (19:37 +0900)
.gitignore
doc/README.md
doc/edge-orchestration-api.json
doc/generate-api/api/swagger.yaml
doc/generate-api/go/api_service_manager.go
doc/generate-api/go/routers.go
doc/swagger-codegen-cli.jar [moved from doc/generate-api/swagger-codegen-cli.jar with 100% similarity]
src/restapi/v1/restapi.go
src/restapi/v1/routers.go

index 5d0f86b..ebc62b8 100644 (file)
@@ -7,6 +7,7 @@
 bin/*
 pkg/*
 vendor/src
+doc/generate-api/*
 
 # Test binary, build with `go test -c`
 *.test
index 32c2797..03ad8a4 100644 (file)
@@ -10,5 +10,5 @@ Java HotSpot(TM) 64-Bit Server VM (build 25.201-b09, mixed mode)
 ```
 ### 2. Code generate
 ```
-$ java -jar swagger-codegen-cli.jar generate -i ../edge-orchestration-api.json -l go-server
+$ java -jar swagger-codegen-cli.jar generate -i edge-orchestration-api.json -l go-server
 ```
index 7bd3287..e058a7d 100644 (file)
                                        }
                                }
                        }
+               },
+               "/api/v1/servicemgr/services/{appname}": {
+                       "get": {
+                               "tags": [
+                                       "Service Manager"
+                               ],
+                               "description": "Get information of app",
+                               "consumes": [
+                                       "application/json"
+                               ],
+                               "produces": [
+                                       "application/json"
+                               ],
+                               "parameters": [
+                                       {
+                                               "name": "appname",
+                                               "in": "path",
+                                               "description": "Name of executed app",
+                                               "required": true,
+                                               "type": "string"
+                                       }
+                               ],
+                               "responses": {
+                                       "200": {
+                                               "description": "Successful operation",
+                                               "schema": {
+                                                       "$ref": "#/definitions/ServiceInfo"
+                                               }
+                                       }
+                               }
+                       }
                }
        },
        "definitions": {
index c5ef1b4..05f3174 100644 (file)
@@ -235,6 +235,27 @@ paths:
           description: "Successful operation"
           schema:
             $ref: "#/definitions/APIResponse"
+  /api/v1/servicemgr/services/{appname}:
+    get:
+      tags:
+      - "Service Manager"
+      description: "Get information of app"
+      consumes:
+      - "application/json"
+      produces:
+      - "application/json"
+      parameters:
+      - name: "appname"
+        in: "path"
+        description: "Name of executed app"
+        required: true
+        type: "string"
+        x-exportParamName: "Appname"
+      responses:
+        200:
+          description: "Successful operation"
+          schema:
+            $ref: "#/definitions/ServiceInfo"
 definitions:
   EdgeResource:
     type: "string"
@@ -400,6 +421,9 @@ definitions:
         description: "Name of requested user service"
       serviceList:
         $ref: "#/definitions/MicroServiceList"
+    example:
+      appName: "GreetWorldApp"
+      serviceList: ""
   ServiceList:
     type: "array"
     items:
index 11cdb89..368b813 100644 (file)
@@ -13,6 +13,11 @@ import (
        "net/http"
 )
 
+func ApiV1ServicemgrServicesAppnameGet(w http.ResponseWriter, r *http.Request) {
+       w.Header().Set("Content-Type", "application/json; charset=UTF-8")
+       w.WriteHeader(http.StatusOK)
+}
+
 func ApiV1ServicemgrServicesDelete(w http.ResponseWriter, r *http.Request) {
        w.Header().Set("Content-Type", "application/json; charset=UTF-8")
        w.WriteHeader(http.StatusOK)
index ca2e5b3..0d53db1 100644 (file)
@@ -98,6 +98,13 @@ var routes = Routes{
        },
 
        Route{
+               "ApiV1ServicemgrServicesAppnameGet",
+               strings.ToUpper("Get"),
+               "/api/v1/servicemgr/services/{appname}",
+               ApiV1ServicemgrServicesAppnameGet,
+       },
+
+       Route{
                "ApiV1ServicemgrServicesDelete",
                strings.ToUpper("Delete"),
                "/api/v1/servicemgr/services",
index 0df85e0..304cf9b 100644 (file)
@@ -71,11 +71,6 @@ func APIV1ServicemgrServicesDelete(w http.ResponseWriter, r *http.Request) {
        log.Printf("[%s] APIV1ServicemgrServicesDelete", logPrefix)
 }
 
-// APIV1ServicemgrServicesGet function
-func APIV1ServicemgrServicesGet(w http.ResponseWriter, r *http.Request) {
-       log.Printf("[%s] APIV1ServicemgrServicesGet", logPrefix)
-}
-
 // APIV1ServicemgrServicesPost function
 func APIV1ServicemgrServicesPost(w http.ResponseWriter, r *http.Request) {
        log.Printf("[%s] APIV1ServicemgrServicesPost", logPrefix)
@@ -117,21 +112,13 @@ func APIV1ServicemgrEventServiceIDPost(w http.ResponseWriter, r *http.Request) {
        id, err := strconv.ParseUint(serviceID, 10, 64)
 
        if len(serviceID) == 0 || err != nil {
-               w.Header().Set("Content-Type", "application/json; charset=UTF-8")
-               w.WriteHeader(http.StatusBadRequest)
+               writeJSONResponse(w, nil, http.StatusBadRequest)
        } else {
                servicemgr.DataPathHandler(w, r, id)
-
-               w.Header().Set("Content-Type", "application/json; charset=UTF-8")
-               w.WriteHeader(http.StatusOK)
+               writeJSONResponse(w, nil, http.StatusOK)
        }
 }
 
-// APIV1ServicemgrServicesServiceIDGet function
-func APIV1ServicemgrServicesServiceIDGet(w http.ResponseWriter, r *http.Request) {
-       log.Printf("[%s] APIV1ServicemgrServicesServiceIDGet", logPrefix)
-}
-
 // APIV1ServicemgrServicesServiceIDPost function
 func APIV1ServicemgrServicesServiceIDPost(w http.ResponseWriter, r *http.Request) {
        log.Printf("[%s] APIV1ServicemgrServicesServiceIDPost", logPrefix)
@@ -160,72 +147,58 @@ func APIV1ServicemgrServicesGet(w http.ResponseWriter, r *http.Request) {
 
        ret, err := servicemgr.ServiceList()
        if err != nil {
-               w.Header().Set("Content-Type", "application/json; charset=UTF-8")
                writeJSONResponse(w, nil, http.StatusBadRequest)
-               return
        }
 
        json, err := json.Marshal(ret)
        if err == nil {
-               w.Header().Set("Content-Type", "application/json; charset=UTF-8")
                writeJSONResponse(w, json, http.StatusOK)
        } else {
-               w.Header().Set("Content-Type", "application/json; charset=UTF-8")
                writeJSONResponse(w, nil, http.StatusBadRequest)
        }
 }
 
-// APIV1ServicemgrServicesGetByAppName function
-func APIV1ServicemgrServicesGetByAppName(w http.ResponseWriter, r *http.Request) {
-       log.Printf("[%s] APIV1ServicemgrServicesGetByAppName", logPrefix)
+// APIV1ServicemgrServicesAppnameGet function
+func APIV1ServicemgrServicesAppnameGet(w http.ResponseWriter, r *http.Request) {
+       log.Printf("[%s] APIV1ServicemgrServicesAppnameGet", logPrefix)
 
        vars := mux.Vars(r)
        appName := vars["appname"]
 
        ret, err := servicemgr.FindServiceByName(appName)
        if err != nil {
-               w.Header().Set("Content-Type", "application/json; charset=UTF-8")
                writeJSONResponse(w, nil, http.StatusBadRequest)
-               return
        }
 
        json, err := json.Marshal(ret)
        if err == nil {
-               w.Header().Set("Content-Type", "application/json; charset=UTF-8")
                writeJSONResponse(w, json, http.StatusOK)
        } else {
-               w.Header().Set("Content-Type", "application/json; charset=UTF-8")
                writeJSONResponse(w, nil, http.StatusBadRequest)
        }
 }
 
-// APIV1ServicemgrServicesGetByServiceID function
-func APIV1ServicemgrServicesGetByServiceID(w http.ResponseWriter, r *http.Request) {
-       log.Printf("[%s] APIV1ServicemgrServicesGetByServiceID", logPrefix)
+// APIV1ServicemgrServicesServiceIDGet function
+func APIV1ServicemgrServicesServiceIDGet(w http.ResponseWriter, r *http.Request) {
+       log.Printf("[%s] APIV1ServicemgrServicesServiceIDGet", logPrefix)
 
        vars := mux.Vars(r)
        serviceID := vars["serviceid"]
 
        id, err := strconv.ParseUint(serviceID, 10, 64)
        if err != nil {
-               w.Header().Set("Content-Type", "application/json; charset=UTF-8")
                writeJSONResponse(w, nil, http.StatusBadRequest)
-               return
        }
 
        ret, err := servicemgr.FindServiceByID(id)
        if err != nil {
-               w.Header().Set("Content-Type", "application/json; charset=UTF-8")
                writeJSONResponse(w, nil, http.StatusBadRequest)
-               return
        }
 
        json, err := json.Marshal(ret)
        if err == nil {
-               w.Header().Set("Content-Type", "application/json; charset=UTF-8")
                writeJSONResponse(w, json, http.StatusOK)
        } else {
-               w.Header().Set("Content-Type", "application/json; charset=UTF-8")
                writeJSONResponse(w, nil, http.StatusBadRequest)
        }
 }
index 8ab65f6..c31eac2 100644 (file)
@@ -102,6 +102,13 @@ var routes = Routes{
        },
 
        Route{
+               "APIV1ServicemgrServicesAppnameGet",
+               strings.ToUpper("Get"),
+               "/api/v1/servicemgr/services/{appname}",
+               APIV1ServicemgrServicesAppnameGet,
+       },
+
+       Route{
                "APIV1ServicemgrServicesDelete",
                strings.ToUpper("Delete"),
                "/api/v1/servicemgr/services",
@@ -142,25 +149,4 @@ var routes = Routes{
                "/api/v1/servicemgr/services/{serviceid}",
                APIV1ServicemgrServicesServiceIDPost,
        },
-
-       Route{
-               "APIV1ServicemgrServicesGet",
-               strings.ToUpper("Get"),
-               "/api/v1/servicemgr/services",
-               APIV1ServicemgrServicesGet,
-       },
-
-       Route{
-               "APIV1ServicemgrServicesGetByAppName",
-               strings.ToUpper("Get"),
-               "/api/v1/servicemgr/services/{appname}",
-               APIV1ServicemgrServicesGetByAppName,
-       },
-
-       Route{
-               "APIV1ServicemgrServicesGetByServiceID",
-               strings.ToUpper("Get"),
-               "/api/v1/servicemgr/services/{serviceid}",
-               APIV1ServicemgrServicesGetByServiceID,
-       },
 }