dao

package
v0.0.0-...-73d3301 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 28, 2016 License: GPL-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package dao manage the objects persistence layer

Package dao manage the objects persistence layer

Package dao manage the objects persistence layer

Index

Constants

This section is empty.

Variables

View Source
var (
	// Programmer must set the Database attribute from DomainDAO with a valid connection
	// before using this object
	ErrDomainDAOUndefinedDatabase = errors.New("No database defined for DomainDAO")

	// Pagination attribute is mandatory, and it's a pointer only to fill some query
	// informations in it. For the user that wants all records without pagination for a B2B
	// integration need to pass zero in the page size
	ErrDomainDAOPaginationUndefined = errors.New("Pagination was not defined")

	// An invalid order by field was given to be converted in one of the known order by
	// fields of the Domain DAO
	ErrDomainDAOOrderByFieldUnknown = errors.New("Unknown order by field")
)

List of possible errors that can occur in this DAO. There can be also other errors from low level drivers.

View Source
var (
	// Programmer must set the Database attribute from ScanDAO with a valid connection before using
	// this object
	ErrScanDAOUndefinedDatabase = errors.New("No database defined for ScanDAO")

	// Pagination attribute is mandatory, and it's a pointer only to fill some query
	// informations in it. For the user that wants all records without pagination for a B2B
	// integration need to pass zero in the page size
	ErrScanDAOPaginationUndefined = errors.New("Pagination was not defined")

	// An invalid order by field was given to be converted in one of the known order by
	// fields of the Scan DAO
	ErrScanDAOOrderByFieldUnknown = errors.New("Unknown order by field")
)

List of possible errors that can occur in this DAO. There can be also other errors from low level drivers.

View Source
var (
	// An invalid order by direction was given to be converted in one of the known order by
	// fields of the DAO
	ErrDAOOrderByDirectionUnknown = errors.New("Unknown order by direction")
)

Functions

func DAOOrderByDirectionToString

func DAOOrderByDirectionToString(value DAOOrderByDirection) string

Convert the DAO order by direction from enum into string. If the enum is unknown this method will return an empty string

func DomainDAOOrderByFieldToString

func DomainDAOOrderByFieldToString(value DomainDAOOrderByField) string

Convert the DomainDAO order by field from enum into string. If the enum is unknown this method will return an empty string

func ScanDAOOrderByFieldToString

func ScanDAOOrderByFieldToString(value ScanDAOOrderByField) string

Convert the ScanDAO order by field from enum into string. If the enum is unknown this method will return an empty string

Types

type DAOOrderByDirection

type DAOOrderByDirection int

Enumerate definition for the OrderBy so that we can make it easy to determinate the direction of an order by field

const (
	DAOOrderByDirectionAscending  DAOOrderByDirection = 1  // From lower to higher
	DAOOrderByDirectionDescending DAOOrderByDirection = -1 // From Higher to lower
)

List of possible directions of each field in an order by query

func DAOOrderByDirectionFromString

func DAOOrderByDirectionFromString(value string) (DAOOrderByDirection, error)

Convert the DAO order by direction from string into enum. If the string is unknown an error will be returned. The string is case insensitive and spaces around it are ignored

type DomainDAO

type DomainDAO struct {
	Database *mgo.Database // MongoDB Database
}

DomainDAO is the structure responsable for keeping the database connection to save the domain anytime during the their existence

func (DomainDAO) FindAll

func (dao DomainDAO) FindAll(pagination *DomainDAOPagination, expand bool, filter string) ([]model.Domain, error)

Retrieve all domains using pagination control. This method is used by an end user to see all domains that are already registered in the system. The user will probably wants pagination to analyze the data in amounts. When pagination values are not informed, default values are adopted. There's also an expand flag that can control if each domain object from the list will have only the FQDN, last modification, nameserver and DS status or the full information

func (DomainDAO) FindAllAsync

func (dao DomainDAO) FindAllAsync() (chan DomainResult, error)

