本文整理汇总了Golang中github.com/google/go-github/github.BasicAuthTransport类的典型用法代码示例。如果您正苦于以下问题:Golang BasicAuthTransport类的具体用法?Golang BasicAuthTransport怎么用?Golang BasicAuthTransport使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BasicAuthTransport类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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))
}
开发者ID:dindinet,项目名称:go-github,代码行数:32,代码来源:main.go
示例2: createGithubClient
func (grp githubRegistryProvider) createGithubClient(credentialName string) (*http.Client, *github.Client, error) {
if credentialName == "" {
return http.DefaultClient, github.NewClient(nil), nil
}
c, err := grp.cp.GetCredential(credentialName)
if err != nil {
log.Printf("Failed to fetch credential %s: %v", credentialName, err)
log.Print("Trying to use unauthenticated client")
return http.DefaultClient, github.NewClient(nil), nil
}
if c != nil {
if c.APIToken != "" {
ts := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: string(c.APIToken)},
)
tc := oauth2.NewClient(oauth2.NoContext, ts)
return tc, github.NewClient(tc), nil
}
if c.BasicAuth.Username != "" && c.BasicAuth.Password != "" {
tp := github.BasicAuthTransport{
Username: c.BasicAuth.Username,
Password: c.BasicAuth.Password,
}
return tp.Client(), github.NewClient(tp.Client()), nil
}
}
return nil, nil, fmt.Errorf("No suitable credential found for %s", credentialName)
}
开发者ID:danielckv,项目名称:deployment-manager,代码行数:32,代码来源:registryprovider.go
示例3: githubAuth
func githubAuth(configs *Config) *github.Client {
tp := github.BasicAuthTransport{
Username: strings.TrimSpace(configs.Github_Login),
Password: strings.TrimSpace(configs.Github_Password),
}
client := github.NewClient(tp.Client())
user, _, err := client.Users.Get("")
if err != nil {
log.Printf("error: %v", err)
return nil
} else {
log.Printf("INFO: Logged in as: %s", *user.Login)
return client
}
}
开发者ID:josemrobles,项目名称:pull-request-robification,代码行数:16,代码来源:github.go
示例4: getUserPassClient
// getUserPassClient returns a GitHub client for authorization testing. The client
// uses BasicAuth via GH username and password passed in environment variables
// (and will skip the calling test if those vars are not present).
func getUserPassClient(t *testing.T) *github.Client {
username, ok := os.LookupEnv(envKeyGitHubUsername)
if !ok {
t.Skipf(msgEnvMissing, envKeyGitHubUsername)
}
password, ok := os.LookupEnv(envKeyGitHubPassword)
if !ok {
t.Skipf(msgEnvMissing, envKeyGitHubPassword)
}
tp := github.BasicAuthTransport{
Username: strings.TrimSpace(username),
Password: strings.TrimSpace(password),
}
return github.NewClient(tp.Client())
}
开发者ID:alxp,项目名称:deadci,代码行数:21,代码来源:authorizations_test.go
注:本文中的github.com/google/go-github/github.BasicAuthTransport类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论