github.com/gagliardetto/golang-go@v0.0.0-20201020153340-53909ea70814/cmd/go/not-internal/auth/auth.go (about) 1 // Copyright 2019 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // Package auth provides access to user-provided authentication credentials. 6 package auth 7 8 import "net/http" 9 10 // AddCredentials fills in the user's credentials for req, if any. 11 // The return value reports whether any matching credentials were found. 12 func AddCredentials(req *http.Request) (added bool) { 13 // TODO(golang.org/issue/26232): Support arbitrary user-provided credentials. 14 netrcOnce.Do(readNetrc) 15 for _, l := range netrc { 16 if l.machine == req.URL.Host { 17 req.SetBasicAuth(l.login, l.password) 18 return true 19 } 20 } 21 22 return false 23 }