當前位置: 首頁>>代碼示例>>Golang>>正文


Golang ScanDAO.RemoveAll方法代碼示例

本文整理匯總了Golang中github.com/rafaeljusto/shelter/dao.ScanDAO.RemoveAll方法的典型用法代碼示例。如果您正苦於以下問題:Golang ScanDAO.RemoveAll方法的具體用法?Golang ScanDAO.RemoveAll怎麽用?Golang ScanDAO.RemoveAll使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/rafaeljusto/shelter/dao.ScanDAO的用法示例。


在下文中一共展示了ScanDAO.RemoveAll方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: deleteScans

func deleteScans(database *mgo.Database) {
	scanDAO := dao.ScanDAO{
		Database: database,
	}

	if err := scanDAO.RemoveAll(); err != nil {
		utils.Fatalln("Error removing scans", err)
	}
}
開發者ID:rafaeljusto,項目名稱:shelter,代碼行數:9,代碼來源:rest_handler_scans.go

示例2: ClearDatabase

// Function created to remove all entries from the database to ensure that the tests
// enviroments are always equal
func ClearDatabase(database *mgo.Database) {
	domainDAO := dao.DomainDAO{
		Database: database,
	}
	domainDAO.RemoveAll()

	scanDAO := dao.ScanDAO{
		Database: database,
	}
	scanDAO.RemoveAll()
}
開發者ID:rafaeljusto,項目名稱:shelter,代碼行數:13,代碼來源:database.go

示例3: scansExpand

func scansExpand(scanDAO dao.ScanDAO) {
	newScans := newScans()
	for _, scan := range newScans {
		if err := scanDAO.Save(&scan); err != nil {
			utils.Fatalln("Error creating scans", err)
		}
	}

	pagination := dao.ScanDAOPagination{}
	scans, err := scanDAO.FindAll(&pagination, false)

	if err != nil {
		utils.Fatalln("Error retrieving scans", err)
	}

	for _, scan := range scans {
		if scan.DomainsScanned != 0 ||
			scan.DomainsWithDNSSECScanned != 0 ||
			!scan.FinishedAt.Equal(time.Time{}) ||
			len(scan.NameserverStatistics) > 0 ||
			len(scan.DSStatistics) > 0 {
			utils.Fatalln("Not compressing scan in results", nil)
		}
	}

	scans, err = scanDAO.FindAll(&pagination, true)

	if err != nil {
		utils.Fatalln("Error retrieving scans", err)
	}

	for _, scan := range scans {
		if scan.DomainsScanned == 0 ||
			scan.DomainsWithDNSSECScanned == 0 ||
			scan.FinishedAt.Equal(time.Time{}) ||
			scan.StartedAt.Equal(time.Time{}) ||
			len(scan.NameserverStatistics) == 0 ||
			len(scan.DSStatistics) == 0 {
			fmt.Println(scan.DomainsScanned == 0,
				scan.DomainsWithDNSSECScanned == 0,
				scan.FinishedAt.Equal(time.Time{}),
				scan.StartedAt.Equal(time.Time{}),
				len(scan.NameserverStatistics) == 0,
				len(scan.DSStatistics) == 0)
			utils.Fatalln("Compressing scan in results when it shouldn't", nil)
		}
	}

	if err := scanDAO.RemoveAll(); err != nil {
		utils.Fatalln("Error removing scans", err)
	}
}
開發者ID:rafaeljusto,項目名稱:shelter,代碼行數:52,代碼來源:dao_scan.go

示例4: main

func main() {
	flag.Parse()

	var config ScanDAOTestConfigFile
	err := utils.ReadConfigFile(configFilePath, &config)

	if err == utils.ErrConfigFileUndefined {
		fmt.Println(err.Error())
		fmt.Println("Usage:")
		flag.PrintDefaults()
		return

	} else if err != nil {
		utils.Fatalln("Error reading configuration file", err)
	}

	database, databaseSession, err := mongodb.Open(
		[]string{config.Database.URI},
		config.Database.Name,
		false, "", "",
	)

	if err != nil {
		utils.Fatalln("Error connecting the database", err)
	}
	defer databaseSession.Close()

	scanDAO := dao.ScanDAO{
		Database: database,
	}

	// If there was some problem in the last test, there could be some data in the
	// database, so let's clear it to don't affect this test. We avoid checking the error,
	// because if the collection does not exist yet, it will be created in the first
	// insert
	scanDAO.RemoveAll()

	scanLifeCycle(scanDAO)
	scanConcurrency(scanDAO)
	scanStatistics(scanDAO)
	scansPagination(scanDAO)
	scansExpand(scanDAO)

	utils.Println("SUCCESS!")
}
開發者ID:rafaeljusto,項目名稱:shelter,代碼行數:45,代碼來源:dao_scan.go

示例5: scanStatistics

func scanStatistics(scanDAO dao.ScanDAO) {
	scan := newScan()
	scan.NameserverStatistics = map[string]uint64{
		"OK":      40,
		"TIMEOUT": 10,
	}
	scan.DSStatistics = map[string]uint64{
		"OK":     8,
		"DNSERR": 2,
	}

	// Create scan
	if err := scanDAO.Save(&scan); err != nil {
		utils.Fatalln("Couldn't save scan in database", err)
	}

	var err error
	scan, err = scanDAO.FindByStartedAt(scan.StartedAt)
	if err != nil {
		utils.Fatalln("Couldn't find created scan in database", err)
	}

	if len(scan.NameserverStatistics) != 2 ||
		scan.NameserverStatistics["OK"] != 40 ||
		scan.NameserverStatistics["TIMEOUT"] != 10 {
		utils.Fatalln("Not retrieving nameserver statistics correctly", nil)
	}

	if len(scan.DSStatistics) != 2 ||
		scan.DSStatistics["OK"] != 8 ||
		scan.DSStatistics["DNSERR"] != 2 {
		utils.Fatalln("Not retrieving DS statistics correctly", nil)
	}

	if err := scanDAO.RemoveAll(); err != nil {
		utils.Fatalln("Error removing scans from database", err)
	}
}
開發者ID:rafaeljusto,項目名稱:shelter,代碼行數:38,代碼來源:dao_scan.go

示例6: calculateScanDurations

func calculateScanDurations(numberOfDomains int, scanDAO dao.ScanDAO) (
	totalDuration time.Duration, domainsPerSecond int64,
) {

	beginTimer := time.Now()
	scan.ScanDomains()
	totalDuration = time.Since(beginTimer)

	totalDurationSeconds := int64(totalDuration / time.Second)
	if totalDurationSeconds > 0 {
		domainsPerSecond = int64(numberOfDomains) / totalDurationSeconds

	} else {
		domainsPerSecond = int64(numberOfDomains)
	}

	// As we are running a lot of scans at the same time, and the scan information unique
	// key is the start time of the scan, we must clear the database to avoid log messages
	// of scan insert errors
	scanDAO.RemoveAll()

	return
}
開發者ID:rafaeljusto,項目名稱:shelter,代碼行數:23,代碼來源:scan.go

示例7: scansPagination

func scansPagination(scanDAO dao.ScanDAO) {
	numberOfItems := 1000

	for i := 0; i < numberOfItems; i++ {
		scan := model.Scan{
			StartedAt: time.Now().Add(time.Duration(-i) * time.Minute),
		}

		if err := scanDAO.Save(&scan); err != nil {
			utils.Fatalln("Error saving scan in database", err)
		}
	}

	pagination := dao.ScanDAOPagination{
		PageSize: 10,
		Page:     5,
		OrderBy: []dao.ScanDAOSort{
			{
				Field:     dao.ScanDAOOrderByFieldStartedAt,
				Direction: dao.DAOOrderByDirectionAscending,
			},
		},
	}

	scans, err := scanDAO.FindAll(&pagination, true)
	if err != nil {
		utils.Fatalln("Error retrieving scans", err)
	}

	if pagination.NumberOfItems != numberOfItems {
		utils.Errorln("Number of items not calculated correctly", nil)
	}

	if pagination.NumberOfPages != numberOfItems/pagination.PageSize {
		utils.Errorln("Number of pages not calculated correctly", nil)
	}

	if len(scans) != pagination.PageSize {
		utils.Errorln("Number of scans not following page size", nil)
	}

	pagination = dao.ScanDAOPagination{
		PageSize: 10000,
		Page:     1,
		OrderBy: []dao.ScanDAOSort{
			{
				Field:     dao.ScanDAOOrderByFieldStartedAt,
				Direction: dao.DAOOrderByDirectionAscending,
			},
		},
	}

	scans, err = scanDAO.FindAll(&pagination, true)
	if err != nil {
		utils.Fatalln("Error retrieving scans", err)
	}

	if pagination.NumberOfPages != 1 {
		utils.Fatalln("Calculating wrong number of pages when there's only one page", nil)
	}

	if err := scanDAO.RemoveAll(); err != nil {
		utils.Fatalln("Error removing scans from database", err)
	}
}
開發者ID:rafaeljusto,項目名稱:shelter,代碼行數:65,代碼來源:dao_scan.go


注:本文中的github.com/rafaeljusto/shelter/dao.ScanDAO.RemoveAll方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。