MCPcopy Create free account
hub / github.com/google/go-github / main

Function main

example/basicauth/main.go:30–63  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

28)
29
30func main() {
31 r := bufio.NewReader(os.Stdin)
32 fmt.Print("GitHub Username: ")
33 username, _ := r.ReadString('\n')
34
35 fmt.Print("GitHub Password: ")
36 password, _ := term.ReadPassword(int(os.Stdin.Fd()))
37
38 tp := github.BasicAuthTransport{
39 Username: strings.TrimSpace(username),
40 Password: strings.TrimSpace(string(password)),
41 }
42
43 client, err := github.NewClient(github.WithHTTPClient(tp.Client()))
44 if err != nil {
45 log.Fatalf("error: %v", err)
46 }
47 ctx := context.Background()
48 user, _, err := client.Users.Get(ctx, "")
49
50 // Is this a two-factor auth error? If so, prompt for OTP and try again.
51 if errors.As(err, new(*github.TwoFactorAuthError)) {
52 fmt.Print("\nGitHub OTP: ")
53 otp, _ := r.ReadString('\n')
54 tp.OTP = strings.TrimSpace(otp)
55 user, _, err = client.Users.Get(ctx, "")
56 }
57
58 if err != nil {
59 log.Fatalf("error: %v", err)
60 }
61
62 fmt.Printf("\n%v\n", github.Stringify(user))
63}

Callers

nothing calls this directly

Calls 5

ClientMethod · 0.95
NewClientFunction · 0.92
WithHTTPClientFunction · 0.92
StringifyFunction · 0.92
GetMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…