Selaa lähdekoodia

Update external.agi.go

Alan Yeung 2 vuotta sitten
vanhempi
commit
094199ff88
1 muutettua tiedostoa jossa 10 lisäystä ja 0 poistoa
  1. 10 0
      mod/agi/external.agi.go

+ 10 - 0
mod/agi/external.agi.go

@@ -97,6 +97,8 @@ func (g *Gateway) AddExternalEndPoint(w http.ResponseWriter, r *http.Request) {
 		common.SendErrorResponse(w, "Bad parameter")
 		return
 	}
+
+	// put the data in then marshal
 	id := uuid.New().String()
 
 	dat.Path = path
@@ -109,6 +111,7 @@ func (g *Gateway) AddExternalEndPoint(w http.ResponseWriter, r *http.Request) {
 	}
 	sysdb.Write("external_agi", id, string(jsonStr))
 
+	// send the uuid to frontend
 	common.SendJSONResponse(w, "\""+id+"\"")
 }
 
@@ -130,17 +133,21 @@ func (g *Gateway) RemoveExternalEndPoint(w http.ResponseWriter, r *http.Request)
 		common.SendErrorResponse(w, "Bad parameter")
 		return
 	}
+
+	// check if endpoint is here
 	data, isExist := g.checkIfExternalEndpointExist(uuid)
 	if !isExist {
 		common.SendErrorResponse(w, "UUID does not exists in the database!")
 		return
 	}
 
+	// make sure user cant see other's endpoint
 	if data.Username != userInfo.Username {
 		common.SendErrorResponse(w, "Bad Request, you have no permission to access this UUID entry!")
 		return
 	}
 
+	// delete record
 	sysdb.Delete("external_agi", uuid)
 
 	common.SendOK(w)
@@ -181,6 +188,7 @@ func (g *Gateway) ListExternalEndpoint(w http.ResponseWriter, r *http.Request) {
 		}
 	}
 
+	// marhsal and return
 	returnJson, err := json.Marshal(dataFromDB)
 	if err != nil {
 		common.SendErrorResponse(w, "Bad JSON")
@@ -197,10 +205,12 @@ func (g *Gateway) checkIfExternalEndpointExist(uuid string) (endpointFormat, boo
 	}
 	var dat endpointFormat
 
+	// check if key exist
 	if !sysdb.KeyExists("external_agi", uuid) {
 		return dat, false
 	}
 
+	// if yes then return the value
 	jsonData := ""
 	sysdb.Read("external_agi", uuid, &jsonData)
 	json.Unmarshal([]byte(jsonData), &dat)