Improve documentation and golint compliance of registry package
* Add godoc documentation where it was missing * Change identifier names that don't match Go style, such as INDEX_NAME * Rename RegistryInfo to PingResult, which more accurately describes what this structure is for. It also has the benefit of making the name not stutter if used outside the package. Updates #14756 Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
This commit is contained in:
parent
a246ab0a5e
commit
52136ab008
11 changed files with 231 additions and 142 deletions
|
@ -21,19 +21,12 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
// ErrAlreadyExists is an error returned if an image being pushed
|
||||
// already exists on the remote side
|
||||
ErrAlreadyExists = errors.New("Image already exists")
|
||||
ErrDoesNotExist = errors.New("Image does not exist")
|
||||
errLoginRequired = errors.New("Authentication is required.")
|
||||
)
|
||||
|
||||
type TimeoutType uint32
|
||||
|
||||
const (
|
||||
NoTimeout TimeoutType = iota
|
||||
ReceiveTimeout
|
||||
ConnectTimeout
|
||||
)
|
||||
|
||||
// dockerUserAgent is the User-Agent the Docker client uses to identify itself.
|
||||
// It is populated on init(), comprising version information of different components.
|
||||
var dockerUserAgent string
|
||||
|
@ -74,10 +67,12 @@ func DockerHeaders(metaHeaders http.Header) []transport.RequestModifier {
|
|||
return modifiers
|
||||
}
|
||||
|
||||
// HTTPClient returns a HTTP client structure which uses the given transport
|
||||
// and contains the necessary headers for redirected requests
|
||||
func HTTPClient(transport http.RoundTripper) *http.Client {
|
||||
return &http.Client{
|
||||
Transport: transport,
|
||||
CheckRedirect: AddRequiredHeadersToRedirectedRequests,
|
||||
CheckRedirect: addRequiredHeadersToRedirectedRequests,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -98,7 +93,9 @@ func trustedLocation(req *http.Request) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
func AddRequiredHeadersToRedirectedRequests(req *http.Request, via []*http.Request) error {
|
||||
// addRequiredHeadersToRedirectedRequests adds the necessary redirection headers
|
||||
// for redirected requests
|
||||
func addRequiredHeadersToRedirectedRequests(req *http.Request, via []*http.Request) error {
|
||||
if via != nil && via[0] != nil {
|
||||
if trustedLocation(req) && trustedLocation(via[0]) {
|
||||
req.Header = via[0].Header
|
||||
|
@ -124,6 +121,8 @@ func shouldV2Fallback(err errcode.Error) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
// ErrNoSupport is an error type used for errors indicating that an operation
|
||||
// is not supported. It encapsulates a more specific error.
|
||||
type ErrNoSupport struct{ Err error }
|
||||
|
||||
func (e ErrNoSupport) Error() string {
|
||||
|
@ -133,6 +132,8 @@ func (e ErrNoSupport) Error() string {
|
|||
return e.Err.Error()
|
||||
}
|
||||
|
||||
// ContinueOnError returns true if we should fallback to the next endpoint
|
||||
// as a result of this error.
|
||||
func ContinueOnError(err error) bool {
|
||||
switch v := err.(type) {
|
||||
case errcode.Errors:
|
||||
|
@ -145,6 +146,8 @@ func ContinueOnError(err error) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
// NewTransport returns a new HTTP transport. If tlsConfig is nil, it uses the
|
||||
// default TLS configuration.
|
||||
func NewTransport(tlsConfig *tls.Config) *http.Transport {
|
||||
if tlsConfig == nil {
|
||||
var cfg = tlsconfig.ServerDefault
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue