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


Golang interaction.Interactor類代碼示例

本文整理匯總了Golang中github.com/hlandau/acme/interaction.Interactor的典型用法代碼示例。如果您正苦於以下問題:Golang Interactor類的具體用法?Golang Interactor怎麽用?Golang Interactor使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: getEmail

func getEmail(interactor interaction.Interactor) (string, error) {
	for {
		res, err := interactor.Prompt(&interaction.Challenge{
			Title:        "E. Mail Address Required",
			ResponseType: interaction.RTLineString,
			Prompt:       "E. mail address: ",
			Body:         `Please enter an e. mail address where you can be reached. Although entering an e. mail address is optional, it is highly recommended.`,
			UniqueID:     "acme-enter-email",
		})
		if err != nil {
			return "", err
		}

		if res.Value == "" {
			return "", nil
		}

		if res.Cancelled {
			return "-", nil
		}

		addr, err := mail.ParseAddress(res.Value)
		if err != nil {
			continue
		}

		return addr.Address, nil
	}
}
開發者ID:falkbizz,項目名稱:acme,代碼行數:29,代碼來源:register.go

示例2: AssistedUpsertRegistration

// Using the given client and interactor (or interaction.Auto if nil), register
// the client account if it does not already exist.
//
// The interactor is used to prompt for terms of service agreement, if
// agreement has not already been obtained. An e. mail address is prompted for.
func AssistedUpsertRegistration(cl *acmeapi.Client, interactor interaction.Interactor, ctx context.Context) error {
	interactor = defaultInteraction(interactor)

	email := ""

	for {
		err := cl.AgreeRegistration(ctx)
		if err != nil {
			if e, ok := err.(*acmeapi.AgreementError); ok {
				res, err := interactor.Prompt(&interaction.Challenge{
					Title:        "Terms of Service Agreement Required",
					YesLabel:     "I Agree",
					NoLabel:      "Cancel",
					ResponseType: interaction.RTYesNo,
					UniqueID:     "acme-agreement:" + e.URI,
					Prompt:       "Do you agree to the Terms of Service?",
					Body: fmt.Sprintf(`You must agree to the terms of service at the following URL to continue:

%s

Do you agree to the terms of service set out in the above document?`, e.URI),
				})
				if err != nil {
					return err
				}
				if !res.Cancelled {
					if email == "" {
						email, err = getEmail(interactor)
						if err != nil {
							return err
						}
						if email == "-" {
							return fmt.Errorf("e. mail input cancelled")
						}
					}

					if cl.AccountInfo.AgreementURIs == nil {
						cl.AccountInfo.AgreementURIs = map[string]struct{}{}
					}
					cl.AccountInfo.AgreementURIs[e.URI] = struct{}{}
					if email != "" {
						cl.AccountInfo.ContactURIs = []string{"mailto:" + email}
					}
					continue
				}
			}
		}

		return err
	}
}
開發者ID:falkbizz,項目名稱:acme,代碼行數:56,代碼來源:register.go

示例3: Start

// Start is a no-op for the DNS method.
func (s *dnsResponder) Start(interactor interaction.Interactor) error {
	if interactor == nil {
		return fmt.Errorf("interaction func not provided but required")
	}

	log.Debug("dns-01 interaction prompt")
	_, err := interactor.Prompt(&interaction.Challenge{
		Title: "Verification DNS Record", Body: fmt.Sprintf(`All other verification methods have failed. In order to complete the DNS verification method, you must place the verification DNS record at

  _acme-challenge IN TXT %#v

under the name to be verified before continuing.

However, you should consider that it is likely to be easier for you to investigate and rectify the reason that the HTTP and TLSSNI challenges did not work. You may wish to consider this notice a failure condition.`, s.dnsString),
	})
	if err != nil {
		return err
	}

	return nil
}
開發者ID:meyskens,項目名稱:acme,代碼行數:22,代碼來源:dns.go

示例4: getEmail

func getEmail(interactor interaction.Interactor) (string, error) {
	for {
		res, err := interactor.Prompt(&interaction.Challenge{
			Title:        "E. Mail Address Required",
			ResponseType: interaction.RTLineString,
			Prompt:       "E. mail address: ",
			Body:         `Please enter an e. mail address where you can be reached. Although entering an e. mail address is optional, it is highly recommended.`,
			UniqueID:     "acme-enter-email",
		})
		if err != nil {
			return "", err
		}

		if res.Value == "" {
			return "", nil
		}

		if res.Cancelled {
			return "-", nil
		}

		addr, err := mail.ParseAddress(res.Value)
		if err != nil {
			if res.Noninteractive {
				// If the e. mail address specified was invalid but we received it from
				// a noninteractive source, don't loop or we will loop forever. Instead
				// just act like one wasn't specified.
				return "", nil
			}

			continue
		}

		return addr.Address, nil
	}
}
開發者ID:hlandau,項目名稱:acme,代碼行數:36,代碼來源:register.go


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