本文整理匯總了Golang中github.com/rafaeljusto/shelter/dao.DomainDAO.FindAll方法的典型用法代碼示例。如果您正苦於以下問題:Golang DomainDAO.FindAll方法的具體用法?Golang DomainDAO.FindAll怎麽用?Golang DomainDAO.FindAll使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/rafaeljusto/shelter/dao.DomainDAO
的用法示例。
在下文中一共展示了DomainDAO.FindAll方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: domainFilter
func domainFilter(domainDAO dao.DomainDAO) {
numberOfItems := 20
for i := 0; i < numberOfItems; i++ {
domain := model.Domain{
FQDN: fmt.Sprintf("example%d.com.br", i),
}
if err := domainDAO.Save(&domain); err != nil {
utils.Fatalln("Error saving domain in database", err)
}
}
pagination := dao.DomainDAOPagination{
PageSize: 10,
Page: 5,
OrderBy: []dao.DomainDAOSort{
{
Field: dao.DomainDAOOrderByFieldFQDN,
Direction: dao.DAOOrderByDirectionAscending,
},
},
}
domains, err := domainDAO.FindAll(&pagination, true, "example1\\.com.*")
if err != nil {
utils.Fatalln("Error retrieving domains", err)
}
if len(domains) != 1 {
utils.Fatalln(fmt.Sprintf("Wrong number of domains when there's filter. "+
"Expected '1' and got '%d'", len(domains)), nil)
}
if domains[0].FQDN != "example1.com.br" {
utils.Fatalln("Wrong domain returned", nil)
}
for i := 0; i < numberOfItems; i++ {
fqdn := fmt.Sprintf("example%d.com.br", i)
if err := domainDAO.RemoveByFQDN(fqdn); err != nil {
utils.Fatalln("Error removing domain from database", err)
}
}
}
示例2: domainsPagination
func domainsPagination(domainDAO dao.DomainDAO) {
numberOfItems := 1000
for i := 0; i < numberOfItems; i++ {
domain := model.Domain{
FQDN: fmt.Sprintf("example%d.com.br", i),
}
if err := domainDAO.Save(&domain); err != nil {
utils.Fatalln("Error saving domain in database", err)
}
}
pagination := dao.DomainDAOPagination{
PageSize: 10,
Page: 5,
OrderBy: []dao.DomainDAOSort{
{
Field: dao.DomainDAOOrderByFieldFQDN,
Direction: dao.DAOOrderByDirectionAscending,
},
},
}
domains, err := domainDAO.FindAll(&pagination, true, "")
if err != nil {
utils.Fatalln("Error retrieving domains", 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(domains) != pagination.PageSize {
utils.Errorln("Number of domains not following page size", nil)
}
pagination = dao.DomainDAOPagination{
PageSize: 10000,
Page: 1,
OrderBy: []dao.DomainDAOSort{
{
Field: dao.DomainDAOOrderByFieldFQDN,
Direction: dao.DAOOrderByDirectionAscending,
},
},
}
domains, err = domainDAO.FindAll(&pagination, true, "")
if err != nil {
utils.Fatalln("Error retrieving domains", err)
}
if pagination.NumberOfPages != 1 {
utils.Fatalln("Calculating wrong number of pages when there's only one page", nil)
}
for i := 0; i < numberOfItems; i++ {
fqdn := fmt.Sprintf("example%d.com.br", i)
if err := domainDAO.RemoveByFQDN(fqdn); err != nil {
utils.Fatalln("Error removing domain from database", err)
}
}
}
示例3: domainsExpand
func domainsExpand(domainDAO dao.DomainDAO) {
newDomains := newDomains()
domainsResult := domainDAO.SaveMany(newDomains)
for _, domainResult := range domainsResult {
if domainResult.Error != nil {
utils.Fatalln("Error creating domains", domainResult.Error)
}
}
pagination := dao.DomainDAOPagination{}
domains, err := domainDAO.FindAll(&pagination, false, "")
if err != nil {
utils.Fatalln("Error retrieving domains", err)
}
for _, domain := range domains {
if len(domain.Owners) > 0 {
utils.Fatalln("Not compressing owners in results", nil)
}
for _, nameserver := range domain.Nameservers {
if len(nameserver.Host) > 0 ||
nameserver.IPv4 != nil ||
nameserver.IPv6 != nil ||
!nameserver.LastCheckAt.Equal(time.Time{}) ||
!nameserver.LastOKAt.Equal(time.Time{}) {
utils.Fatalln("Not compressing nameservers in results", nil)
}
}
for _, ds := range domain.DSSet {
if ds.Algorithm != 0 ||
len(ds.Digest) > 0 ||
ds.DigestType != 0 ||
ds.Keytag != 0 ||
!ds.ExpiresAt.Equal(time.Time{}) ||
!ds.LastCheckAt.Equal(time.Time{}) ||
!ds.LastOKAt.Equal(time.Time{}) {
utils.Fatalln("Not compressing ds set in results", nil)
}
}
}
domains, err = domainDAO.FindAll(&pagination, true, "")
if err != nil {
utils.Fatalln("Error retrieving domains", err)
}
for _, domain := range domains {
if len(domain.Owners) == 0 {
utils.Fatalln("Compressing owners in results when it shouldn't", nil)
}
for _, nameserver := range domain.Nameservers {
if len(nameserver.Host) == 0 ||
nameserver.IPv4 == nil ||
nameserver.IPv6 == nil ||
nameserver.LastCheckAt.Equal(time.Time{}) ||
nameserver.LastOKAt.Equal(time.Time{}) ||
nameserver.LastStatus != model.NameserverStatusOK {
utils.Fatalln("Compressing nameservers in results when it shouldn't", nil)
}
}
for _, ds := range domain.DSSet {
if ds.Algorithm == 0 ||
len(ds.Digest) == 0 ||
ds.DigestType == 0 ||
ds.Keytag == 0 ||
ds.ExpiresAt.Equal(time.Time{}) ||
ds.LastCheckAt.Equal(time.Time{}) ||
ds.LastOKAt.Equal(time.Time{}) ||
ds.LastStatus != model.DSStatusOK {
utils.Fatalln("Compressing ds set in results when it shouldn't", nil)
}
}
}
domainsResult = domainDAO.RemoveMany(newDomains)
for _, domainResult := range domainsResult {
if domainResult.Error != nil {
utils.Fatalln("Error removing domains", domainResult.Error)
}
}
}
示例4: retrieveDomains
//.........這裏部分代碼省略.........
} else {
log.Println("Error while writing response. Details:", err)
w.WriteHeader(http.StatusInternalServerError)
}
return
}
orderByField, err := dao.DomainDAOOrderByFieldFromString(field)
if err != nil {
if err := h.MessageResponse("invalid-query-order-by", ""); err == nil {
w.WriteHeader(http.StatusBadRequest)
} else {
log.Println("Error while writing response. Details:", err)
w.WriteHeader(http.StatusInternalServerError)
}
return
}
orderByDirection, err := dao.DAOOrderByDirectionFromString(direction)
if err != nil {
if err := h.MessageResponse("invalid-query-order-by", ""); err == nil {
w.WriteHeader(http.StatusBadRequest)
} else {
log.Println("Error while writing response. Details:", err)
w.WriteHeader(http.StatusInternalServerError)
}
return
}
pagination.OrderBy = append(pagination.OrderBy, dao.DomainDAOSort{
Field: orderByField,
Direction: orderByDirection,
})
}
case "pagesize":
var err error
pagination.PageSize, err = strconv.Atoi(value)
if err != nil {
if err := h.MessageResponse("invalid-query-page-size", ""); err == nil {
w.WriteHeader(http.StatusBadRequest)
} else {
log.Println("Error while writing response. Details:", err)
w.WriteHeader(http.StatusInternalServerError)
}
return
}
case "page":
var err error
pagination.Page, err = strconv.Atoi(value)
if err != nil {
if err := h.MessageResponse("invalid-query-page", ""); err == nil {
w.WriteHeader(http.StatusBadRequest)
} else {
log.Println("Error while writing response. Details:", err)
w.WriteHeader(http.StatusInternalServerError)
}
return
}
case "expand":
expand = true
case "filter":
filter = value
}
}
}
domainDAO := dao.DomainDAO{
Database: h.GetDatabase(),
}
domains, err := domainDAO.FindAll(&pagination, expand, filter)
if err != nil {
log.Println("Error while filtering domains objects. Details:", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
domainsResponse := protocol.ToDomainsResponse(domains, pagination, expand, filter)
h.Response = &domainsResponse
// Last-Modified is going to be the most recent date of the list
for _, domain := range domains {
if domain.LastModifiedAt.After(h.lastModifiedAt) {
h.lastModifiedAt = domain.LastModifiedAt
}
}
w.Header().Add("ETag", h.GetETag())
w.Header().Add("Last-Modified", h.lastModifiedAt.Format(time.RFC1123))
w.WriteHeader(http.StatusOK)
}