1
0
mirror of https://github.com/interviewstreet/go-jira.git synced 2025-01-05 22:53:53 +02:00
go-jira/examples/basicauth/main.go
2021-08-27 14:45:21 +05:30

48 lines
841 B
Go

package main
import (
"bufio"
"fmt"
"golang.org/x/term"
"os"
"strings"
"syscall"
jira "github.com/chhekur/go-jira"
)
func main() {
r := bufio.NewReader(os.Stdin)
fmt.Print("Jira URL: ")
jiraURL, _ := r.ReadString('\n')
fmt.Print("Jira Username: ")
username, _ := r.ReadString('\n')
fmt.Print("Jira Password: ")
bytePassword, _ := term.ReadPassword(int(syscall.Stdin))
password := string(bytePassword)
tp := jira.BasicAuthTransport{
Username: strings.TrimSpace(username),
Password: strings.TrimSpace(password),
}
client, err := jira.NewClient(tp.Client(), strings.TrimSpace(jiraURL))
if err != nil {
fmt.Printf("\nerror: %v\n", err)
return
}
u, _, err := client.User.Get("admin")
if err != nil {
fmt.Printf("\nerror: %v\n", err)
return
}
fmt.Printf("\nEmail: %v\nSuccess!\n", u.EmailAddress)
}