Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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 month 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 (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-01-17T19:48:24.000Z (almost 3 years ago)
- Last Synced: 2023-07-27T22:18:42.365Z (over 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 brevityurl, _ := 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
```