https://github.com/leejones/netrc
A Go package that gets the credentials for a given host from a netrc file.
https://github.com/leejones/netrc
go http
Last synced: about 1 year ago
JSON representation
A Go package that gets the credentials for a given host from a netrc file.
- Host: GitHub
- URL: https://github.com/leejones/netrc
- Owner: leejones
- Created: 2022-01-17T19:35:56.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-01-17T19:48:24.000Z (about 4 years ago)
- Last Synced: 2025-02-01T13:21:23.772Z (about 1 year ago)
- Topics: go, http
- Language: Go
- Homepage:
- Size: 7.81 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# netrc
A Go package that gets the credentials for a given host from a netrc file.
## Example Usage
This example shows how to make an HTTP GET request using the credentials from
the user's `.netrc` file in their home directory:
```go
// note: some error handling is removed for brevity
url, _ := url.Parse("https://example.com/")
client := http.Client{Timeout: 5 * time.Second}
request, _ := http.NewRequest("GET", url.String(), nil)
credentials, err := netrc.Get(url.Host)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to load credentials from netrc file: %v\n", err)
os.Exit(1)
}
request.SetBasicAuth(credentials.Username, credentials.Password)
response, _ := client.Do(request)
// handle err and response etc
```