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


Golang DNSResolver.LookupHost方法代碼示例

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


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

示例1: validateEmail

func validateEmail(address string, resolver bdns.DNSResolver) (prob *probs.ProblemDetails) {
	_, err := mail.ParseAddress(address)
	if err != nil {
		return &probs.ProblemDetails{
			Type:   probs.InvalidEmailProblem,
			Detail: unparseableEmailDetail,
		}
	}
	splitEmail := strings.SplitN(address, "@", -1)
	domain := strings.ToLower(splitEmail[len(splitEmail)-1])
	var resultMX []string
	var resultA []net.IP
	resultMX, err = resolver.LookupMX(domain)

	if err == nil && len(resultMX) == 0 {
		resultA, err = resolver.LookupHost(domain)
		if err == nil && len(resultA) == 0 {
			return &probs.ProblemDetails{
				Type:   probs.InvalidEmailProblem,
				Detail: emptyDNSResponseDetail,
			}
		}
	}
	if err != nil {
		dnsProblem := bdns.ProblemDetailsFromDNSError(err)
		return &probs.ProblemDetails{
			Type:   probs.InvalidEmailProblem,
			Detail: dnsProblem.Detail,
		}
	}

	return nil
}
開發者ID:paulehoffman,項目名稱:boulder,代碼行數:33,代碼來源:registration-authority.go

示例2: validateEmail

func validateEmail(ctx context.Context, address string, resolver bdns.DNSResolver) (prob *probs.ProblemDetails) {
	emails, err := mail.ParseAddressList(address)
	if err != nil {
		return &probs.ProblemDetails{
			Type:   probs.InvalidEmailProblem,
			Detail: unparseableEmailDetail,
		}
	}
	if len(emails) > 1 {
		return &probs.ProblemDetails{
			Type:   probs.InvalidEmailProblem,
			Detail: multipleAddressDetail,
		}
	}
	splitEmail := strings.SplitN(emails[0].Address, "@", -1)
	domain := strings.ToLower(splitEmail[len(splitEmail)-1])
	var resultMX []string
	var resultA []net.IP
	var errMX, errA error
	var wg sync.WaitGroup
	wg.Add(2)
	go func() {
		resultMX, errMX = resolver.LookupMX(ctx, domain)
		wg.Done()
	}()
	go func() {
		resultA, errA = resolver.LookupHost(ctx, domain)
		wg.Done()
	}()
	wg.Wait()

	if errMX != nil {
		prob := bdns.ProblemDetailsFromDNSError(errMX)
		prob.Type = probs.InvalidEmailProblem
		return prob
	} else if len(resultMX) > 0 {
		return nil
	}
	if errA != nil {
		prob := bdns.ProblemDetailsFromDNSError(errA)
		prob.Type = probs.InvalidEmailProblem
		return prob
	} else if len(resultA) > 0 {
		return nil
	}

	return &probs.ProblemDetails{
		Type:   probs.InvalidEmailProblem,
		Detail: emptyDNSResponseDetail,
	}
}
開發者ID:patf,項目名稱:boulder,代碼行數:51,代碼來源:registration-authority.go

示例3: validateEmail

func validateEmail(ctx context.Context, address string, resolver bdns.DNSResolver) (prob *probs.ProblemDetails) {
	emails, err := mail.ParseAddressList(address)
	if err != nil {
		return probs.InvalidEmail(unparseableEmailDetail)
	}
	if len(emails) > 1 {
		return probs.InvalidEmail(multipleAddressDetail)
	}
	splitEmail := strings.SplitN(emails[0].Address, "@", -1)
	domain := strings.ToLower(splitEmail[len(splitEmail)-1])
	var resultMX []string
	var resultA []net.IP
	var errMX, errA error
	var wg sync.WaitGroup
	wg.Add(2)
	go func() {
		resultMX, errMX = resolver.LookupMX(ctx, domain)
		wg.Done()
	}()
	go func() {
		resultA, errA = resolver.LookupHost(ctx, domain)
		wg.Done()
	}()
	wg.Wait()

	// We treat timeouts as non-failures for best-effort email validation
	// See: https://github.com/letsencrypt/boulder/issues/2260
	if problemIsTimeout(errMX) || problemIsTimeout(errA) {
		return nil
	}

	if errMX != nil {
		prob := bdns.ProblemDetailsFromDNSError(errMX)
		prob.Type = probs.InvalidEmailProblem
		return prob
	} else if len(resultMX) > 0 {
		return nil
	}
	if errA != nil {
		prob := bdns.ProblemDetailsFromDNSError(errA)
		prob.Type = probs.InvalidEmailProblem
		return prob
	} else if len(resultA) > 0 {
		return nil
	}

	return probs.InvalidEmail(emptyDNSResponseDetail)
}
開發者ID:jfrazelle,項目名稱:boulder,代碼行數:48,代碼來源:ra.go


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