Retrieve all domains for a scan. This method can take a long time to load all domains, so it will return a channel and will send a domain as soon as it is loaded from the database. The method ends when it returns a nil domain or an error in the channel result

func (DomainDAO) FindAllAsyncToBeNotified

func (dao DomainDAO) FindAllAsyncToBeNotified(
	nameserverErrorAlertDays,
	nameserverTimeoutAlertDays,
	dsErrorAlertDays,
	dsTimeoutAlertDays,
	maxExpirationAlertDays int,
) (chan DomainResult, error)

Return all domains that need to be notified due to the error tolerancy policy. The objective is to help the user to configure correctly the nameservers alerting about problems. We are going to have different notification tolerances for nameserver, ds and the type of errors (timeout and others). In the worst case this method can return all the domains from the system, so it will work asynchronously, returning the domain as soon as it is selected

func (DomainDAO) FindByFQDN

func (dao DomainDAO) FindByFQDN(fqdn string) (model.Domain, error)

Try to find the domain using the FQDN attribute. The system was designed to have an unique FQDN. The database should be prepared (with indexes) to search faster when using FQDN as condition

func (DomainDAO) Remove

func (dao DomainDAO) Remove(domain *model.Domain) error

Remove a database entry based on a given domain id. This method is useful as a RemoveMany auxiliar method, because it's faster that RemoveByFQDN

func (DomainDAO) RemoveAll

func (dao DomainDAO) RemoveAll() error

