Fix null pointer exception when no sdk installed. v1.0.0-rc1
authorSebastien Douheret <sebastien.douheret@iot.bzh>
Thu, 30 Nov 2017 21:35:51 +0000 (22:35 +0100)
committerSebastien Douheret <sebastien.douheret@iot.bzh>
Thu, 30 Nov 2017 22:15:57 +0000 (23:15 +0100)
Signed-off-by: Sebastien Douheret <sebastien.douheret@iot.bzh>
lib/xdsserver/apiv1-folders.go

index b29613c..cac83ab 100644 (file)
@@ -78,7 +78,9 @@ func (s *APIService) addFolder(c *gin.Context) {
                fd.WriteString("export XDS_PROJECT_ID=" + newFld.ID + "\n")
                if newFld.DefaultSdk == "" {
                        sdks := s.sdks.GetAll()
-                       newFld.DefaultSdk = sdks[0].ID
+                       if len(sdks) > 0 {
+                               newFld.DefaultSdk = sdks[0].ID
+                       }
                }
                fd.WriteString("export XDS_SDK_ID=" + newFld.DefaultSdk + "\n")
                fd.Close()