// RowsToServiceGroup convert sql rows to service group list
RowsToServiceGroup convert sql rows to service group list
// RowsToServiceGroup convert sql rows to service group list
func RowsToServiceGroup(rows *sql.Rows, containsPagination bool) []ServiceGroup {
	var serviceGroups []ServiceGroup
	for rows.Next() {
		var serviceG ServiceGroup
		var id string
		var a int
		var servicesList string
		if containsPagination {
			rows.Scan(&id, &serviceG.Name, &serviceG.IsReachable, &servicesList, &a)
		} else {
			rows.Scan(&id, &serviceG.Name, &serviceG.IsReachable, &servicesList)
		}
		servicesListArray := strings.Split(servicesList, ",")
		services := make([]bson.ObjectId, 0)
		for _, s := range servicesListArray {
			if !bson.IsObjectIdHex(strings.Trim(s, " ")) {
				continue
			}
			services = append(services, bson.ObjectIdHex(strings.Trim(s, " ")))
		}
		serviceG.Services = services
		serviceG.HostsEnabled = make([]string, 0)
		if bson.IsObjectIdHex(id) {
			serviceG.Id = bson.ObjectIdHex(id)
		} else {
			serviceG.Id = bson.NewObjectId()
		}
		serviceGroups = append(serviceGroups, serviceG)
	}
	defer rows.Close()
	return serviceGroups
}
func RowsToServiceGroup ( rows * sql . Rows , containsPagination bool ) [ ] ServiceGroup { var serviceGroups [ ] ServiceGroup for rows . Next ( ) { var serviceG ServiceGroup var id string var a int var servicesList string if containsPagination { rows . Scan ( & id , & serviceG . Name , & serviceG . IsReachable , & servicesList , & a ) } else { rows . Scan ( & id , & serviceG . Name , & serviceG . IsReachable , & servicesList ) } servicesListArray := strings . Split ( servicesList , " " ) services := make ( [ ] bson . ObjectId , 0 ) for _ , s := range servicesListArray { if ! bson . IsObjectIdHex ( strings . Trim ( s , " " ) ) { continue } services = append ( services , bson . ObjectIdHex ( strings . Trim ( s , " " ) ) ) } serviceG . Services = services serviceG . HostsEnabled = make ( [ ] string , 0 ) if bson . IsObjectIdHex ( id ) { serviceG . Id = bson . ObjectIdHex ( id ) } else { serviceG . Id = bson . NewObjectId ( ) } serviceGroups = append ( serviceGroups , serviceG ) } defer rows . Close ( ) return serviceGroups }
RowsToServiceGroup convert sql rows to service group list
RowsToServiceGroup convert sql rows to service group list