Remove all domain entries from the database. This is a DANGEROUS method, use with caution. For now is used only by the integration test enviroments to clear the database before starting a new test. We don't drop the collection because we don't wanna lose the indexes. Dropping the collection is much faster, but this method is probably never going to be a part of a critical system (I don't known any system that wants to erase all your data)

func (DomainDAO) RemoveByFQDN

func (dao DomainDAO) RemoveByFQDN(fqdn string) error

Remove a database entry that have a given FQDN. The system was designed to have an unique FQDN. The database should be prepared (with indexes) to search faster when using FQDN as condition

func (DomainDAO) RemoveMany

func (dao DomainDAO) RemoveMany(domains []*model.Domain) []DomainResult

Remove many domain objects from database at once, is faster than removing each one because it use go routines to execute everything concurrently

func (DomainDAO) Save

func (dao DomainDAO) Save(domain *model.Domain) error

Save the domain object in the database and by consequence will also save the nameservers and ds set. On creation the domain object is going to receive the id that refers to the entry in the database

func (DomainDAO) SaveMany

func (dao DomainDAO) SaveMany(domains []*model.Domain) []DomainResult

Save many domains at once, creating go routines to execute each domain in the classic Save method. This happens because there's no method to execute Upsert to many documents at once in the mgo API. http://stackoverflow.com/questions/19810176/mongodb-mgo- library-golang-multiple-insert-updates

type DomainDAOOrderByField

type DomainDAOOrderByField int

Enumerate definition for the OrderBy so that we can limit the fields that the user can use in a query

const (
	DomainDAOOrderByFieldFQDN           DomainDAOOrderByField = 0 // Order by domain's FQDN
	DomainDAOOrderByFieldLastModifiedAt DomainDAOOrderByField = 1 // Order by the last modification date of the domain object
)

List of possible fields that can be used to order a result set

func DomainDAOOrderByFieldFromString

func DomainDAOOrderByFieldFromString(value string) (DomainDAOOrderByField, error)

Convert the DomainDAO order by field from string into enum. If the string is unknown an error will be returned. The string is case insensitive and spaces around it are ignored

type DomainDAOPagination

type DomainDAOPagination struct {
	OrderBy       []DomainDAOSort // Sort the list before the pagination
	PageSize      int             // Number of items that are going to be considered in one page
	Page          int             // Current page that will be returned
	NumberOfItems int             // Total number of items in the result set
	NumberOfPages int             // Total number of pages calculated for the current result set
}

DomainDAOPagination was created as a necessity for big result sets that needs to be sent for an end-user. With pagination we can control the size of the data and make it faster for the user to interact with it in a web interface as example

type DomainDAOSort

type DomainDAOSort struct {
	Field     DomainDAOOrderByField // Field to be sorted
	Direction DAOOrderByDirection   // Direction used in the sort
}

DomainDAOSort is an object responsable to relate the order by field and direction. Each field used for sort, can be sorted in both directions

type DomainResult

type DomainResult struct {
	Domain *model.Domain // Domain related to the result
	Error  error         // When different of nil, represents an error of the operation
}

DomainResult is used when calling methods that execute actions over many domain objects. On error the caller need to know witch domain got an error. We are using this solution because there's no pair structure in Go language

type ScanDAO

type ScanDAO struct {
	Database *mgo.Database // MongoDB Database
}

ScanDAO is the structure responsible for keeping the database connection to save a new scan object after every execution

func (ScanDAO) FindAll

func (dao ScanDAO) FindAll(pagination *ScanDAOPagination, expand bool) ([]model.Scan, error)

Retrieve all scans using pagination control. This method is used by an end user to see all scans that were executed in the system. The user will probably wants pagination to analyze the data in amounts. When pagination values are not informed, default values are adopted. There's also an expand flag that can control if each scan object from the list will have only the started date and the last modification date or the full information

func (ScanDAO) FindByStartedAt

func (dao ScanDAO) FindByStartedAt(startedAt time.Time) (model.Scan, error)

Try to find the scan using the startedAt time attribute

func (ScanDAO) RemoveAll

func (dao ScanDAO) RemoveAll() error

Remove all scan entries from the database. This is a DANGEROUS method, use with caution. For now is used only by the integration test enviroments to clear the database before starting a new test. We don't drop the collection because we don't wanna lose the indexes. Dropping the collection is much faster, but this method is probably never going to be a part of a critical system (I don't known any system that wants to erase all your data)

func (ScanDAO) RemoveByStartedAt

func (dao ScanDAO) RemoveByStartedAt(startedAt time.Time) error

Remove a database entry that have a given startedAt time

func (ScanDAO) Save

func (dao ScanDAO) Save(scan *model.Scan) error

Save the scan object in the database. On creation the scan object is going to receive the id that refers to the entry in the database

type ScanDAOOrderByField

type ScanDAOOrderByField int

Enumerate definition for the OrderBy so that we can limit the fields that the user can use in a query

const (
	ScanDAOOrderByFieldStartedAt                ScanDAOOrderByField = 0 // Order by scan's begin time
	ScanDAOOrderByFieldDomainsScanned           ScanDAOOrderByField = 1 // Order by the number of domains scanned
	ScanDAOOrderByFieldDomainsWithDNSSECScanned ScanDAOOrderByField = 2 // Order by the number of domains with DNSSEC scanned
)

List of possible fields that can be used to order a result set

func ScanDAOOrderByFieldFromString

func ScanDAOOrderByFieldFromString(value string) (ScanDAOOrderByField, error)

Convert the ScanDAO order by field from string into enum. If the string is unknown an error will be returned. The string is case insensitive and spaces around it are ignored

type ScanDAOPagination

type ScanDAOPagination struct {
	OrderBy       []ScanDAOSort // Sort the list before the pagination
	PageSize      int           // Number of items that are going to be considered in one page
	Page          int           // Current page that will be returned
	NumberOfItems int           // Total number of items in the result set
	NumberOfPages int           // Total number of pages calculated for the current result set
}

ScanDAOPagination was created as a necessity for big result sets that needs to be sent for an end-user. With pagination we can control the size of the data and make it faster for the user to interact with it in a web interface as example

type ScanDAOSort

type ScanDAOSort struct {
	Field     ScanDAOOrderByField // Field to be sorted
	Direction DAOOrderByDirection // Direction used in the sort
}

ScanDAOSort is an object responsable to relate the order by field and direction. Each field used for sort, can be sorted in both directions

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL