本文整理匯總了Golang中github.com/google/go-github/github.BasicAuthTransport.OTP方法的典型用法代碼示例。如果您正苦於以下問題:Golang BasicAuthTransport.OTP方法的具體用法?Golang BasicAuthTransport.OTP怎麽用?Golang BasicAuthTransport.OTP使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/google/go-github/github.BasicAuthTransport
的用法示例。
在下文中一共展示了BasicAuthTransport.OTP方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: main
func main() {
r := bufio.NewReader(os.Stdin)
fmt.Print("GitHub Username: ")
username, _ := r.ReadString('\n')
fmt.Print("GitHub Password: ")
bytePassword, _ := terminal.ReadPassword(int(syscall.Stdin))
password := string(bytePassword)
tp := github.BasicAuthTransport{
Username: strings.TrimSpace(username),
Password: strings.TrimSpace(password),
}
client := github.NewClient(tp.Client())
user, _, err := client.Users.Get("")
// Is this a two-factor auth error? If so, prompt for OTP and try again.
if _, ok := err.(*github.TwoFactorAuthError); err != nil && ok {
fmt.Print("\nGitHub OTP: ")
otp, _ := r.ReadString('\n')
tp.OTP = strings.TrimSpace(otp)
user, _, err = client.Users.Get("")
}
if err != nil {
fmt.Printf("\nerror: %v\n", err)
return
}
fmt.Printf("\n%v\n", github.Stringify(user))
}