示例#1
0
func (n NetrcAuth) String() string {
	netrcPath := n.NetrcPath
	if netrcPath == "" {
		netrcPath = filepath.Join(os.Getenv("HOME"), ".netrc")
	}
	apiURL, _ := url.Parse(gitHubAPIURL)
	credentials, err := netrc.FindMachine(netrcPath, apiURL.Host)
	if err != nil {
		panic(fmt.Errorf("netrc error (%s): %v", apiURL.Host, err))
	}
	return fmt.Sprintf("Basic %s", hashAuth(credentials.Login, credentials.Password))
}
示例#2
0
文件: main.go 项目: bhenderson/netrc
func main() {
	flag.Parse()

	m, err := netrc.FindMachine(file, flag.Arg(0))
	if err != nil {
		log.Fatal(err)
	}

	if *pass {
		fmt.Println(m.Password)
		return
	}

	if t := flag.Arg(1); t != "" {
		*tempFlag = t
	}
	temp, err := template.New("temp").Parse(*tempFlag)
	if err != nil {
		log.Fatal(err)
	}

	temp.Execute(os.Stdout, m)
}