2
0
Эх сурвалжийг харах

check for host limit on free tier

Abhishek Kondur 2 жил өмнө
parent
commit
a43fea35d8
1 өөрчлөгдсөн 8 нэмэгдсэн , 1 устгасан
  1. 8 1
      logic/hosts.go

+ 8 - 1
logic/hosts.go

@@ -86,7 +86,14 @@ func GetHost(hostid string) (*models.Host, error) {
 
 // CreateHost - creates a host if not exist
 func CreateHost(h *models.Host) error {
-	_, err := GetHost(h.ID.String())
+	hosts, err := GetAllHosts()
+	if err != nil && !database.IsEmptyRecord(err) {
+		return err
+	}
+	if len(hosts) >= Hosts_Limit {
+		return errors.New("free tier limits exceeded on hosts")
+	}
+	_, err = GetHost(h.ID.String())
 	if (err != nil && !database.IsEmptyRecord(err)) || (err == nil) {
 		return ErrHostExists
 	}